基于 SSE 的MCP服务器和客户端
这演示了基于 SSE 的 MCP 服务器和使用其工具的独立 MCP 客户端的工作模式。基于此处的原始讨论。
用法
注意:确保在.env
中或作为环境变量提供ANTHROPIC_API_KEY
。
为什么?
这意味着 MCP 服务器现在可以是一个正在运行的进程,代理(客户端)可以随时随地连接、使用和断开连接。换句话说,基于 SSE 的服务器和客户端可以是解耦的进程(甚至可能位于解耦的节点上)。这与基于 STDIO 的模式(客户端本身会将服务器作为子进程生成)不同,并且更适合“云原生”用例。
通过 Smithery 安装
要通过Smithery自动为 Claude Desktop 安装基于 SSE 的服务器和客户端:
服务器
weather.py
是一个基于 SSE 的 MCP 服务器,它提供了一些基于国家气象局 API 的工具。改编自 MCP 文档中的示例 STDIO 服务器实现。
默认情况下,服务器在 0.0.0.0:8080 上运行,但可以使用命令行参数进行配置,例如:
客户
client.py
是一个 MCP 客户端,用于连接并使用基于 SSE 的 MCP 服务器的工具。代码改编自 MCP 文档中STDIO 客户端的示例实现。
默认情况下,客户端连接到命令行参数中提供的 SSE 端点,例如:
This server cannot be installed
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
这个基于 SSE 的 MCP 服务器允许用户连接并与国家气象局 API 交互以检索天气警报和预报。
Related Resources
Related MCP Servers
- -securityFlicense-qualityThis is a Model Context Protocol (MCP) server that provides weather information using the National Weather Service (NWS) API. Features Get weather alerts for a US state Get weather forecast for a specific location (using latitude and longitude)Last updated -Python
- AsecurityAlicenseAqualityAn MCP server that provides real-time weather information including temperature, humidity, wind speed, and sunrise/sunset times through the OpenWeatherMap API.Last updated -1PythonMIT License
- -securityFlicense-qualityAn MCP server implementation that allows users to fetch and display weather information for specified cities, including temperature, humidity, wind speed, and weather descriptions.Last updated -Python
- -securityAlicense-qualityAn MCP server that connects to OpenWeatherMap's API to provide current weather data and multi-day forecasts for locations worldwide in different measurement units.Last updated -12TypeScriptMIT License