Skip to main content
Glama
weather-mcp

weather-mcp

by hammerZh-Z

Weather MCP

一个基于 Open-Meteo 的 MCP 天气服务:提供"按天数"和"按星期几"两种查询方式,返回 Markdown(默认)或 JSON。

环境要求

  • Python:3.13+

  • 依赖:httpx、pydantic、mcp(见 pyproject.toml)

Related MCP server: Weather MCP Server

快速开始

方式 1:使用 uvx 直接运行(推荐)

无需安装,直接运行:

uvx weather-mcp

方式 2:从 PyPI 安装

pip install weather-mcp

然后运行:

weather-mcp

方式 3:本地开发

安装依赖(如果你使用 uv):

uv sync

或使用 pip:

pip install httpx>=0.27.0 pydantic>=2.6.0 mcp>=0.1.0

工具列表

1) weather_query_by_days

查询“指定城市在 N 天后”的天气(支持 0~16 天)。

输入参数:

  • city(string):城市名(如 北京、上海、New York)

  • days_later(int):未来第几天(0=今天,1=明天,范围 0-16)

  • response_format(string,可选):markdown 或 json(默认 markdown)

示例(以 MCP 工具入参 JSON 表示):

{"city":"北京","days_later":1,"response_format":"markdown"}

2) weather_query_by_weekday

查询“下一个指定星期几”的天气。

输入参数:

  • city(string):城市名(如 北京、上海、New York)

  • target_weekday(string):目标星期(英文,大小写不敏感):Monday/Tuesday/Wednesday/Thursday/Friday/Saturday/Sunday

  • response_format(string,可选):markdown 或 json(默认 markdown)

说明:

  • 如果今天刚好是 target_weekday,为了避免歧义,本工具会查询“下周同一天”(即 +7 天)。

示例:

{"city":"上海","target_weekday":"Saturday","response_format":"json"}

返回内容

Markdown(默认)

包含(如有数据):

  • 天气状况(WMO code 映射的中文描述)

  • 最高/最低温、最高/最低体感温

  • 降水量、最大降水概率

  • 最大风速

  • 最大/最小湿度

  • 最大紫外线指数(含等级:低/中等/高/很高/极高)

  • 日出/日落时间

JSON

工具会返回一个 JSON 字符串,结构类似:

  • 顶层:city、country、date、latitude、longitude

  • weather:包含 Open-Meteo daily 下的各字段在目标日期对应的值(例如 weathercode、temperature_2m_max、precipitation_sum、sunrise、sunset 等)

MCP 服务配置

本服务使用 STDIO (标准输入输出) 传输方式。

快速启动配置

方式 1:使用 weather-mcp 命令(推荐)

如果已通过 pip 或 uvx 安装:

{
  "command": "weather-mcp",
  "args": [],
  "env": {}
}

方式 2:使用 uvx 直接运行

{
  "command": "uvx",
  "args": ["weather-mcp"],
  "env": {}
}

方式 3:使用 Python 直接运行

{
  "command": "python",
  "args": ["weather.py"],
  "env": {}
}

配置说明

  • 传输方式:STDIO (标准输入输出)

  • 环境变量:无需额外环境变量配置

  • 托管类型:仅本地可用(STDIO 方式需要本地运行)

  • 网络要求:需要能访问 Open-Meteo API (api.open-meteo.com 和 geocoding-api.open-meteo.com)

Claude Desktop 配置示例

在 Claude Desktop 的配置文件中添加:

{
  "mcpServers": {
    "weather": {
      "command": "weather-mcp"
    }
  }
}

或者使用 uvx:

{
  "mcpServers": {
    "weather": {
      "command": "uvx",
      "args": ["weather-mcp"]
    }
  }
}

备注与限制

  • 预报范围:Open-Meteo 日级预报限制为 0-16 天。

  • 城市解析:先通过 Open-Meteo Geocoding 获取经纬度,再拉取预报(需要可访问外网)。

  • 错误返回:出错时返回以 Error: 开头的字符串(例如城市不存在、参数校验失败、请求超时/限流等)。

  • 传输方式:使用 STDIO 传输,需要在本地运行,适合集成到 MCP 客户端(如 Claude Desktop)。

Available Tools

2 tools
weather_query_by_daysA
Read-onlyIdempotent

查询指定城市在指定天数后的天气情况。

这个工具可以查询未来16天内任意一天的天气预报,包括温度、降水、风力等信息。

Args: params (WeatherQueryInput): 已验证的输入参数,包含: - city (str): 城市名称(例如:'北京', '上海', 'New York', 'London') - days_later (int): 未来的天数(0=今天, 1=明天, 2=后天, 范围:0-16) - response_format (ResponseFormat): 输出格式,默认为markdown

Returns: str: 格式化的天气信息

成功响应包含:
- 天气状况(晴朗、多云、雨等)
- 温度范围(最低/最高温度)
- 体感温度
- 降水量和降水概率
- 风速
- 湿度
- 紫外线指数
- 日出日落时间

错误响应:
"Error: <错误信息>"

Examples: - 查询明天的天气: city="北京", days_later=1 - 查询后天的天气: city="上海", days_later=2 - 查询7天后的天气: city="New York", days_later=7

Error Handling: - 如果城市名称无效,返回城市未找到错误 - 如果天数超出范围(0-16),返回验证错误 - 如果API请求失败,返回相应的错误信息

Inputs: params (required). Returns: result

weather_query_by_weekdayA
Read-onlyIdempotent

查询指定城市在下一个指定星期几的天气情况。

这个工具可以查询下一个指定星期几(如本周六、本周日)的天气预报。

Args: params (WeekdayQueryInput): 已验证的输入参数,包含: - city (str): 城市名称(例如:'北京', '上海', 'New York') - target_weekday (str): 目标星期几(例如:'Saturday', 'Sunday', 'Monday') - response_format (ResponseFormat): 输出格式,默认为markdown

Returns: str: 格式化的天气信息,包含与weather_query_by_days相同的详细信息

Examples: - 查询本周六的天气: city="北京", target_weekday="Saturday" - 查询本周日的天气: city="上海", target_weekday="Sunday" - 查询下周一的天气: city="Guangzhou", target_weekday="Monday"

Error Handling: - 如果城市名称或星期几无效,返回相应的验证错误 - 如果API请求失败,返回相应的错误信息

Inputs: params (required). Returns: result

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.7/5.0

    Scored across 2 tools

    Disambiguation4/5

    The two tools differ only in how the target date is expressed (day offset vs. weekday name) and return identical data, so an agent must decide between query interfaces rather than distinct capabilities. The descriptions make the boundary clear enough (0-16 day range vs. next occurrence of a weekday), but the overlap is real since weather_query_by_weekday is essentially a syntactic sugar wrapper over weather_query_by_days.

    Naming Consistency5/5

    Both tools follow an identical, predictable 'weather_query_by_<dimension>' pattern with snake_case throughout. The suffix directly reflects the parameter that distinguishes them, which reinforces rather than confuses the distinction.

    Tool Count3/5

    Two tools is thin for a weather service; the surface is entirely forecast-by-date and nothing else. A weather domain naturally supports current conditions, hourly data, or location resolution, so the set feels under-scoped even for a deliberately minimal server.

    Completeness3/5

    The 16-day forecast with rich detail is well covered, and 'today' is reachable via days_later=0, so the core query is not a dead end. However there is no geocoding/city validation tool, no current-conditions or hourly tool, and no way to query multiple cities or historical data, leaving notable gaps for a weather domain.

    Maintenance

    ActivityInactive
    ResponsivenessSyncing

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables users to get current weather information for any city using the Open-Meteo API. Provides detailed meteorological data including temperature, precipitation, day/night status, and hourly forecasts through natural language queries.
      ISC
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to fetch current weather conditions and forecasts for any city using the Open-Meteo API. Provides temperature, precipitation, and hourly forecast data through natural language queries.
      ISC
    • F
      license
      Not graded
      quality
      D
      maintenance
      Provides real-time and historical weather data for any city worldwide, including forecasts, air quality, and marine conditions, using the free Open-Meteo API.
      -