Skip to main content
Glama
ctermiii

Weather MCP Server

by ctermiii
README.md
# Weather MCP Server

基于 Open-Meteo API 的 MCP (Model Context Protocol) 天气服务器,为 LLM 大模型提供实时天气查询功能。

## 功能特性

- 支持中英文城市名称查询
- 自动地理编码(城市名→坐标)
- 获取7天天气预报
- 详细的天气信息包括:
  - **温度**: 最高/最低温度、体感温度
  - **风力**: 风速、阵风、风向
  - **舒适度**: 基于温度和湿度的舒适度评估
  - **天气状况**: 晴、雨、雪等详细描述
  - **降水信息**: 降水量、降雨量、降雪量
  - **其他**: 日出日落时间、湿度等

## 安装

```bash
npm install
```

## 使用方法

### 1. 配置 MCP 客户端

在 Claude Desktop 或其他 MCP 客户端的配置文件中添加:

**MacOS**: `~/Library/Application Support/Claude/claude_desktop_config.json`
**Windows**: `%APPDATA%/Claude/claude_desktop_config.json`

```json
{
  "mcpServers": {
    "weather": {
      "command": "node",
      "args": ["/Users/wanli/.config/mcp/weather-mcp-metro/index.js"]
    }
  }
}
```

### 2. 启动服务器

```bash
npm start
```

### 3. 在 LLM 中使用

服务器提供了一个工具 `get_weather`,可以通过以下方式调用:

```
请帮我查询北京的天气
```

或

```
What's the weather like in Shanghai?
```

## API 说明

### get_weather

获取指定城市的天气预报信息。

**参数:**
- `city` (string, 必需): 城市名称,支持中英文

**返回示例:**

```json
{
  "城市信息": {
    "名称": "Beijing",
    "国家": "China",
    "坐标": "39.9075, 116.39723",
    "时区": "Asia/Shanghai"
  },
  "当前天气": {
    "时间": "2025-10-17T10:00",
    "温度": "18°C",
    "体感温度": "16°C",
    "湿度": "65%",
    "天气状况": "部分多云",
    "风速": "12 km/h",
    "风向": "东北",
    "舒适度": "舒适"
  },
  "七天预报": [
    {
      "日期": "2025-10-17",
      "最高温度": "22°C",
      "最低温度": "14°C",
      "天气状况": "部分多云",
      "降水量": "0mm",
      "降雨量": "0mm",
      "降雪量": "0cm",
      "最大风速": "15 km/h",
      "最大阵风": "25 km/h",
      "主导风向": "东",
      "日出": "2025-10-17T06:30",
      "日落": "2025-10-17T18:15",
      "舒适度": "舒适"
    }
    // ... 其余6天
  ]
}
```

## 技术细节

### 数据来源

- **地理编码 API**: `https://geocoding-api.open-meteo.com/v1/search`
- **天气数据 API**: `https://api.open-meteo.com/v1/forecast`

### 天气参数

- `temperature_2m_max/min`: 最高/最低温度
- `weathercode`: 天气代码(自动转换为中文描述)
- `precipitation_sum`: 总降水量
- `rain_sum`: 降雨量
- `snowfall_sum`: 降雪量
- `windspeed_10m_max`: 最大风速
- `windgusts_10m_max`: 最大阵风
- `winddirection_10m_dominant`: 主导风向
- `sunrise/sunset`: 日出日落时间
- `relative_humidity_2m`: 相对湿度
- `apparent_temperature`: 体感温度

### 舒适度评级

基于体感温度和湿度计算:
- 非常寒冷 (< 0°C)
- 寒冷 (0-10°C)
- 凉爽 (10-16°C)
- 舒适 (16-24°C)
- 温暖 (24-28°C)
- 炎热 (28-32°C)
- 酷热 (> 32°C)

同时考虑湿度影响(高湿度/干燥提示)

## 依赖项

- `@modelcontextprotocol/sdk`: MCP SDK

## 许可证

MIT

## 注意事项

- Open-Meteo API 是免费开源的,无需 API 密钥
- 数据更新频率取决于 Open-Meteo 服务
- 建议合理使用,避免过于频繁的请求

TDQS

B3.4/5.0

Scored across 1 tool

Disambiguation5/5

With only one tool, there is no possibility of ambiguity or overlap between tools. The tool's purpose is clearly defined as fetching weather forecasts for a specified city.

Naming Consistency5/5

The single tool name 'get_weather' follows a clear verb_noun pattern. Since there are no other tools to compare, consistency is inherently perfect.

Tool Count2/5

A single tool is too few for a weather server, as it lacks operations like searching locations, getting historical data, or setting preferences. This minimal set limits functionality and may cause agent failures in broader weather-related tasks.

Completeness2/5

The server is severely incomplete for a weather domain. It only provides forecast retrieval, missing essential operations such as current conditions, alerts, location search, or multi-city queries, which are standard in weather APIs.

Maintenance

ActivityInactive
ResponsivenessNo issues