MCP-Server
多服务器模型上下文协议(MCP)演示
一个完整的演示,展示如何构建和集成多个模型上下文协议(MCP)服务器,并与由 Groq 和实时 OpenWeatherMap 数据驱动的 LangGraph ReAct 代理协同工作。
该项目展示了 LLM 代理如何在一个统一的工作流中动态发现并使用来自不同 MCP 服务器和传输协议(stdio 和 streamable-http)的工具。
🏗️ 架构
flowchart LR
subgraph Agent["LangGraph ReAct Agent (client.py)"]
ChatGroq["LLM: Groq (Qwen / ChatGroq)"]
MultiMCP["MultiServerMCPClient"]
end
subgraph MathServer["Math MCP Server (mathserver.py)"]
MathTools["Tools: add, sub, mul, div"]
end
subgraph WeatherServer["Weather MCP Server (weatherserver.py)"]
WeatherTools["Tool: get_weather (OpenWeatherMap API)"]
end
MultiMCP -- "stdio transport (subprocess)" --> MathServer
MultiMCP -- "streamable-http (http://127.0.0.1:8000/mcp)" --> WeatherServer组件
数学 MCP 服务器(
mathserver.py):使用 FastMCP 构建。
通过
stdio传输运行。公开算术工具:
add、sub、mul、div。由 MCP 客户端自动作为后台子进程启动。
天气 MCP 服务器(
weatherserver.py):使用 FastMCP 构建,通过
streamable-http传输在http://127.0.0.1:8000/mcp上运行。使用
httpx从 OpenWeatherMap API 获取实时气象数据。公开
get_weather工具(返回温度、天气描述、体感温度和湿度)。
编排客户端(
client.py):使用
langchain-mcp-adapters中的MultiServerMCPClient同时连接到两个 MCP 服务器。组装工具,并使用 Groq 的快速 LLM 推理(
ChatGroq)驱动 LangGraph ReAct 代理。
Related MCP server: AIE8-MCP Server
📁 项目结构
Mcp_demo/
├── client.py # ReAct Agent & Multi-Server MCP client orchestrator
├── mathserver.py # FastMCP server running on stdio transport
├── weatherserver.py # FastMCP server with OpenWeatherMap API on HTTP transport
├── requirements.txt # Python package dependencies
├── pyproject.toml # Project configuration & metadata
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules (protects .env and caches)
└── README.md # Project documentation🚀 快速开始
1. 前提条件
Python 3.10+
OpenWeatherMap API 密钥 (免费层级)
2. 安装
克隆仓库并安装依赖:
git clone https://github.com/sreeshanthkprakash-stack/MCP-Server.git
cd MCP-Server
# Create and activate virtual environment
python -m venv .venv
# On Windows:
.venv\Scripts\activate
# On Linux/macOS:
source .venv/bin/activate
# Install dependencies
pip install -r requirements.txt3. 环境配置
在根目录下创建一个 .env 文件(或从 .env.example 复制):
GROQ_API_KEY=your_groq_api_key_here
OPENWEATHER_API_KEY=your_openweather_api_key_here🧪 运行应用程序
步骤 1:启动天气 MCP 服务器
由于天气服务器通过 HTTP 通信,请先在终端中启动它:
python weatherserver.py天气服务器将开始监听
http://127.0.0.1:8000/mcp。
步骤 2:运行代理客户端
打开第二个终端窗口(确保虚拟环境已激活),然后运行:
python client.py预期输出示例
math_response The result of the expression ((15*20)+200)/4 is 125.
weather_response Weather in Hyderabad: haze, temperature 29.5°C (feels like 32.1°C), humidity 65%📦 依赖项
mcp:官方模型上下文协议 SDK(FastMCP)langchain-mcp-adapters:将 LangChain 连接到 MCP 服务器langgraph:基于图的代理编排运行时langchain-groq:使用 Groq 的高速 LLM 推理httpx:用于天气 API 请求的异步 HTTP 客户端python-dotenv:安全的环境变量加载
📄 许可证
本项目是开源的,并根据 MIT 许可证 提供。
This server cannot be deployed
Maintenance
Related MCP Connectors
LLM Orchestration Agent (Mcp)
One MCP endpoint for Claude, GPT & Gemini: 100+ tools + no-code connectors + agent workers.
LLM Orchestration MCP Agent
MCP server for building and testing AI agents with multi-model experimentation and insights.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceDemonstrates custom MCP servers for math and weather operations, enabling multi-agent orchestration using LangChain, Groq, and MCP adapters for both local and remote tool integration.1-
- FlicenseBqualityDmaintenanceAn MCP server that provides web search capabilities through the Tavily API and weather data retrieval tools. It demonstrates how to integrate external APIs into AI applications and build agentic workflows with LangGraph.3-
- FlicenseNot gradedqualityDmaintenanceA demonstration MCP server that provides math (add/multiply) and weather tools, connecting via stdio and streamable HTTP, and integrates with LangChain and LangGraph for agentic workflows.-
- FlicenseNot gradedqualityCmaintenanceAn MCP server that provides math tools (add, subtract, multiply) and a weather tool, with a LangChain agent client that uses Groq to answer natural language queries.-