气象MCP服务器
中文文档 |英语
使用模型上下文协议(MCP)构建的简单天气信息服务。
概述
Weather MCP Server通过一个简单的API接口为世界各地的城市提供天气信息。它使用模型上下文协议(MCP)与客户端通信,允许与AI助手和其他MCP兼容应用程序轻松集成。
特性
- 按城市名称获取当前天气状况
- 返回温度、天气描述、湿度和风速
- 如果外部API不可用,则回退到生成的数据
- 简单轻便的实现
技术栈
- TypeScript
- Node.js
- MCP SDK(@modelcontextprotocol/SDK)
- Zod用于验证
安装
- 克隆存储库
git clone https://github.com/Annihilater/mcp-server-get-weather- 安装依赖项:
npm install- 构建项目:
npm run build用法
启动服务器:
npx @modelcontextprotocol/inspector node dist/index.jsMCP配置
要在Cursor中使用此天气服务,需要在~/.cursor/mcp.json文件中添加以下配置:
"mcp-server-get-weather": {
"command": "node",
"args": [
"
/dist/index.js"
]
}将 替换为实际项目路径。配置完成后,可以通过MCP工具调用mcp_mcp_server_get_weather_get_weather函数来获取天气信息。
示例
api参考
get_weather
获取指定城市的天气信息。
参数
| 名称 | 类型 | 描述 |
|---|---|---|
| cityName | string | 要获取天气的城市名称 |
响应
返回具有以下结构的JSON对象:
{
"city": "London",
"current_condition": {
"temperature": "15",
"weatherDesc": "Partly cloudy",
"humidity": "71",
"windSpeed": "11",
"observation_time": "06:53 PM"
},
"forecast": {
"maxTemp": "16",
"minTemp": "9",
"sunHour": "7.4",
"date": "2023-04-12"
}
}发展
可用脚本
npm run build-构建项目并使入口点可执行npm run watch-自动监视更改和重建npx @modelcontextprotocol/inspector node dist/index.js-启动服务器
项目结构
src/index.ts-入口点,使用stdio传输设置MCP服务器src/server.ts-服务器实现,定义天气工具
许可证
麻省理工学院
