Skip to main content
Glama
KDimkuz

mcp-weather-connector

by KDimkuz

mcp-weather-connector

这是一个 MCP 服务器,用于通过 Open-Meteo 让 AI 智能体访问天气预报——一个无需密钥和注册即可使用的公共 API。

这个仓库刻意做得很小:重点在于为智能体构建工具层的方式,而不是天气本身。这里用天气作为一个容易理解的例子,来展示模型与外部世界之间的信任边界。

为什么需要这个

Model Context Protocol 是一种允许语言模型在外部服务中执行操作的方式。一旦拥有了这种权限,问题就来了:如果模型给工具传入了垃圾数据,而外部服务此刻正好返回 503,会发生什么?

这段代码中明确展示了三个决策:

来自模型的输入是不可信的。 模型可能传入空字符串、长达十几 KB 的文本块或控制字符。所有这一切都会在 server.py 中、在网络调用发生之前被拦截掉,而不是交给外部 API 处理。

错误按类型区分。 4xx 错误重试没有意义——这是请求错误,重试也不会解决。5xx 通常是偶发故障——带短暂停顿重试一次。逻辑在 _get_json 中,并用调用计数测试验证。

对外输出的是文本,而不是原始 JSON。 智能体无需自己揣测,也不容易在转述时出错。返回 200 但缺少所需字段时被视为故障,而不是有机会返回空内容。

另外:超出范围的天数会被限制到边界值,而不是被当作错误。如果模型请求 37 天的预报,那么给出 7 天也是比用错误消息打断对话更好的一个方案。

Related MCP server: open-meteo-mcp-server

工具集

工具

作用

current_weather(city)

当前天气:温度、体感、湿度、风力

forecast(city, days=3)

未来 1–7 天预报,包含降水量

locate(query)

检查居民点是否存在并区分国家

locate 的存在是为了应对一个场景:当智能体不确定地名拼写时,最好先向用户确认,而不是默默给出另一个城市的天气。

安装

pip install -e .

连接到 Claude Desktop

claude_desktop_config.json 中:

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

重启应用后,工具会出现在可用列表中。

开发

pip install -e ".[dev]"
pytest
ruff check .

测试覆盖了真正容易出问题的情形:空输入和超长输入、非数字的天数、4xx 不重试、5xx 只重试一次、第二次尝试成功、返回 200 但无有效载荷、未知天气代码。HTTP 测试通过 respx 模拟,测试中不需要真实网络。

结构

src/mcp_weather/
    client.py    — работа с Open-Meteo: типы, повторы, разбор ответа
    server.py    — MCP-слой: валидация входа и форматирование вывода
tests/
    test_tools.py

网络代码特意与 MCP 层分离:客户端可以独立测试,而智能体工具则只是对接清晰函数的轻薄封装。

许可证

MIT

Install Server
A
license - permissive license
A
quality
C
maintenance

Maintenance

Maintainers
Response time
Release cycle
Releases (12mo)
Commit activity

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Servers

  • A
    license
    Not graded
    quality
    F
    maintenance
    Enables AI assistants to retrieve current weather, forecasts, and summaries for any global location using the Open-Meteo API, with no API key required.
    21
    Creative Commons Zero v1.0 Universal
  • A
    license
    A
    quality
    D
    maintenance
    Provides comprehensive access to Open-Meteo weather APIs, including forecasts, historical data, air quality, marine weather, and geocoding, enabling LLMs to retrieve weather information and location data.
    17
    668
    1
    MIT
  • A
    license
    Not graded
    quality
    C
    maintenance
    Provides live weather data (current conditions, forecasts) and city geocoding through Open-Meteo API, enabling AI assistants to answer weather queries without an API key.
    MIT

View all related MCP servers

Related MCP Connectors

  • Global weather via Open-Meteo: forecast, ERA5 archive, marine, air quality, geocoding, elevation.

  • US weather & geo for AI agents: forecasts, alerts, earthquakes, elevation, geocoding. No keys.

  • Real-time weather conditions and multi-day forecasts via Open-Meteo — free, no API key required

View all MCP Connectors

Latest Blog Posts

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/KDimkuz/mcp-weather-connector'

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