weather-china-mcp
This server provides real-time weather and 5-day forecast for Chinese cities via weather.com.cn, requiring no API key.
README
中国天气网 MCP 服务
基于中国天气网(weather.com.cn)的 MCP 服务器,提供实时天气和 5 天预报查询。
直接调用中国天气网官方接口,无需 API Key,免费使用。
安装
cd weather-china-mcp
npm install
配置
配置位置说明(项目级 vs 全局)
MCP 服务可以在两个位置配置,区别如下:
| 配置级别 | 配置文件位置 | 作用范围 | 适用客户端 |
|---|---|---|---|
| 项目级 | 项目根目录下的 .mcp.json / opencode.jsonc |
仅当前项目 | Claude Code、OpenCode |
| 全局级 | 用户主目录下的配置文件 | 所有项目 | Claude Code、Claude Desktop、OpenCode、Cursor 等 |
方式一:项目级配置(仅当前项目生效)
适用场景:希望这个 MCP 服务只在某个特定项目中可用。
在项目根目录下创建 .mcp.json 文件:
<项目根目录>/
├── .mcp.json ← 在这里创建
├── src/
├── package.json
└── ...
方式二:全局配置(推荐,所有项目生效)
适用场景:希望在任何项目、任何目录都能使用这个 MCP 服务。
2.1 Claude Code 全局配置
配置文件路径:
| 系统 | 完整路径 |
|---|---|
| Windows | C:\Users\<你的用户名>\.claude.json |
| macOS | /Users/<你的用户名>/.claude.json |
| Linux | /home/<你的用户名>/.claude.json |
简写:
~/.claude.json
在 ~/.claude.json 中添加 mcpServers 字段(详见下方安装方式)。
2.2 Claude Desktop 配置
| 系统 | 完整路径 |
|---|---|
| Windows | %APPDATA%\Claude\claude_desktop_config.json |
| macOS | ~/Library/Application Support/Claude/claude_desktop_config.json |
2.3 OpenCode 全局配置
配置文件路径:
| 系统 | 完整路径 |
|---|---|
| Windows | C:\Users\<你的用户名>\.config\opencode\opencode.jsonc |
| macOS | ~/.config/opencode/opencode.jsonc |
| Linux | ~/.config/opencode/opencode.jsonc |
简写:
~/.config/opencode/opencode.jsonc
⚠️ 注意:OpenCode 的配置格式与 Claude Code 不同,详见下方 OpenCode 配置格式。
2.4 Cursor / Windsurf / Cline 等 IDE
| IDE | 配置方式 |
|---|---|
| Cursor | 设置面板 → MCP,或项目 .cursor/mcp.json |
| Windsurf | 设置面板 → MCP |
| Cline | 扩展设置 → MCP 配置 |
安装方式与配置内容
以下安装方式对应不同的
command+args,根据你的选择填入上述配置文件。
安装方式 A:GitHub 直装(npx,推荐)
无需克隆,直接通过 npx 从 GitHub 运行:
{
"mcpServers": {
"weather-china": {
"type": "stdio",
"command": "npx",
"args": ["-y", "github:zaixiamaomaoyu/weather-china-mcp"]
}
}
}
安装方式 B:本地克隆(Git Clone)
如果你是从 GitHub 克隆到本地运行的,需要先安装依赖,然后使用本地绝对路径:
git clone https://github.com/zaixiamaomaoyu/weather-china-mcp.git
cd weather-china-mcp
npm install
配置内容(将 <你的项目路径> 替换为实际路径):
{
"mcpServers": {
"weather-china": {
"type": "stdio",
"command": "node",
"args": ["<你的项目路径>/weather-china-mcp/src/index.js"]
}
}
}
示例:如果克隆到
D:\projects\weather-china-mcp,则路径为D:/projects/weather-china-mcp/src/index.js
安装方式 C:npm 全局安装
npm install -g weather-china-mcp
配置内容:
{
"mcpServers": {
"weather-china": {
"type": "stdio",
"command": "weather-china-mcp",
"args": []
}
}
}
安装方式 D:npm 包 + npx(不全局安装)
无需全局安装,直接用 npx 运行:
{
"mcpServers": {
"weather-china": {
"type": "stdio",
"command": "npx",
"args": ["-y", "weather-china-mcp"]
}
}
}
各安装方式对比
| 安装方式 | 是否需要克隆 | 是否需要全局安装 | 配置中的 command | 推荐度 |
|---|---|---|---|---|
| A. GitHub 直装(npx) | ❌ | ❌ | npx -y github:... |
⭐⭐⭐ |
| B. 本地克隆 | ✅ | ❌ | node <绝对路径> |
⭐⭐ |
| C. npm 全局安装 | ❌ | ✅ | weather-china-mcp |
⭐⭐ |
| D. npm + npx | ❌ | ❌ | npx -y weather-china-mcp |
⭐⭐⭐ |
OpenCode 配置格式
⚠️ OpenCode 的配置格式与 Claude Code 不同,主要差异如下:
| 差异项 | Claude Code | OpenCode |
|---|---|---|
| 顶层键 | mcpServers |
mcp |
| 类型关键字 | "stdio" |
"local" |
| 命令格式 | command: "npx" + args: ["-y", "..."] |
command: ["npx", "-y", "..."](合并为一个数组) |
| 环境变量 | env: { "KEY": "val" } |
environment: { "KEY": "val" } |
| 支持注释 | ❌ | ✅(.jsonc 格式) |
OpenCode 配置示例
在 opencode.jsonc(项目级或全局)中添加:
// opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"weather-china": {
"type": "local",
"command": ["npx", "-y", "github:zaixiamaomaoyu/weather-china-mcp"],
"enabled": true
}
}
}
OpenCode 各安装方式对应的 command
| 安装方式 | OpenCode 的 command 数组 |
|---|---|
| A. GitHub 直装(推荐) | ["npx", "-y", "github:zaixiamaomaoyu/weather-china-mcp"] |
| B. 本地克隆 | ["node", "<绝对路径>/weather-china-mcp/src/index.js"] |
| C. npm 全局安装 | ["weather-china-mcp"] |
| D. npm + npx | ["npx", "-y", "weather-china-mcp"] |
OpenCode MCP 管理命令
opencode mcp list # 列出所有 MCP 服务器和认证状态
opencode mcp auth <name> # 与需要 OAuth 的 MCP 服务器进行认证
opencode mcp debug <name> # 调试连接/OAuth 问题
opencode mcp logout <name> # 移除已存储的凭证
配置验证
配置完成后,重启你的客户端,然后验证:
Claude Code:运行 /mcp,如果看到 weather-china 服务已连接并列出 weather_current、weather_forecast、weather_summary 三个工具,说明配置成功。
OpenCode:运行 opencode mcp list,如果看到 weather-china 状态为已连接,说明配置成功。
其他客户端:在对话中尝试调用天气查询,如"查询北京天气"。
可用工具
| 工具名称 | 描述 | 参数 |
|---|---|---|
weather_current |
实时天气(温度、湿度、PM2.5、空气质量、气压) | city(必填) |
weather_forecast |
5 天天气预报(含天气状况、高低温、风向风力) | city(必填) |
weather_summary |
天气摘要(实时 + 今天 + 明天) | city(必填) |
支持的城市
支持任意中文城市名查询,查找逻辑如下:
- 本地映射表(
city-codes-complete.json,含 2732 个城市/区县)- 精确匹配(如
广州) - 自动去后缀(如
广州市→广州) - 模糊匹配(如输入部分城市名)
- 精确匹配(如
- 在线搜索 fallback(中国天气网内部搜索接口)
- 本地表找不到时,自动按城市名在线搜索代码
- 搜索到后自动缓存到本地,下次无需再请求网络
- 支持镇级地名(自动映射到上级市级数据)
数据源
| 项目 | 说明 |
|---|---|
| 数据来源 | 中国天气网 weather.com.cn |
| 天气接口 | http://d1.weather.com.cn/weather_index/{城市代码}.html |
| 搜索接口 | http://toy1.weather.com.cn/search?cityname=城市名 |
| 认证方式 | 无需 API Key |
注意事项
- 预报天数:
weather_forecast返回 5 天预报,这是中国天气网官方接口fc数组能提供的最大天数,无法获取 7 天或 15 天数据。
返回数据示例
weather_current
{
"city": "广州",
"temperature_c": "28.8",
"weather": "多云",
"wind": "西南风 1级",
"humidity_pct": "84%",
"pressure_hpa": "998",
"aqi": "36",
"pm25": "36",
"updateTime": "18:30",
"notice": "多云转晴,南风转微风 3-4级转<3级"
}
weather_forecast
{
"city": "广州",
"updateTime": "18:30",
"days": 5,
"forecast": [
{
"date": "7/22",
"week": "今天",
"weather_day": "多云",
"weather_night": "晴",
"temp_high": "33℃",
"temp_low": "25℃",
"wind_day": "南风 3-4级",
"wind_night": "无持续风向 <3级"
}
]
}
weather_summary
{
"city": "广州",
"updateTime": "18:30",
"current": {
"temperature_c": "28.8",
"humidity_pct": "84%",
"weather": "多云",
"wind": "西南风 1级",
"aqi": "36",
"pm25": "36"
},
"today": {
"date": "7/22",
"week": "今天",
"weather_day": "多云",
"weather_night": "晴",
"temp_high": "33℃",
"temp_low": "25℃",
"wind": "南风 3-4级"
},
"tomorrow": {
"date": "7/23",
"week": "星期四",
"weather_day": "晴",
"weather_night": "晴",
"temp_high": "34℃",
"temp_low": "26℃",
"wind": "无持续风向 <3级"
}
}
依赖
- @modelcontextprotocol/sdk — MCP 协议 SDK
许可证
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。