SampleMCP
SampleMCP
一个简单的 Python 项目,演示了如何使用 FastMCP、LangChain MCP 适配器、LangGraph 和 OpenAI 构建并连接 MCP 服务器。
功能
使用
stdio的数学 MCP 服务器使用
streamable-http的天气 MCP 服务器连接多个 MCP 服务器的 LangChain MCP 客户端
使用 MCP 工具的 LangGraph ReAct 代理
数学和天气查询的工具调用示例
项目结构
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 installed
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
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/JayantPrakash/SampleMCP'
If you have feedback or need assistance with the MCP directory API, please join our Discord server