一个提供全球城市天气信息的 Model Context Protocol (MCP) 服务器,可助力你轻松获取各地天气详情。
本服务器可提供全球城市的天气信息,你可以按照以下步骤进行安装和使用。
npm install
npm run build
npm start
在你的 MCP 配置中添加以下内容:
{
"mcpServers": {
"weather-server": {
"command": "node",
"args": ["path/to/weather-server/build/index.js"],
"env": {
"OPENWEATHER_API_KEY": "your-api-key-here" // 可选 - 未提供时将使用 mock 数据
},
"disabled": false,
"autoApprove": []
}
}
}
此服务器有两种运行模式:
OPENWEATHER_API_KEY 环境变量提供 OpenWeather API 密钥时,服务器将从 OpenWeather API 获取实时天气数据。要获取 OpenWeather API 密钥:
在没有 API 密钥的情况下,mock 数据模式非常适合开发、测试或不需要实时天气数据的情况。
获取指定城市的当前天气信息。
{
"city": "string" // 城市名称(例如,“伦敦”,“纽约”,“东京”)
}
{
"location": "London, GB",
"date": "2025年3月24日,星期一",
"time": "下午7:30:00",
"temperature": {
"current": "12°C",
"feelsLike": "10°C"
},
"weather": {
"main": "多云",
"description": "阴云密布",
"icon": " cloudy "
},
"wind": {
"speed": 15,
"direction": 270
},
"humidity": 80,
"source": "openweather" // 来源标识符,可以是 openweather 或 mock 数据
}
| 属性 | 详情 |
|---|---|
location |
城市及其对应国家的标识符。 |
date 和 time |
天气数据获取的时间和日期。 |
temperature |
当前温度和体感温度。 |
weather |
当前天气状况,包括主要描述和图标。 |
wind |
风速和方向(以度数表示,0 - 360 度)。 |
humidity |
相对湿度百分比。 |
source |
数据来源标识符,可以是 openweather 或 mock 数据。 |
此项目使用 MIT 许可证。