Skip to main content
Glama

Weather-MCP-Server

天气 MCP 服务器

这是一个模型上下文协议 (MCP) 服务器,使用国家气象局 (NWS) API 提供天气信息。

特征

  • 获取美国某州的天气警报
  • 获取特定位置的天气预报(使用纬度和经度)

要求

  • Python 3.10+
  • FastMCP
  • httpx

安装

  1. 克隆此存储库
  2. 设置虚拟环境:
    python -m venv .venv source .venv/bin/activate # On Windows, use `.venv\Scripts\activate`
  3. 使用 uv 安装所需的软件包:
    uv add "mcp[cli]" httpx

配置

服务器使用具有以下设置的配置文件config.py

  • NWS_API_BASE :国家气象局 API 的基本 URL
  • USER_AGENT :向 NWS API 发出请求时使用的 User-Agent 字符串
  • LOG_LEVEL :日志记录级别(例如“INFO”、“DEBUG”)
  • LOG_FORMAT :日志消息的格式字符串
  • REQUEST_TIMEOUT :API 请求的超时时间(秒)

您可以在config.py文件中修改这些设置来定制服务器行为。

用法

独立运行服务器

要独立运行服务器:

  1. 如果尚未激活,请激活虚拟环境:
    source .venv/bin/activate # On Windows, use `.venv\Scripts\activate`
  2. 运行服务器:
    python weather.py

与 Cline 一起使用

Weather MCP 服务器已添加到 Cline 配置中。在 Cline 中使用它:

  1. 确保 Cline 已正确设置并运行。
  2. Weather MCP 服务器将作为名为“weather”的工具提供。
  3. 您可以在 Cline 中使用以下工具:a. get_alerts(state: str) :获取美国某个州的天气警报(使用两个字母的州代码,例如“CA”代表加利福尼亚州)b. get_forecast(latitude: float, longitude: float) :获取特定位置的天气预报

Cline 中的用法示例:

# Get alerts for California result = await mcp.call_tool("weather.get_alerts", state="CA") print(result) # Get forecast for San Francisco (approximate coordinates) result = await mcp.call_tool("weather.get_forecast", latitude=37.7749, longitude=-122.4194) print(result)

注意:调用 MCP 工具的具体语法可能因您的 Cline 设置而异。请参阅 Cline 文档以获取最新的使用说明。

错误处理和日志记录

该服务器改进了 API 请求和日志记录的错误处理功能。如果请求过程中发生错误,服务器将记录该错误并返回相应的错误消息。日志将以配置的日志级别和格式打印到控制台。

测试

单元测试

运行单元测试:

python -m unittest test_weather.py

这些测试涵盖了get_alertsget_forecast工具的基本功能。

手动测试

要手动测试服务器,您可以使用 MCP 客户端调用提供的工具。以下是一些示例命令:

# Get alerts for California result = await mcp.call_tool("get_alerts", state="CA") print(result) # Get forecast for San Francisco (approximate coordinates) result = await mcp.call_tool("get_forecast", latitude=37.7749, longitude=-122.4194) print(result)

贡献

欢迎贡献代码!欢迎提交 Pull 请求。

执照

该项目是开源的,可根据MIT 许可证使用。

-
security - not tested
F
license - not found
-
quality - not tested

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 提供天气信息。

功能获取美国某个州的天气警报获取特定位置的天气预报(使用纬度和经度)

  1. 特征
    1. 要求
      1. 安装
        1. 配置
          1. 用法
            1. 独立运行服务器
            2. 与 Cline 一起使用
          2. 错误处理和日志记录
            1. 测试
              1. 单元测试
              2. 手动测试
            2. 贡献
              1. 执照

                Related MCP Servers

                • -
                  security
                  F
                  license
                  -
                  quality
                  This SSE-based MCP server allows users to connect and interact with National Weather Service APIs to retrieve weather alerts and forecasts.
                  Last updated -
                  90
                  Python
                • A
                  security
                  A
                  license
                  A
                  quality
                  Model 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 -
                  4
                  Python
                  MIT License
                • -
                  security
                  F
                  license
                  -
                  quality
                  An 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
                  • Linux
                  • Apple
                • -
                  security
                  A
                  license
                  -
                  quality
                  An 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 -
                  16
                  TypeScript
                  MIT License

                View all related MCP servers

                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/JackKuo666/Weather-MCP-Server'

                If you have feedback or need assistance with the MCP directory API, please join our Discord server