j

jalaj-pandey

@jalaj-pandey/Weather-MCP-Tool
0 Stars 339 次浏览 jalaj-pandey 更新于 2026-08-23
该服务暂未提供标准配置,请参考 README 手动接入

服务介绍

天气 MCP 工具(印度专用)

一个使用 OpenWeatherMap API 的 MCP(Model Context Protocol)服务器,提供以下功能:

  • 实时天气状况
  • 5天天气预报
  • 空气质量数据
  • 位置搜索

🚀 设置

  1. 需要 Python 3.10+

  2. 安装依赖项:
    bash
    pip install -r requirements.txt

  3. OpenWeatherMap 获取 API 密钥。

  4. 在根目录下创建一个 .env 文件:

    OPENWEATHER_API_KEY=your_api_key_here


🛠 可用工具

get_current_weather(location: str)

返回给定位置的当前天气。

get_weather_forecast(location: str, days: int = 5)

返回指定位置的天气预报(最多5天)。

get_air_quality(location: str)

返回空气质量指标和 AQI 等级。

search_location(query: str)

根据查询返回最多5个匹配的位置。


🧪 示例输出(印度)

当前天气(德里)

json
{
"location": {
"name": "Delhi",
"country": "IN",
"lat": 28.6139,
"lon": 77.2090
},
"temperature": {
"current": 32.4,
"feels_like": 35.1,
"min": 30.0,
"max": 36.2
},
"weather_condition": {
"main": "Haze",
"description": "smoky haze",
"icon": "50d"
},
"wind": {
"speed": 4.1,
"deg": 135
},
"clouds": 20,
"humidity": 58,
"pressure": 1005,
"visibility": 5000,
"sunrise": "2025-03-16T06:20:00",
"sunset": "2025-03-16T18:40:00",
"timestamp": "2025-03-16T14:30:00"
}

天气预报(孟买)

json
{
"location": {
"name": "Mumbai",
"country": "IN",
"lat": 19.0760,
"lon": 72.8777
},
"forecast": [
{
"datetime": "2025-03-16T12:00:00",
"temperature": {
"temp": 33.2,
"feels_like": 37.8,
"min": 31.5,
"max": 34.0
},
"weather_condition": {
"main": "Clouds",
"description": "scattered clouds",
"icon": "03d"
},
"wind": {
"speed": 3.9,
"deg": 200
},
"clouds": 40,
"humidity": 70,
"pressure": 1008,
"visibility": 10000,
"pop": 0.1
}
],
"days": 5
}

空气质量(班加罗尔)

json
{
"location": {
"name": "Bengaluru",
"country": "IN",
"lat": 12.9716,
"lon": 77.5946
},
"air_quality_index": 2,
"air_quality_level": "Fair",
"components": {
"co": 102.4,
"no": 0.0,
"no2": 12.6,
"o3": 30.5,
"so2": 3.8,
"pm2_5": 45.1,
"pm10": 60.2,
"nh3": 1.5
},
"timestamp": "2025-03-16T14:30:00"
}

位置搜索

json
{
"results": [
{
"name": "Kolkata",
"state": "West Bengal",
"country": "IN",
"lat": 22.5726,
"lon": 88.3639
},
{
"name": "Kolkata",
"state": "",
"country": "IN",
"lat": 22.5675,
"lon": 88.3700
}
]
}


🧰 错误处理

所有工具都会返回清晰的错误信息:
json
{ "error": "Location XYZ not found" }


📌 注意事项

  • 确保 .env 文件配置正确。
  • API 密钥可能需要一段时间才能激活。
  • OpenWeatherMap 免费层级:每分钟60次 API 调用。

🧑‍💻 运行服务器

bash
mcp dev main.py

运行后,您可以使用此服务器与 Claude Desktop 或其他自动化工具等兼容 MCP 的客户端配合使用。


相关 MCP 服务