本地MCP服务器客户端代理

本地MCP服务器客户端代理

一个用于本地部署的MCP服务器和客户端代理工具,支持Web Search功能。

快速入门指南

简介

Agent-MCP 是一个本地MCP(Model Context Protocol)服务器与客户端实现,支持调用Google SerpAPI进行搜索。

使用方法

  1. 安装依赖:确保已安装Python环境及相关依赖。
  2. 配置MCP Server
    • 参考Antropic文档搭建本地MCP Server。
    • 使用Google SerpAPI作为Search API。
  3. 运行MCP Client
    • 修改代码以适配OpenAI接口。
    • 测试支持的模型如Qwen2.5和DeepSeek-V3。
  4. 示例代码
    async with MCPServerStdio(params={"command": "python", "args": [LOCAL_SERVER_PATH]}) as server:
        tools = await server.list_tools()
        print(f"Connected to server with tools: {tools}")
        planning_agent = PlanningAgent(
            name="Planning Agent",
            model=model,
            handoffs=[ResearchAgent(name="Research Agent", model=model, mcp_servers=[server])]
        )
        result_stream = Runner.run_streamed(
            starting_agent=planning_agent,
            input="What's the main focus on the topic of AI in 2025?",
            max_turns=15
        )
        async for event in result_stream.stream_events():
            # 根据事件类型处理输出
            pass