天气 MCP 服务器
这是一个模型上下文协议 (MCP) 服务器,使用国家气象局 (NWS) API 提供天气信息。
特征
- 获取美国某州的天气警报
- 获取特定位置的天气预报(使用纬度和经度)
要求
- Python 3.10+
- FastMCP
- httpx
安装
- 克隆此存储库
- 设置虚拟环境:
- 使用 uv 安装所需的软件包:
配置
服务器使用具有以下设置的配置文件config.py
:
NWS_API_BASE
:国家气象局 API 的基本 URLUSER_AGENT
:向 NWS API 发出请求时使用的 User-Agent 字符串LOG_LEVEL
:日志记录级别(例如“INFO”、“DEBUG”)LOG_FORMAT
:日志消息的格式字符串REQUEST_TIMEOUT
:API 请求的超时时间(秒)
您可以在config.py
文件中修改这些设置来定制服务器行为。
用法
独立运行服务器
要独立运行服务器:
- 如果尚未激活,请激活虚拟环境:
- 运行服务器:
与 Cline 一起使用
Weather MCP 服务器已添加到 Cline 配置中。在 Cline 中使用它:
- 确保 Cline 已正确设置并运行。
- Weather MCP 服务器将作为名为“weather”的工具提供。
- 您可以在 Cline 中使用以下工具:a.
get_alerts(state: str)
:获取美国某个州的天气警报(使用两个字母的州代码,例如“CA”代表加利福尼亚州)b.get_forecast(latitude: float, longitude: float)
:获取特定位置的天气预报
Cline 中的用法示例:
注意:调用 MCP 工具的具体语法可能因您的 Cline 设置而异。请参阅 Cline 文档以获取最新的使用说明。
错误处理和日志记录
该服务器改进了 API 请求和日志记录的错误处理功能。如果请求过程中发生错误,服务器将记录该错误并返回相应的错误消息。日志将以配置的日志级别和格式打印到控制台。
测试
单元测试
运行单元测试:
这些测试涵盖了get_alerts
和get_forecast
工具的基本功能。
手动测试
要手动测试服务器,您可以使用 MCP 客户端调用提供的工具。以下是一些示例命令:
贡献
欢迎贡献代码!欢迎提交 Pull 请求。
执照
该项目是开源的,可根据MIT 许可证使用。
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.
这是一个模型上下文协议 (MCP) 服务器,使用国家气象局 (NWS) API 提供天气信息。
功能获取美国某个州的天气警报获取特定位置的天气预报(使用纬度和经度)
Related Resources
Related MCP Servers
- -securityFlicense-qualityThis SSE-based MCP server allows users to connect and interact with National Weather Service APIs to retrieve weather alerts and forecasts.Last updated -90Python
- AsecurityAlicenseAqualityModel Context Protocol (MCP) server that provides weather forecast, warnings, water level associated with flood, and earthquake reports from Malaysia Government's Open API.Last updated -4PythonMIT 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 -16TypeScriptMIT License