Skip to main content
Glama

多服务器模型上下文协议(MCP)演示

一个完整的演示,展示如何构建和集成多个模型上下文协议(MCP)服务器,并与由 Groq 和实时 OpenWeatherMap 数据驱动的 LangGraph ReAct 代理协同工作。

该项目展示了 LLM 代理如何在一个统一的工作流中动态发现并使用来自不同 MCP 服务器和传输协议(stdiostreamable-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

组件

  1. 数学 MCP 服务器(mathserver.py

    • 使用 FastMCP 构建。

    • 通过 stdio 传输运行。

    • 公开算术工具:addsubmuldiv

    • 由 MCP 客户端自动作为后台子进程启动。

  2. 天气 MCP 服务器(weatherserver.py

    • 使用 FastMCP 构建,通过 streamable-http 传输在 http://127.0.0.1:8000/mcp 上运行。

    • 使用 httpxOpenWeatherMap API 获取实时气象数据。

    • 公开 get_weather 工具(返回温度、天气描述、体感温度和湿度)。

  3. 编排客户端(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. 前提条件

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.txt

3. 环境配置

在根目录下创建一个 .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%

📦 依赖项


📄 许可证

本项目是开源的,并根据 MIT 许可证 提供。

F
license - not found
-
quality - not tested
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

View all related MCP servers

Related MCP Connectors

  • MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.

  • MCP server exposing the Backtest360 engine API as tools for AI agents.

  • Agent-native collaboration network: orchestrate a team of long-running agents from any MCP client.

View all MCP Connectors

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/sreeshanthkprakash-stack/MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server