天气数据服务

Open-Meteo MCP Server是一个全面的模型上下文协议(MCP)服务器,为Open-Meteo天气API提供完整的功能,包括工具、资源和AI助手提示。

  • by Achrefjr1997
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Achrefjr1997/open-meteo-mcp

使用说明

打开Meteo MCP服务器

一个全面的模型上下文协议(MCP)服务器 开放天气 天气API,将API的全部功能展示为人工智能助手的工具、资源和提示。


🌟 特性

🌤️ 完整的天气数据访问

类别 覆盖范围 变量
当前天气 实时,15分钟分辨率 50+
每小时预测 长达16天 200+
每日预测 合计值 100+
历史天气 1940年至今(ERA5,ECMWF) 150+
空气质量 PM2.5、PM10、气体、空气质量指数、花粉 30+
海洋天气 波浪、涌浪、水温 20+
气候数据 长期模式,正常值 50+

🎯 天气模型覆盖范围

提供商 型号 分辨率 覆盖范围
ECMWF IFS高分辨率,合奏 9km 全球
美国国家海洋和大气管理局 GFS、HRRR、合奏 3-25km 北美
德国气象局 ICON Global/EU/D2 2-13km 欧洲/全球
天气-法国 ARPEGE,AROME 1.3-10公里 法国/欧洲
英国气象局 UKMO全球/英国 2-10km 英国/全球
遇见挪威 北欧,全球 2.5-10km 北欧/全球
ECCC(加拿大) GEM全球/区域 10-25km 北美
JMA(日本) MSM,GSM 5-20公里 日本/亚洲

🛠️ MCP组件

33工具 -API完全访问

  • 预测: get_current_weather, get_hourly_forecast, get_daily_forecast, get_15min_forecast, get_complete_forecast
  • 历史的: get_historical_hourly, get_historical_daily温度/降水/风分析
  • 空气质量: get_current_air_quality, get_air_quality_index, get_pollen_forecast, get_uv_index_forecast
  • 地理编码: search_location, get_location_by_id, resolve_coordinates, get_nearby_cities
  • 合奏: get_ensemble_forecast, compare_weather_models,特定于模型的工具
  • 海军陆战队: get_marine_forecast, get_elevation, get_climate_data
  • 实用: list_weather_variables, list_weather_models, get_weather_summary

25资源 -参考数据

  • 变量: weather://variables/{all,temperature,wind,precipitation,clouds,pressure,humidity,solar,soil,air_quality,marine,weather_codes,usage-guide}
  • 模型: weather://models/{all,ecmwf,noaa,dwd,meteo_france,ukmo,met_norway,eccc,jma,ensemble,comparison,usage-guide}

4提示 -AI助手指导

  • weather_analysis_prompt -一般天气援助最佳实践
  • marine_weather_prompt -海洋和沿海天气专业
  • climate_analysis_prompt -气候数据分析指南
  • air_quality_health_prompt -空气质量和健康建议

📦 安装

先决条件

  • Python 3.10或更高版本
  • pip(Python包管理器)
  • Docker(可选,用于容器化部署)

选项1:从源代码安装(推荐)

# Clone the repository
git clone https://github.com/Achrefjr1997/open-meteo-mcp.git
cd open-meteo-mcp

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Install the package
pip install -e .

选项2:安装开发依赖项

pip install -e ".[dev]"

选项3:Docker(生产就绪)

# Build the Docker image
docker build -t open-meteo-mcp .

# Run with Docker Compose (stdio transport)
docker compose up open-meteo-mcp

# Run with SSE transport (HTTP access on port 8000)
docker compose up open-meteo-sse

# Run test suite
docker compose --profile test up open-meteo-test

📘 Docker文档:参见 医生.md 完整的Docker设置,包括Kubernetes部署、资源限制和生产最佳实践。


⚙️ 配置

环境变量

变量 描述 默认值 必填
OPEN_METEO_API_KEY API密钥用于商业用途(每天超过1万次呼叫) 无 ❌
OPEN_METEO_TIMEOUT 请求超时(秒) 30.0 ❌
OPEN_METEO_TIMEZONE 默认时区(例如。, Africa/Tunis, Europe/Paris) GMT ❌
OPEN_METEO_RATE_LIMIT 速率限制延迟(秒) 0.1 ❌
OPEN_METEO_API_URL 预测API基础URL https://api.open-meteo.com ❌
OPEN_METEO_AIR_QUALITY_API_URL 空气质量API基础URL https://air-quality-api.open-meteo.com ❌
OPEN_METEO_MARINE_API_URL 船用API基础URL https://marine-api.open-meteo.com ❌
OPEN_METEO_ENSEMBLE_API_URL 集成API基础URL https://ensemble-api.open-meteo.com ❌
OPEN_METEO_CLIMATE_API_URL 气候API基础URL https://climate-api.open-meteo.com ❌
OPEN_METEO_GEOCODING_API_URL 地理编码API基础URL https://geocoding-api.open-meteo.com ❌
OPEN_METEO_ARCHIVE_API_URL 存档API基础URL https://archive-api.open-meteo.com ❌

配置示例

Linux/Mac:

export OPEN_METEO_API_KEY=your_api_key
export OPEN_METEO_TIMEOUT=60.0
export OPEN_METEO_TIMEZONE=Africa/Tunis

Windows(PowerShell):

$env:OPEN_METEO_API_KEY="your_api_key"
$env:OPEN_METEO_TIMEOUT="60.0"
$env:OPEN_METEO_TIMEZONE="Africa/Tunis"

Docker(.env文件):

OPEN_METEO_API_KEY=your_api_key
OPEN_METEO_TIMEOUT=60.0
OPEN_METEO_TIMEZONE=Africa/Tunis
# Custom API URLs (optional)
OPEN_METEO_API_URL=https://api.open-meteo.com
OPEN_METEO_AIR_QUALITY_API_URL=https://air-quality-api.open-meteo.com
OPEN_METEO_MARINE_API_URL=https://marine-api.open-meteo.com

常见时区

地区 时区
突尼斯 Africa/Tunis
法国 Europe/Paris
德国 Europe/Berlin
英国 Europe/London
美国东部 America/New_York
美国太平洋 America/Los_Angeles
日本 Asia/Tokyo
澳大利亚(悉尼) Australia/Sydney

🚀 用法

运行服务器

标准传输(本地MCP客户端)

# Run directly
python -m src.server

# Or use the installed command
open-meteo-mcp

SSE传输(远程HTTP访问)

# Run with SSE for remote access
python -m src.server --transport sse --port 8000

# With custom host
python -m src.server --transport sse --host 0.0.0.0 --port 8080

MCP客户端配置

光标IDE

增添 .cursor/settings.json:

{
  "mcpServers": {
    "open-meteo": {
      "command": "python",
      "args": ["-m", "src.server"],
      "cwd": "/path/to/open-meteo-mcp",
      "description": "Weather data from Open-Meteo API"
    }
  }
}

克劳德桌面

增添 claude_desktop_config.json:

{
  "mcpServers": {
    "open-meteo": {
      "command": "python",
      "args": ["-m", "src.server"],
      "cwd": "/path/to/open-meteo-mcp"
    }
  }
}

带MCP客户端的Docker

{
  "mcpServers": {
    "open-meteo": {
      "command": "docker",
      "args": ["run", "-i", "--rm", "-e", "OPEN_METEO_API_KEY=your_key", "open-meteo-mcp"],
      "description": "Weather data via Docker"
    }
  }
}

示例查询

连接后,您可以询问AI助手:

What's the current weather in London?

Show me the 7-day forecast for Tokyo with temperature and precipitation.

What was the weather like in Paris during January 2024?

Compare the ECMWF and GFS models for New York this week.

What's the air quality index in Beijing right now? Is it safe for outdoor exercise?

Find coordinates for Barcelona, Spain and get the marine forecast for sailing.

What's the elevation of Denver, Colorado?

List all available weather variables for solar energy applications.

I have allergies - what's the pollen forecast for Berlin this week?

Plan my outdoor wedding in Amsterdam on Saturday - give me hour-by-hour weather from 2 PM to 10 PM.

📚 可用工具

预测工具

工具 说明 参数
get_current_weather 当前天气状况 lat、lon、变量、单位
get_hourly_forecast 每小时预测(最多16天) lat、lon、变量、forecast_days
get_daily_forecast 每日预测摘要 lat、lon、变量、forecast_days
get_15min_forecast 15分钟间隔预测(EU/NA) lat、lon、变量、forecast_days
get_complete_forecast 当前+每小时+每日合并 lat、lon、forecast_days

历史工具

工具 描述 日期范围
get_historical_hourly 历史小时数据 1940年至今
get_historical_daily 历史日总量 1940年至今
get_historical_temperature_extremes 最高/最低温度分析 1940年至今
get_historical_precipitation_analysis 降水统计 1940年至今
get_historical_wind_analysis 风速/风向分析 1940年至今

空气质量工具

工具 描述 覆盖范围
get_current_air_quality PM2.5、PM10、气体 全球
get_hourly_air_quality 每小时空气质量预报 全球
get_air_quality_index AQI与健康建议 全球
get_pollen_forecast 花粉预测(桤木、桦木、草等) 欧洲
get_uv_index_forecast 具有安全指导的紫外线指数 全球

地理编码工具

工具 描述 用例
search_location 按名称搜索位置 城市查找
get_location_by_id 按ID获取位置详细信息 缓存查找
resolve_coordinates 将地名转换为坐标 自然语言
get_nearby_cities 查找附近城市 区域查询

集成和模型专用工具

工具 描述 型号
get_ensemble_forecast 多模型集成 全部
compare_weather_models 比较模型预测 ECMWF、GFS、ICON
get_ecmwf_forecast ECMWF IFS预测 ECMWF
get_gfs_forecast 美国国家海洋和大气管理局全球飞行服务预测
get_icon_forecast DWD图标预测 DWD
get_metno_forecast 挪威气象局预报 挪威气象局
get_meteo_france_forecast 天气预报-法国 天气预报-法国

船用和专用工具

工具 描述 变量
get_marine_forecast 海洋天气和波浪 波浪高度、周期、方向
get_elevation 高程数据 高程
get_climate_data 长期气候正常值 温度、降水
get_weather_code_explanation WMO天气代码 0-99代码
list_weather_variables 所有可用变量 200+
list_weather_models 所有可用型号 30+
get_weather_summary 快速天气摘要 全部

📖 可用资源

通过MCP客户端中的URI访问参考数据:

可变资源

URI 描述
weather://variables/all 所有200+天气变量
weather://variables/temperature 温度相关变量
weather://variables/wind 风速、风向、阵风
weather://variables/precipitation 雨、雪、降水
weather://variables/clouds 云层覆盖和类型
weather://variables/pressure 大气压力
weather://variables/humidity 湿度和湿度
weather://variables/solar 太阳辐射和紫外线
weather://variables/soil 土壤温度和湿度
weather://variables/air_quality 空气质量和污染物
weather://variables/marine 海洋和波浪条件
weather://variables/weather_codes WMO天气代码(0-99)
weather://variables/usage-guide 最佳做法和实例

模型资源

URI 描述
weather://models/all 所有30+天气模型
weather://models/ecmwf ECMWF(欧洲中心)模型
weather://models/noaa 美国国家海洋和大气管理局模型
weather://models/dwd DWD(德国)型号
weather://models/meteo_france 天气-法国模型
weather://models/ukmo 英国气象局模型
weather://models/met_norway Met挪威模特
weather://models/eccc 加拿大环境模型
weather://models/jma JMA(日本)型号
weather://models/ensemble 集合预测模型
weather://models/comparison 车型比较指南
weather://models/usage-guide 选型指南

🧪 测试

运行测试

# Install test dependencies
pip install pytest pytest-asyncio

# Run all tests
pytest tests/ -v

# Run with coverage
pytest tests/ --cov=src --cov-report=html

# Run specific test file
pytest tests/test_client.py -v

# Run tests in Docker
docker compose --profile test up open-meteo-test

测试结果

============================= test session starts =============================
collected 118 items

tests/test_client.py ...................ss...ss........                 [ 28%]
tests/test_prompts/test_prompts.py .............                         [ 39%]
tests/test_resources/test_resources.py ...................               [ 55%]
tests/test_server.py .......................                             [ 75%]
tests/test_tools/test_tools.py ............ssss...ssss......             [100%]

====================== 106 passed, 12 skipped in 39.50s ======================

代码质量

# Format code
black src/ tests/

# Lint code
ruff check src/ tests/

# Type checking
mypy src/

# All quality checks
black --check src/ tests/ && ruff check src/ tests/ && mypy src/

🏗️ 项目结构

open-meteo-mcp/
├── src/
│   ├── __init__.py              # Package metadata
│   ├── server.py                # Main MCP server entry point
│   ├── client.py                # Open-Meteo API client (async)
│   ├── tools/
│   │   ├── __init__.py
│   │   ├── forecast.py          # 5 forecast tools
│   │   ├── historical.py        # 5 historical tools
│   │   ├── air_quality.py       # 5 air quality tools
│   │   ├── geocoding.py         # 5 geocoding tools
│   │   ├── ensemble.py          # 7 ensemble/model tools
│   │   ├── marine.py            # 3 marine tools
│   │   └── specialized.py       # 3 utility tools
│   ├── resources/
│   │   ├── __init__.py
│   │   ├── variables.py         # 13 variable resources
│   │   └── models.py            # 12 model resources
│   └── prompts/
│       ├── __init__.py
│       └── weather_assistant.py # 4 prompts
├── tests/
│   ├── __init__.py
│   ├── conftest.py              # Pytest fixtures
│   ├── test_client.py           # API client tests (38 tests)
│   ├── test_server.py           # Server tests (23 tests)
│   ├── test_tools/
│   │   ├── __init__.py
│   │   └── test_tools.py        # Tool tests (28 tests)
│   ├── test_resources/
│   │   ├── __init__.py
│   │   └── test_resources.py    # Resource tests (19 tests)
│   └── test_prompts/
│       ├── __init__.py
│       └── test_prompts.py      # Prompt tests (13 tests)
├── .github/
│   └── workflows/
│       └── ci.yml               # GitHub Actions CI
├── docker-compose.yml           # Docker orchestration
├── Dockerfile                   # Multi-stage build
├── DOCKER.md                    # Docker documentation
├── pyproject.toml               # Project configuration
├── requirements.txt             # Python dependencies
├── README.md                    # This file
├── QUICKSTART.md                # 5-minute setup guide
└── TEST_PROMPTS.md              # Comprehensive test prompts

📊 API费率限制和定价

Open Meteo是 免费用于非商业用途:

使用层 API密钥 费率限制 成本
非商业性 不需要 合理使用 免费
商业(<10k/天) 不需要 合理使用 免费
商业(>10k/天) 必填 按约定 已支付

最佳实践

  • ✅ 实现速率限制(默认:延迟0.1秒)
  • ✅ 尽可能缓存响应
  • ✅ 使用特定变量(不要请求不必要的数据)
  • ✅ 属性Open Meteo:“Open Meteo.com提供的天气数据”

🤝 贡献

欢迎投稿!请按照以下步骤操作:

  1. 分叉 存储库
  2. 创建 特征分支(git checkout -b feature/amazing-feature)
  3. 承诺 您的更改(git commit -m 'Add amazing feature')
  4. 测试 您的更改(pytest tests/ -v)
  5. 棉绒 你的代码(black . && ruff check .)
  6. 推 到分行(git push origin feature/amazing-feature)
  7. 打开 拉取请求

开发设置

# Clone your fork
git clone https://github.com/Achrefjr1997/open-meteo-mcp.git
cd open-meteo-mcp

# Create virtual environment
python -m venv venv
source venv/bin/activate  # or venv\Scripts\activate on Windows

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests to verify setup
pytest tests/ -v

📄 许可证

归因要求: 在出版物或产品中使用天气数据时,请注明Open Meteo:

Weather data provided by Open-Meteo.com

🆘 支持

|资源|链接| |----------|------| | Open-Meteo API文档 | https://open-meteo.com/en/docs | | 打开Meteo GitHub | https://github.com/open-meteo/open-meteo | | MCP规范 | https://modelcontextprotocol.io/ |

建于❤️ 面向天气爱好者和人工智能开发人员