Uses Axios HTTP client for making API requests to weather and geocoding services, enabling reliable data fetching from Open-Meteo and other services.
Provides specific installation instructions for macOS users, including the location of configuration files needed for setup.
Runs as a Node.js application, with specific instructions for running the server through the Node.js runtime environment.
Built with TypeScript for type safety, with instructions for compiling the TypeScript code before running the server.
Implements data validation using Zod to ensure proper formatting and validation of user inputs and API responses.
天气MCP服务器 🌤️
一个基于Model Context Protocol (MCP)的天气查询服务器,可以根据用户输入的地址或自动获取当前位置来查询天气信息和预报。
功能特性 ✨
- 🌍 多种位置查询方式:支持地址、坐标、当前位置
- 🌤️ 实时天气信息:获取当前详细天气数据
- 📅 天气预报:支持1-10天的未来天气预报
- 📍 地理编码:地址与坐标之间的转换
- 💡 智能建议:根据天气条件提供生活建议
- 🌐 多语言支持:中文界面,支持全球地址查询
- 🔧 易于集成:标准MCP协议,兼容多种AI客户端
安装 🚀
1. 克隆项目
2. 安装依赖
3. 编译和运行
🎉 无需API密钥! 本项目使用完全免费的Open-Meteo API,无需注册或配置任何密钥。
使用方法 📖
在Claude Desktop中使用
- 打开Claude Desktop配置文件:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json
- Windows:
%APPDATA%/Claude/claude_desktop_config.json
- macOS:
- 添加MCP服务器配置:
- 重启Claude Desktop
在其他MCP客户端中使用
参考各客户端的文档,使用stdio传输协议连接到服务器:
可用工具 🔧
1. get-weather-by-address
根据地址获取当前天气信息
参数:
address
(string): 地址,例如:"北京市"、"上海市浦东新区"、"New York"
示例:
2. get-forecast-by-address
根据地址获取天气预报
参数:
address
(string): 地址days
(number, 可选): 预报天数,1-10天,默认5天
示例:
3. get-current-location-weather
获取当前位置的天气信息(基于IP地址)
参数: 无
示例:
4. get-current-location-forecast
获取当前位置的天气预报
参数:
days
(number, 可选): 预报天数,1-10天,默认5天
示例:
5. get-weather-by-coordinates
根据经纬度坐标获取天气信息
参数:
latitude
(number): 纬度,-90到90之间longitude
(number): 经度,-180到180之间
示例:
6. geocode-address
将地址转换为经纬度坐标
参数:
address
(string): 要解析的地址
示例:
可用资源 📚
weather://status
显示天气服务的配置状态和可用性
可用提示 🎯
weather-assistant
天气查询智能助手
参数:
location
(string, 可选): 位置信息query_type
(enum, 可选): 查询类型,"current"或"forecast"
示例输出 📋
天气信息示例
天气预报示例
技术架构 🏗️
核心组件
- WeatherService: 天气API调用和数据格式化
- LocationService: 地理位置服务和地址解析
- MCP Server: 基于标准MCP协议的服务器实现
依赖项
@modelcontextprotocol/sdk
: MCP协议实现axios
: HTTP请求库zod
: 数据验证dotenv
: 环境变量管理
API服务商
- Open-Meteo: 免费天气数据提供商
- Open-Meteo Geocoding: 免费地理编码服务
- IP-API: 免费IP地址定位服务
开发 🛠️
项目结构
开发命令
添加新功能
- 在相应的服务类中添加新方法
- 在
src/index.ts
中注册新的工具、资源或提示 - 更新类型定义(如需要)
- 重新编译和测试
故障排除 🔧
常见问题
- 网络连接问题
- 检查网络连接
- 确认防火墙设置允许外部API访问
- 地址解析失败
- 尝试使用更具体的地址
- 检查地址拼写是否正确
- 编译错误
- 确保Node.js版本 >= 18.0.0
- 删除
node_modules
和dist
目录后重新安装
- 服务暂时不可用
- Open-Meteo服务偶尔可能维护,请稍后重试
调试模式
启用详细日志:
贡献 🤝
欢迎贡献代码!请遵循以下步骤:
- Fork 项目
- 创建功能分支 (
git checkout -b feature/AmazingFeature
) - 提交更改 (
git commit -m 'Add some AmazingFeature'
) - 推送到分支 (
git push origin feature/AmazingFeature
) - 创建Pull Request
许可证 📄
本项目采用 MIT 许可证。详见 LICENSE 文件。
支持 💬
如果您遇到问题或有建议,请:
- 查看常见问题
- 搜索现有的Issues
- 创建新的Issue并详细描述问题
更新日志 📝
v1.0.0
- 初始版本发布
- 使用Open-Meteo免费API,无需密钥
- 支持基本天气查询功能
- 支持地址和坐标查询
- 支持当前位置自动检测
- 支持天气预报(最多16天)
- 提供智能天气建议
- 完全免费使用
享受使用天气MCP服务器! 🌤️✨
Related MCP Servers
- -security-license-qualityA Model Context Protocol server that provides current weather information and 3-day forecasts for specified cities using the Open-Meteo API.Last updated -Python
- AsecurityFlicenseAqualityA Model Context Protocol server that provides tools to fetch weather alerts for US states and forecasts based on latitude/longitude coordinates using the US National Weather Service API.Last updated -280TypeScript
- AsecurityFlicenseAqualityA Model Context Protocol server that provides current weather forecasts for specific locations and active weather alerts for US states.Last updated -2TypeScript
- -securityFlicense-qualityA production-ready Model Context Protocol server that provides weather data from OpenWeatherMap API, allowing users to query current weather by city name or coordinates with support for different temperature units.Last updated -Python