- MCP 天气预报服务器
MCP 天气预报服务器
Content
MCP 天气预报服务器
基于高德地图API的MCP (Model Context Protocol) 天气预报服务器,使用TypeScript开发。
🌟 功能特性
- ✅ 实时天气查询 - 获取指定城市的当前天气状况
- ✅ 天气预报查询 - 获取未来几天的天气预报
- ✅ 智能城市识别 - 支持中国市级名称自动转换为城市编码
- ✅ 时区支持 - 可选的时区时间参数
- ✅ 详细天气信息 - 包含温度、湿度、风向、风力等完整信息
- ✅ 错误处理 - 完善的错误提示和异常处理
📋 系统要求
- Node.js 16.0 或更高版本
- TypeScript 5.0 或更高版本
- 高德地图API密钥
🚀 快速开始
1. 安装依赖
npm install
2. 构建项目
npm run build
3. 运行服务器
npm start
或者开发模式:
npm run dev
🔑 获取高德地图API密钥
- 访问 高德开放平台
- 注册并登录账号
- 进入控制台 → 应用管理 → 我的应用
- 创建新应用,选择「Web服务」类型
- 获取API Key
🛠️ 工具使用说明
get-weather-forecast
获取指定城市的天气信息。
参数说明
| 参数名 | 类型 | 必选 | 说明 | 示例 |
|---|---|---|---|---|
cityName | string | ✅ | 中国市级名称 | "北京市", "上海市", "广州市" |
date | string | ❌ | 查询日期 (YYYY-MM-DD) | "2024-01-15" (默认当天) |
forecastType | string | ❌ | 查询类型 | "current" (实时) 或 "forecast" (预报) |
API密钥配置
本服务器从环境变量 AMAP_API_KEY 中读取高德地图API密钥,无需在调用时传递。请确保在启动服务器前设置此环境变量。
使用示例
实时天气查询:
{
"cityName": "北京市",
"forecastType": "current"
}
天气预报查询:
{
"cityName": "广州市",
"date": "2024-01-15",
"forecastType": "forecast"
}
mcp-server 配置示例
{
"mcpServers": {
"weather-forecast": {
"command": "node",
"args": [
"/path/to/your/build/index.js"
],
"env": {
"AMAP_API_KEY": "your_gaode_api_key_here"
}
}
}
}
返回示例
实时天气:
🌈 天气查询结果
📍 北京 北京市
🌤️ 天气:晴
🌡️ 温度:15°C
💨 风向:西北风
🌪️ 风力:3级
💧 湿度:45%
⏰ 更新时间:2024-01-15 14:30:00
📅 查询日期: 2024-01-15
天气预报:
🌈 天气查询结果
📍 上海 上海市
📅 未来几天天气预报:
今天 (星期一)
🌤️ 白天:晴 | 夜间:多云
🌡️ 温度:8°C ~ 18°C
💨 风向:东北风 3级 | 东风 2级
2024-01-16 (星期二)
🌤️ 白天:多云 | 夜间:阴
🌡️ 温度:10°C ~ 20°C
💨 风向:东风 2级 | 东南风 1级
📅 查询日期: 2024-01-15
🏗️ 项目结构
mcp-weather-server/
├── src/
│ └── index.ts # 主服务器代码
├── build/ # 编译输出目录
├── package.json # 项目配置
├── tsconfig.json # TypeScript配置
└── README.md # 项目文档
🔧 开发说明
核心组件
-
地理编码模块 (
getCityCode)- 将城市名称转换为高德地图城市编码
- 支持模糊匹配和智能识别
-
天气查询模块 (
getWeatherInfo)- 调用高德天气API获取天气数据
- 支持实时天气和预报天气两种模式
-
数据格式化模块
formatLiveWeather: 格式化实时天气数据formatForecastWeather: 格式化预报天气数据
API接口说明
高德地理编码API
- 接口地址:
https://restapi.amap.com/v3/geocode/geo - 功能: 将地址转换为坐标和城市编码
- 文档: 地理编码API文档
高德天气查询API
- 接口地址:
https://restapi.amap.com/v3/weather/weatherInfo - 功能: 根据城市编码获取天气信息
- 文档: 天气查询API文档
⚠️ 注意事项
- API限制: 高德地图个人开发者账号每日调用限制为5000次
- 城市名称: 请使用标准的中国市级名称,如"北京市"而不是"北京"
- 网络环境: 确保服务器能够访问高德地图API服务
- 密钥安全: 请妥善保管API密钥,避免泄露
🐛 故障排除
常见错误
-
"无法找到城市编码"
- 检查城市名称拼写是否正确
- 确认使用的是标准市级名称
-
"API密钥无效"
- 验证API密钥是否正确
- 确认密钥对应的服务类型为"Web服务"
-
"网络请求失败"
- 检查网络连接
- 确认防火墙设置允许访问高德API
📄 许可证
MIT License
🤝 贡献
欢迎提交Issue和Pull Request来改进这个项目!
📞 支持
如有问题,请通过以下方式联系:
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Playwright McpPlaywright MCP server
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
DeepChatYour AI Partner on Desktop
ChatWiseThe second fastest AI chatbot™
CursorThe AI Code Editor
Serper MCP ServerA Serper MCP Server
Tavily Mcp
WindsurfThe new purpose-built IDE to harness magic
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题;
Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Amap Maps高德地图官方 MCP Server
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.