mcp-weather-server

xiaowhang/mcp-weather-server

3.1

If you are the rightful owner of mcp-weather-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

A simple Model Context Protocol (MCP) based weather server providing real-time weather information.

Tools
1
Resources
0
Prompts
0

MCP Weather Server

一个简单的基于 Model Context Protocol (MCP) 的天气服务器,提供实时天气信息查询功能。

功能特性

  • 🌤️ 获取全球任意城市的实时天气信息
  • 🗺️ 支持地理编码,通过城市名自动获取经纬度
  • 🌍 支持国家代码过滤,提高查询精度
  • 📡 基于 MCP 协议,可与支持 MCP 的 AI 客户端集成
  • 🔄 使用 Open-Meteo API 提供可靠的天气数据

安装

确保你已安装 Node.js (推荐 18+ 版本) 和 pnpm。

# 克隆项目
git clone https://github.com/xiaowhang/mcp-weather-server.git
cd mcp-weather-server

# 安装依赖
pnpm install

使用方法

开发和测试

1. 开发模式(推荐用于测试)
pnpm dev

这将启动 MCP Inspector,你可以在浏览器中测试工具功能。

2. 直接运行
npx tsx src/main.ts

与 Claude Desktop 集成

要在 Claude Desktop 中使用这个天气服务器,需要配置 MCP 设置:

1. 添加服务器配置

在配置文件中添加以下内容(请将路径替换为你的实际项目路径):

{
  "mcpServers": {
    "weather-server": {
      "command": "npx",
      "args": ["-y", "tsx", "/path/to/your/mcp-weather-server/src/main.ts"]
    }
  }
}

示例配置:

{
  "mcpServers": {
    "weather-server": {
      "command": "npx",
      "args": ["-y", "tsx", "/home/xh/Code/mcp-weather-server/src/main.ts"]
    }
  }
}
2. 重启 Claude Desktop

保存配置文件后,重启 Claude Desktop 应用程序。

3. 验证集成

重启后,你可以在 Claude 中询问天气信息,例如:

  • "北京现在的天气怎么样?"
  • "What's the weather like in New York?"
  • "告诉我上海的当前天气状况"

Claude 将自动调用天气服务器获取实时数据。

使用示例

一旦配置完成,你可以向 Claude 提出各种天气相关的问题:

用户: 北京现在的天气如何?

Claude 将调用 get_current_weather 工具,返回包含以下信息的详细天气报告:
- 当前温度:15°C
- 体感温度:13°C
- 相对湿度:65%
- 降水量:0mm
- 云量:40%
- 气压:1013 hPa
- 天气状况:多云

可用工具

get_current_weather

获取指定城市的当前天气信息。

参数:

  • city (string, 必需): 要查询的城市名,例如 "Beijing"、"New York"
  • countryCode (string, 可选): ISO-3166-1 alpha2 格式的国家代码,例如 "CN"、"US"

示例:

{
  "city": "Beijing",
  "countryCode": "CN"
}

返回数据包含:

  • 当前温度和体感温度
  • 相对湿度
  • 降水量、雨量、雪量
  • 云量覆盖
  • 气压信息
  • 天气代码
  • 是否为白天

API 数据源

本项目使用以下免费 API 服务:

项目结构

src/
├── main.ts      # 应用入口点
├── server.ts    # MCP 服务器配置
├── apis.ts      # API 接口和类型定义
└── tools.ts     # MCP 工具注册

与 AI 客户端集成

这个服务器可以与任何支持 MCP 的 AI 客户端集成,例如:

  • Claude Desktop
  • Cursor
  • Visual Studio Code
  • 其他支持 MCP 的 AI 应用

集成后,AI 助手将能够:

  • 查询任意城市的实时天气
  • 提供详细的天气分析
  • 根据天气条件给出建议