🧠 配备LangChain和AI工具的MCP服务器
该项目演示了如何构建 多工具人工智能助手 使用 模型上下文协议(MCP)LangChain和Groq的Qwen模型。它包括:
- 📐 当地人 数学MCP服务器
- 🌤️ A模拟 气象MCP服务器
- 🤖 对话 AI 代理 (MCP客户)与双方进行对话
______________________________________________________________________
🧰 特性
- 用途 LangChain MCP适配器 连接工具
- 由...驱动 Groq's Qwen法学硕士
- 通过MCP处理本地和远程工具服务器
- 具有工具使用检测功能的交互式CLI聊天
______________________________________________________________________
🏁 先决条件
- Python>=3.11
uv用于项目/环境管理(https://github.com/astral-sh/uv)- 用于加载LLM(Groq)的互联网连接
______________________________________________________________________
⚙️ 安装说明
1.创建项目
mkdir mcp_project
cd mcp_project
uv init将.Python版本和pyproject.toml中的Python版本设置为>=3.11
2.创建虚拟环境
uv venv
source .venv/Scripts/activate3.添加依赖项
Create a requirements.txt file:
langchain-mcp-adapters
langchain-groq
langgraph
mcp安装它们
uv add -r requirements.txt项目结构
mcp项目/ │ ├── math_server.py#用于数学工具的MCP服务器 ├── weather_server.py#用于天气API模拟的MCP服务器 ├── client.py#带有AI代理的MCP客户端 ├── 需求.txt ├── .python版本 └── .env#用于存储Groq API密钥(Groq_API_key)
如何跑步
1.运行天气服务器
python weather_server.py2.运行客户端(自动将数学服务器作为子进程运行)
python client.py对话示例
You: What is the output of 2*3/(4-2)
AI: The result is 3.0
You: What is the weather in New York?
AI: The current weather in New York is sunny.
You: thanks
AI: You're welcome! 😊