天气数据服务

一个基于WeatherAPI.com的MCP服务器,提供实时天气、天气预报、空气质量等天气数据工具。

  • by bsparks
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 bsparks/mcp-weatherapi

使用说明

WeatherAPI MCP服务器

MCP服务器使用 WeatherAPI.com 服务。

特性

此MCP服务器提供以下工具:

  • get_current天气:获取任何位置的当前天气状况
  • 获取预测:获取每小时的天气预报(1-10天)
  • 搜索位置:按名称搜索位置
  • 天文学:获取日出、日落、月相和其他天文数据
  • 获得空气质量:获取空气质量指数和污染物水平

设置

  1. 从获取免费的API密钥 WeatherAPI.com

  2. 将API键设置为环境变量:

    # Windows PowerShell
    $env:WEATHERAPI_KEY = "your_api_key_here"
    
    # Or add to your profile for persistence
    # Edit $PROFILE and add:
    # $env:WEATHERAPI_KEY = "your_api_key_here"
    
  3. 使用uvx安装:

    uvx mcp-weatherapi
    

与MCP客户端一起使用

将此添加到MCP配置中:

{
  "mcpServers": {
    "weatherapi": {
      "command": "uvx",
      "args": [
        "--from", "git+https://github.com/bsparks/mcp-weatherapi.git",
        "mcp-weatherapi"
      ],
      "env": {
        "WEATHERAPI_KEY": "your_api_key_here"
      }
    }
  }
}

发展

  1. 克隆存储库

  2. 安装依赖项:

    pip install -e .
    
  3. 设置API密钥:

    $env:WEATHERAPI_KEY = "your_api_key_here"
    
  4. 运行服务器:

    python weather_server.py
    

可用工具

get_current天气(位置:str)

获取当前的天气状况,包括温度、风、湿度、空气质量等。

示例: get_current_weather("London")

get_forecast(位置:str,天数:int=3)

获取1-10天的天气预报,包括每日摘要和每小时数据。

示例: get_forecast("New York", 5)

search_location(查询:str)

按名称搜索位置(至少3个字符)。

示例: search_location("Paris")

get_astronomy(位置:str,日期:可选[str]=无)

获取天文信息,包括日出、日落、月出、月落和月相。

示例: get_astronomy("Tokyo", "2025-11-07")

获取空气质量(位置:str)

获取空气质量指数和污染物水平。

示例: get_air_quality("Beijing")

API文档

有关WeatherAPI.com服务的更多信息,请访问:https://www.weatherapi.com/docs/

许可证

麻省理工学院