天气数据服务

一个基于Model Context Protocol (MCP)的天气数据服务,提供全球任意城市的当前和历史天气数据。

  • by 167AliRaza
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 167AliRaza/MCP-Demo

使用说明

天气预报MCP服务器

模型上下文协议(MCP)服务器,使用Open-Meteo API为全球任何城市提供当前和历史天气数据。

特性

  • 🌤️ 具有13+个参数的当前天气数据
  • 📊 历史天气数据(历史年份)
  • 🌍 覆盖全球任何城市
  • 🔄 带SSE异步端点的MCP http
  • ⚡ 快速可靠(由Open Meteo提供支持)

快速开始

使用公共服务器

服务器URL: https://weather-mcp.fastmcp.app/mcp

与Claude Desktop集成

添加到您的 claude_desktop_config.json:

{
  "mcpServers": {
    "weather": {
      "url": "https://weather-mcp.fastmcp.app/mcp"
    }
  }
}

与其他MCP客户端集成

from mcp import ClientSession

async with ClientSession("https://weather-mcp.fastmcp.app/mcp") as session:
    result = await session.call_tool(
        "get_weather_data",
        city_name="London",
        query_type="current"
    )
    print(result)

工具文档

get_weather_data

获取任何城市的天气数据。

参数:

  • city_name (string,必填):城市名称
  • query_type (字符串,可选):“当前”或“历史”(默认值:“当前的”)
  • start_date (字符串,可选):历史数据的开始日期(YYYY-MM-DD)
  • end_date (字符串,可选):历史数据的结束日期(YYYY-MM-DD)

退货: 包含天气数据的JSON字符串

示例响应(当前天气):

{
  "location": {
    "city": "London",
    "country": "United Kingdom",
    "latitude": 51.5074,
    "longitude": -0.1278
  },
  "current": {
    "temperature_2m": 15.2,
    "relative_humidity_2m": 72,
    "wind_speed_10m": 12.5,
    "weather_code": 2
  }
}

自我寄宿

先决条件

  • Python 3.8+
  • 点

安装

# Clone the repository
git clone https://github.com/yourusername/weather-mcp-server
cd weather-mcp-server

# Install dependencies
pip install -r requirements.txt

# Run the server
python main.py

服务器将在以下时间启动 http://localhost:8000

Docker部署

FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY main.py .

EXPOSE 8000
CMD ["python", "main.py"]

构建并运行:

docker build -t weather-mcp .
docker run -p 8000:8000 weather-mcp

天气参数

当前天气

  • 温度(°C)
  • 表观温度(°C)
  • 相对湿度(%)
  • 降水量(mm)
  • 雨雪(mm)
  • 天气代码
  • 云量(%)
  • 压力(hPa)
  • 风速、风向、阵风(km/h,°)

历史天气

  • 日最低/最高/平均温度
  • 表观温度
  • 日出/日落时间
  • 降水总量
  • 风力数据
  • 太阳辐射

天气代码

代码 描述
0 晴朗的天空
1-3 主要晴朗至阴天
45、48 雾
51-57 小雨
61-67 下雨
71-77 雪
80-82 阵雨
85-86 阵雪
95-99 雷暴

速率限制

  • Open-Meteo API:每天10000个请求(免费层)
  • 无需认证

贡献

欢迎投稿!请打开问题或PR。

许可证

麻省理工学院许可证-您可以在项目中自由使用!

鸣谢

支持