MCP-v1:多服务器人工智能代理平台
概述
MCP-v1是一个基于Python的平台,演示了如何使用模型上下文协议(MCP)和LangChain构建和连接多个AI驱动的微服务(“工具”)。它具有一个可以与本地和远程服务器交互的客户端,利用LLM(如Groq的Qwen3-32B)来协调复杂任务的工具使用。
特性
- 多服务器编排: 连接到本地(数学)和远程(天气)MCP服务器。
- LLM代理集成: 使用LangChain和LangGraph创建一个可以推理和调用工具的ReAct代理。
- 可扩展工具: 按照提供的服务器模板轻松添加新工具/服务器。
项目结构
├── client.py # Main client that connects to MCP servers and runs the agent
├── mathserver.py # Local math tool server (add, multiply)
├── weather.py # Weather tool server (returns weather info)
├── main.py # Simple hello-world entry point
├── requirements.txt # Python dependencies
├── pyproject.toml # Project metadata and dependencies
├── README.md # This file快速启动
1.安装依赖项
pip install -r requirements.txt2.设置环境变量
创建一个 .env 使用Groq API密钥在项目根目录中创建文件:
GROQ_API_KEY=your_groq_api_key_here3.启动服务器
数学服务器(本地,stdio):
python mathserver.py天气服务器(HTTP,端口8000):
uvicorn weather:app --host 0.0.0.0 --port 8000
# OR, if using FastMCP's built-in runner:
python weather.py4.运行客户端
python client.py输出示例
Math Response: The answer to (5 + 3) * 12 is 96.
Weather response: It's always rainning in Kolkata运作原理
client.py创建aMultiServerMCPClient连接到数学(stdio)和天气(HTTP)服务器。- 它从两个服务器加载可用工具,并使用Groq的Qwen3-32B LLM创建LangChain ReAct代理。
- 代理可以通过调用适当的工具/服务器来回答数学和天气问题。
添加新工具
- 创建新的服务器文件(请参见
mathserver.py或weather.py模板)。 - 在注册您的工具
@mcp.tool()装饰师。 - 将服务器配置添加到
MultiServerMCPClient在……里面client.py.
需求
- Python 3.13+
- 看
requirements.txt对于Python包
作者
Subhadeep保罗
鸣谢
______________________________________________________________________
_该项目用于示范和教育目的。_
