MCP 配置参考
天气 MCP (Model Context Protocol) 使得 Claude、Cursor 等 AI 助手可以直接调用天气数据能力。标准 openAPI Key 与 REST 接口共用配额与鉴权,无需单独申请;高阶能力需 JV Key。完整产品介绍见 天气 MCP 产品文档。
第一步:安装 MCP 服务
pip install weatherwork-consumer-mcp
需要 Python 3.11+
第二步:配置 Claude Desktop(标准版)
编辑 ~/Library/Application Support/Claude/claude_desktop_config.json
{
"mcpServers": {
"weatherwork": {
"command": "weatherwork-consumer-mcp",
"env": {
"WEATHERCN_OPENAPI_KEY": "your_openapi_key"
}
}
}
}
将 your_openapi_key 替换为应用管理页面的 API Key。
配置 Cursor(标准版)
在项目根目录 .cursor/mcp.json 中添加:
{
"mcpServers": {
"weatherwork": {
"command": "weatherwork-consumer-mcp",
"envFile": "/path/to/.env.mcp.local"
}
}
}
.env.mcp.local 内容:WEATHERCN_OPENAPI_KEY=your_openapi_key
高阶版配置(JV Key)需商务申请
{
"mcpServers": {
"weatherwork": {
"command": "weatherwork-consumer-mcp",
"env": {
"WEATHERCN_API_KEY": "your_jv_api_key",
"WEATHERCN_API_SECRET": "your_jv_api_secret"
}
}
}
}
MCP Tool 清单(共 17 个)
核心 Tool(标准版,8 个)
| Tool 名称 | 功能说明 |
|---|---|
| resolve_location | 地名解析与消歧义,支持城市名 / 坐标 |
| get_current_weather | 实况天气(温度、湿度、风力、体感等) |
| get_weather_forecast | 逐日预报,标准 1/5/10 天 |
| get_hourly_forecast | 逐小时预报,标准 1/12/24/72 小时 |
| get_weather_alerts | 气象预警,透传中央气象台官方预警 |
| get_activity_advice | 生活指数与活动建议(穿衣、运动、洗车等) |
| get_air_quality | 空气质量(AQI、PM2.5 实况) |
| get_minute_precipitation | 分钟级降水预报(未来约 2 小时) |
高阶专项 Tool(JV Key,9 个)
| Tool 名称 | 功能说明 |
|---|---|
| get_typhoon_detail | 按台风编号查路径详情 |
| get_typhoon_season_list | 按年度列出命名台风 |
| get_typhoon_recent | 最近若干条台风摘要 |
| get_astronomy_daily | 日出日落、月相等天文逐日数据 |
| get_astronomy_current | 天文实况 |
| get_astronomy_hourly | 天文逐小时 |
| get_tidal_5day_forecast | 5 日潮汐预报(沿海) |
| get_tidal_hourly_forecast | 逐小时潮汐 |
| get_tidal_station | 潮汐站点查询 |
常见 MCP 错误码
| 错误码 | 含义 | 处理建议 |
|---|---|---|
| INVALID_API_KEY | Key 无效或未传入 | 检查环境变量名称和 Key 值是否正确 |
| INVALID_LOCATION | 地名无法识别 | 提供更完整的地名,如"北京市朝阳区" |
| RATE_LIMIT | 超出 QPS 或 PV 配额 | 降低调用频率或联系商务升级配额 |
| UPSTREAM_TIMEOUT | 上游数据源超时 | 稍后重试,一般为短暂性问题 |
| SERVER_ERROR | 服务端内部错误 | 联系 support@weathercn.com 反馈 |
