本项目展示了基于 SSE 的 MCP 服务器以及独立 MCP 客户端工具的工作模式。其灵感源自此处的原始讨论。通过本示例,用户可以了解如何实现解耦的 MCP 服务器与客户端进程,为实际应用提供参考。
⚠️ 重要提示
请确保在
.env或环境变量中提供ANTHROPIC_API_KEY。
uv run weather.py
uv run client.py http://0.0.0.0:8080/sse
Initialized SSE client...
Listing tools...
Connected to server with tools: ['get_alerts', 'get_forecast']
MCP Client Started!
Type your queries or 'quit' to exit.
Query: whats the weather like in Spokane?
I can help you check the weather forecast for Spokane, Washington. I'll use the get_forecast function, but I'll need to use Spokane's latitude and longitude coordinates.
Spokane, WA is located at approximately 47.6587° N, 117.4260° W.
[Calling tool get_forecast with args {'latitude': 47.6587, 'longitude': -117.426}]
Based on the current forecast for Spokane:
Right now it's sunny and cold with a temperature of 37°F and ...
本项目基于 SSE 实现的 MCP 服务器和客户端具有以下特性:
要通过 Smithery 自动安装基于 SSE 的 MCP 服务器和客户端,可使用以下命令:
npx -y @smithery/cli install @sidharthrajaram/mcp-sse --client claude
weather.py 是一个基于 SSE 的 MCP 服务器,它提供了一些基于国家气象局 API 的工具。该服务器改编自 MCP 文档中的 示例 STDIO 服务器实现。
默认情况下,服务器运行在 0.0.0.0:8080,可使用以下命令启动:
uv run weather.py
可以通过命令行参数配置服务器的主机和端口,例如:
uv run weather.py --host --port
client.py 是一个 MCP 客户端,用于连接并使用基于 SSE 的 MCP 服务器中的工具。该客户端改编自 MCP 文档中的 示例 STDIO 客户端实现。
默认情况下,客户端通过命令行参数连接到 SSE 端点,例如:
uv run client.py http://0.0.0.0:8080/sse