mcp-weather-forecast-server
v1.0.1
Published
Weather forecast MCP server
Maintainers
Readme
MCP Weather Server
一个基于 Model Context Protocol (MCP) 的天气预报服务器。支持获取全球城市的实时天气和未来5天天气预报。
安装
npm install mcp-weather-forecast-server配置
获取 OpenWeatherMap API Key:
- 访问 OpenWeatherMap
- 注册账号并获取 API Key
在你的 mcp.json 中添加配置:
{
"mcpServers": {
"weather": {
"command": "npx",
"args": ["mcp-weather-forecast-server"],
"disabled": false,
"autoApprove": ["*"],
"env": {
"OPENWEATHERMAP_API_KEY": "你的API密钥"
}
}
}
}API 功能
get_weather
获取城市当前天气信息
参数:
- city: 城市名称(必填)
- units: 温度单位(可选,默认 metric)
- metric: 摄氏度
- imperial: 华氏度
- standard: 开尔文
返回数据:
{
"temperature": 25.95,
"feels_like": 25.95,
"humidity": 73,
"description": "overcast clouds",
"wind_speed": 0.85
}get_forecast
获取城市5天天气预报
参数:
- city: 城市名称(必填)
- units: 温度单位(可选,默认 metric)
返回数据:
[
{
"date": "2025-04-19 12:00:00",
"temperature": 25.95,
"description": "light rain",
"humidity": 75
},
// ... 更多预报数据
]示例
// 在你的代码中使用
const response = await fetch('http://localhost:3000/weather?city=beijing');
const weather = await response.json();
console.log(weather);许可证
MIT
