Back to MCP directory
publicPublicdnsLocal runtime

weekly-weather-mcp

一个基于OpenWeatherMap API的天气MCP服务,提供全球8天天气预报和实时天气数据,支持多时区显示和详细天气参数查询。

article

README

🚀 如何使用Weather MCP服务器

本项目提供了一个Weather MCP服务器,借助OpenWeatherMap的One Call API 3.0,能够获取特定地区的当前天气和未来8天的天气预报,为用户提供风速、降水量等详细的天气信息。

🚀 快速开始

安装与配置

  1. 安装依赖项
    pip install openweathermap-api python-multipart
    
  2. 设置API密钥
    • 在环境变量中设置 OPENWEATHER_API_KEY
      export OPENWEATHER_API_KEY="your_api_key"
      
    • 或者在代码中直接传递 api_key 参数。
  3. 运行服务器
    python3 weather_mcp_server.py
    

✨ 主要特性

  • 提供两个实用工具:get_weatherget_current_weather
  • 采用OpenWeatherMap的One Call API 3.0。
  • 支持8天天气预报(涵盖今天和未来7天)。
  • 包含每个时间段的早间、午间和晚间天气数据。
  • 显示风速、降水量和其他天气摘要。

💻 使用示例

基础用法

# 获取当前天气
python3 weather_mcp_server.py --current-weather --city New York

# 获取天气预报
python3 weather_mcp_server.py --weather-forecast --location "Beijing,China"

高级用法

  • 支持多天天气数据查询(最多8天)。
  • 可指定具体时间点的天气信息。
  • 提供详细的气象数据,包括降水量、风向等。

输入输出示例

示例输入:

{
  "city": "New York",
  "state": "NY",
  "country": "US"
}

示例输出:

{
  "current_weather": {
    "temperature": 22,
    "condition": "Partly Cloudy",
    "wind_speed": 12,
    "humidity": 65
  },
  "hourly_forecast": [...],
  "daily_forecast": [...]
}

📚 详细文档

问题排查

API密钥问题

  1. 确保已订阅OpenWeatherMap的One Call API 3.0计划。
  2. 确认API密钥在环境变量中正确设置。
  3. 检查是否有超过免费配额的情况。

其他常见问题

  • 位置未找到:检查输入的准确性,尝试添加国家代码。
  • 速率限制:减少API调用频率或升级至付费计划。

开发与测试

自动化测试

  1. 单元测试:
    python test_weather_mcp.py
    
  2. 集成测试:
    python integration_test.py
    

手动测试

# 运行测试客户端
python3 weather_test_client.py --test-all

📄 最后更新

2023年11月4日

help

Runtime guide

cloud

Hosted runtime

Hosted servers run from a provider-managed environment. You usually connect the MCP client to the hosted endpoint or follow the provider's authorization flow, without keeping a local process alive

  1. Open provider connection page
  2. Authorize or copy endpoint
  3. Connect from your MCP client
terminal

Local runtime / other methods

Local servers run on your own machine or infrastructure. You normally copy the server_config into your MCP client, install the required package, and provide env variables from env_schema when needed

  1. Copy server_config
  2. Install required package
  3. Fill env variables and restart client