气象MCP服务器🌤️
模型上下文协议(MCP)服务器,使用Open-Meteo API为任何城市提供实时天气信息。
特性
- 🌍 获取全球任何城市的当前天气
- 🌡️ 返回温度(摄氏度)
- 💨 提供风速(km/h)
- 📍 包括地理坐标
- 🐳 完全容器化Docker
- 🚀 易于部署和使用
快速开始
使用Docker(推荐)
从Docker Hub拉取并运行预构建映像:
docker pull 125478963/weather-mcp:latest
docker run -d -p 8000:8000 125478963/weather-mcp:latest服务器将在以下位置可用: http://localhost:8000/mcp
从源头构建
- 克隆此存储库:
git clone https://github.com/rajeevchandra/weather-mcp-docker.git
cd weather-mcp-docker- 构建Docker镜像:
docker build -t weather-mcp .- 运行容器:
docker run -d -p 8000:8000 weather-mcp用法
此MCP服务器公开了 weather 该工具可供Claude Desktop等MCP客户端使用。
可用工具
weather(city: str)
- 返回指定城市的当前温度(°C)和风速(km/h)
- 默认城市:费城
示例响应
{
"city": "London",
"latitude": 51.5074,
"longitude": -0.1278,
"temperature_c": 15.2,
"windspeed_kmh": 12.5
}配置
服务器运行在:
- 主机:
0.0.0.0(可从容器外部进入) - 端口:
8000 - 端点:
/mcp
与MCP客户端一起使用
克劳德桌面
将此添加到您的Claude Desktop MCP设置中:
{
"mcpServers": {
"weather": {
"url": "http://localhost:8000/mcp"
}
}
}发展
先决条件
- Python 3.11+
- Docker(可选,用于容器化)
地方发展
- 安装依赖项:
pip install -r requirements.txt- 运行服务器:
python server.py测试
运行完整的测试脚本以验证服务器是否正常工作:
python complete_test.py这将:
- 初始化与MCP服务器的会话
- 列出可用工具
- 在多个城市(伦敦、巴黎、东京)测试天气工具
- 显示实时天气数据
预期产量:
✅ Session initialized successfully!
Server: WeatherMCP
Version: 1.20.0
🌍 Getting weather for London...
✅ Success!
Temperature: 14.2°C
Wind Speed: 15.3 km/h或者使用快速健康检查:
curl http://localhost:8000/mcp项目结构
weather-mcp/
├── server.py # Main MCP server implementation
├── requirements.txt # Python dependencies
├── Dockerfile # Docker configuration
├── easy_test.py # Simple test script
└── README.md # This file运作原理
- 地理编码:使用Open-Meteo Geocoding API将城市名称转换为坐标
- 天气数据:使用Open-Meteo weather API获取当前天气数据
- MCP协议:通过模型上下文协议公开天气数据
API学分
此服务器使用 开放气象API 其是免费的并且不需要API密钥。
Docker Hub
Docker Hub上提供了预构建映像:
- 最新的:
125478963/weather-mcp:latest - 版本1:
125478963/weather-mcp:v1
故障排除
服务器没有响应?
检查容器是否正在运行:
docker ps | grep weather-mcp查看日志:
docker logs 端口已在使用中?
使用其他端口:
docker run -d -p 8080:8000 125478963/weather-mcp:latest许可证
MIT许可证-可根据需要自由使用和修改。
贡献
欢迎投稿!请随时提交拉取请求。
支持
有关问题和疑问,请在GitHub上打开问题。
______________________________________________________________________
由以下材料制成❤️ 使用模型上下文协议
