SampleMCP
SampleMCP
一个简单的 Python 项目,演示了如何使用 FastMCP、LangChain MCP 适配器、LangGraph 和 OpenAI 构建并连接 MCP 服务器。
功能
使用
stdio的数学 MCP 服务器使用
streamable-http的天气 MCP 服务器连接多个 MCP 服务器的 LangChain MCP 客户端
使用 MCP 工具的 LangGraph ReAct 代理
数学和天气查询的工具调用示例
Related MCP server: Server MCP
项目结构
SampleMCP/
├── client.py # MCP client + LangGraph agent
├── mathserver.py # Math MCP server with add/multiply tools
├── weather.py # Weather MCP server using streamable HTTP
├── main.py # Basic sample entry point
├── pyproject.toml # Project metadata and dependencies
├── requirements.txt # Python dependencies
└── README.md要求
Python 3.12+
OpenAI API 密钥
可选:Groq API 密钥
安装
克隆仓库:
git clone https://github.com/JayantPrakash/SampleMCP.git
cd SampleMCP安装依赖:
pip install -r requirements.txt或者使用 uv:
uv sync环境变量
在项目根目录下创建一个 .env 文件:
OPENAI_API_KEY=your_openai_api_key
GROQ_API_KEY=your_groq_api_key运行 MCP 服务器
1. 启动天气服务器
天气服务器使用 streamable-http。
python weather.py默认情况下,它在以下地址暴露 MCP 端点:
http://localhost:8000/mcp2. 数学服务器
数学服务器使用 stdio,并由客户端通过以下方式自动启动:
"command": "python",
"args": ["mathserver.py"],
"transport": "stdio"运行客户端
在另一个终端中,运行:
python client.py客户端连接到:
通过
stdio连接的mathserver.py通过
streamable_http连接的weather.py
然后它会创建一个 LangGraph ReAct 代理并询问:
what's (3 + 5) x 12?以及:
what is the weather in California?MCP 工具
数学服务器
定义在 mathserver.py 中。
add(a: int, b: int) -> int将两个数字相加。
multiple(a: int, b: int) -> int将两个数字相乘。
天气服务器
定义在 weather.py 中。
get_weather(location: str) -> str返回给定地点的示例天气响应。
注意事项
mathserver.py使用transport="stdio"。weather.py使用transport="streamable-http"。在
client.py中,可流式 HTTP 传输配置为streamable_http。在执行
client.py之前,请确保天气服务器正在运行。
示例输出
Math response: 96
Weather response: It's always raining in CaliforniaThis server cannot be deployed
Maintenance
Related MCP Connectors
Nifty's MCP server — exposes tasks, projects, messages, and files as tools for AI agents.
MCP server for langchain documentation, generated by doc2mcp.
MCP server for progressive tool usage at any scale (see https://klavis.ai)
MCP server for AI agents to plan, verify, and deploy Cloudflare-native apps.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceDemonstrates an MCP server with calculate and text_stats tools over Streamable HTTP, integrating with LangChain/LangGraph and n8n agents.-
- FlicenseNot gradedqualityDmaintenanceProvides math and weather tools accessible via LangGraph agent using MCP protocol with stdio and streamable HTTP transports.1-
- FlicenseNot gradedqualityDmaintenanceA collection of MCP servers demonstrating math operations, weather data, and LangGraph workflows.1-
- FlicenseNot gradedqualityDmaintenanceA model-agnostic MCP server exposing example tools (add1, multiply2, greet) for learning purposes, working with any LLM through stdio transport.-