天气服务
MCP 服务配置
复制以下 JSON 到 OPClaw 或其他 MCP 客户端的配置文件中即可使用
{
"mcpServers": {
"weather": {
"args": [
"/home/sandbox/.openclaw/workspace/weather-mcp/weather_mcp_server.py"
],
"command": "python3"
}
}
}
服务介绍
天气查询本地 MCP 服务
基于 MCP (Model Context Protocol) + Open-Meteo 免费 API 构建的本地天气服务。
无需注册、无需 API Key,支持中文城市名自动解析坐标。
功能
query_weather_by_city(city)— 一站式:输入城市名(如"北京""Hangzhou")直接返回天气get_weather(latitude, longitude)— 按经纬度查询实时天气 + 未来 3 天预报geocode_city(city)— 城市名 → 经纬度坐标查询
返回内容含:实时温度/体感、湿度、风速风向、气压、天气现象,以及每日最高/最低温、降水概率、日出日落。
安装
cd weather-mcp
pip3 install -r requirements.txt
# 或手动安装
pip3 install fastmcp httpx
启动 / 测试
# 直接运行,以 stdio 协议对外提供服务
python3 weather_mcp_server.py
# 或快速跑一遍内置逻辑自测
python3 -c "import asyncio, weather_mcp_server as s; asyncio.run(s.query_weather_by_city('北京'))"
接入 MCP 客户端
任意支持 MCP 的客户端(Claude Desktop、Cursor、VS Code、各类 MCP CLI 等),
把服务注册为 stdio 类型即可(本地路径需换成你的实际路径):
{
"mcpServers": {
"weather": {
"command": "python3",
"args": ["/home/sandbox/.openclaw/workspace/weather-mcp/weather_mcp_server.py"]
}
}
}
用 mcp CLI 调试
pip3 install mcp # 官方 CLI,用于本地调试
mcp dev /home/sandbox/.openclaw/workspace/weather-mcp/weather_mcp_server.py
项目结构
weather-mcp/
├── weather_mcp_server.py # MCP 服务主程序(核心)
├── requirements.txt # 依赖清单
└── README.md
说明
- 天气数据来自 Open-Meteo(免费、无需 Key,全球覆盖)
- 通过
FastMCP声明式装饰器写工具,代码简洁、易于扩展 - 如需新增指标(如空气质量、紫外线),在
FORECAST_URL的current/daily参数里追加字段即可