使用说明
🌐 MCP多工具聊天机器人
一个由人工智能驱动的聊天机器人,连接到多个微服务(MCP服务器),用于执行以下专门任务 数学运算 和 天气检索 使用 LangChain MCP适配器, LangGraph,以及 格鲁克Qwen-32B 模型。
🚀 特性
- 🤖 基于ReAct框架的LangGraph代理
- 🔧 支持多种工具:数学(加法、乘法)、天气
- 🔌 通过以下方式访问可互操作的工具
MultiServerMCPClient - ⚡ Groq托管的Qwen-32B模型用于快速LLM推理
- 🧩 无缝集成本地(stdio)和HTTP流式MCP工具
🛠️ 技术栈
mcplangchain-groqlangchain-mcp-adapterslanggraphPython 3.10+.env(为GROQ_API_KEY)
📁 项目结构
.
├── mathserver.py # MCP server for Math tools
├── weatherserver.py # MCP server for Weather tool
├── main.py # Chatbot agent with LangGraph + MCP client
├── .env # Contains GROQ_API_KEY
├── README.md
📦 安装
git clone https://github.com/Hari-Kec/MCP-Chatbot.git
cd MCP-Chatbot
pip install -r requirements.txt
添加a .env 文件:
GROQ_API_KEY=your_groq_api_key
📜 用法
🧮 数学服务器(stdio)
python mathserver.py
🌦 天气服务器(可流式传输HTTP)
uvicorn weatherserver:app --port 8000
🧠 LangGraph代理
python main.py
🧪 样本输出
Math response: The answer is 96
Weather response: It's always raining in California
📚 工具定义
天气工具
@mcp.tool()
async def get_weather(location: str) -> str:
return "It's always raining in California"
数学工具
@mcp.tool()
def add(a: int, b: int) -> int:
return a + b
@mcp.tool()
def multiple(a: int, b: int) -> int:
return a * b
🔮 未来的增强功能
- ✅ 添加实时天气API集成
- ✅ 添加更多高级数学函数
- ✅ 在LangGraph中实现内存和上下文
📝 许可证
MIT许可证
