天气服务

一个简单的MCP服务,提供当前天气和5天预报,使用免费的OpenWeatherMap API。

  • by mschneider82
  • Go
  • 本地部署
  • 22 星标
  • 更新于
在 GitHub 查看 mschneider82/mcp-openweather

使用说明

MCP气象服务

一个简单的MCP服务,使用免费的OpenWeatherMap API提供当前天气和5天预报。

特性

  • 当前天气状况
  • 5天天气预报
  • 可配置单位(摄氏度/华氏度/开尔文)
  • 多语言支持
  • 简单的MCP集成

先决条件

  • 转到1.20+
  • OpenWeatherMap API密钥

安装

  1. 从获取OpenWeatherMap API密钥 https://openweathermap.org/api

  2. 克隆存储库:

    git clone https://github.com/mschneider82/mcp-openweather.git
    cd mcp-openweather
    
  3. 构建:

    go build -o mcp-weather
    

配置

设置所需的环境变量:

export OWM_API_KEY="your_api_key_here"

用法


 "mcpServers": {
     "mcp-openweather": {
         "command": "/home/YOURUSER/git/mcp-openweather/mcp-openweather",
         "env": {
             "OWM_API_KEY": "PUT_API_KEY_HERE"
         }
     }
 }

MCP参数

 {
     "tool": "weather",
     "params": {
         "city": "Berlin",          // Required
         "units": "c",             // Optional (c|f|k)
         "lang": "en"              // Optional (en|de|fr|...)
     }
 }

示例响应

 Current weather for München:
     Conditions:  Klarer Himmel 
     Now:         17.78 metric
     High:        18.66 metric
     Low:         17.36 metric
     Pressure:    1017
     Humidity:    40
     FeelsLike:   16.66
     Wind Speed:  1.79
     Wind Degree:    61
     Sunrise:     1747107429 Unixtime
     Sunset:      1747161784 Unixtime
 Weather Forecast for München:
 Date & Time: 2025-05-13 12:00:00 +0000 UTC
 Conditions:  Clear Klarer Himmel
 Temp:        17.78 
 High:        18.93 
 Low:         17.78

 Date & Time: 2025-05-13 15:00:00 +0000 UTC
 Conditions:  Clear Klarer Himmel
 Temp:        18.33 
 High:        19.44 
 Low:         18.33

 Date & Time: 2025-05-13 18:00:00 +0000 UTC
 Conditions:  Clear Klarer Himmel
 Temp:        16.32 
 High:        16.32 
 Low:         15.59

 Date & Time: 2025-05-13 21:00:00 +0000 UTC
 Conditions:  Clear Klarer Himmel
 Temp:        9.18 
 High:        9.18 
 Low:         9.18
...

错误处理

常见错误场景:

Missing API key: FATAL: OWM_API_KEY environment variable not set

Invalid city: current weather error: failed to fetch current weather: city not found

Network issues: failed to fetch forecast: context deadline exceeded

发展

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

Fork the repository

Create a feature branch

Commit changes

Push to the branch

Create a Pull Request

许可证

MIT许可证-详见许可证