天气MCP服务器
一个使用Tomorrow.io API提供实时天气和预报信息的模型上下文协议(MCP)服务器。
概述
这台服务器实现了MCP协议,以提供两款天气工具:
get_realtime_weather获取指定地点的当前天气状况get_weather_forecast获取每小时或每日天气预报
要求
- Rust 1.70+
- 一个Tomorrow.io API密钥(免费套餐可在https://www.tomorrow.io获取)
设置
- 克隆仓库 并安装依赖项:
cargo build- 创建一个
.env文件 在项目根目录中使用您的API密钥:
echo "WEATHER_API_KEY=your_api_key_here" > .env重要提示: 永远不要犯下 .env 将文件提交到版本控制系统。它已经在(版本控制系统的)列表中了 .gitignore。
- 更新配置 在
config/config.json:
{
"weather_forecast_url": "https://api.tomorrow.io/v4/weather/forecast?location={location}×teps={timestep}&apikey={apiKey}",
"weather_realtime_url": "https://api.tomorrow.io/v4/weather/realtime?location={location}&apikey={apiKey}"
}运行服务器
cargo run服务器在标准输入(stdin)上监听JSON-RPC请求,并将响应输出到标准输出(stdout)。
API工具
获取实时天气
获取某地的当前天气。
参数:
location(字符串,必填):城市名称或地点
示例回复:
Current weather for London: 15.5°C, Partly Cloudy. Humidity: 65%, Wind: 3.2 m/s (as of 2024-10-19T14:30:00Z)获取天气预报
获取某地的天气预报。
参数:
location(字符串,必填):城市名称或位置timestep(字符串,可选):1h对于每小时或1d用于日常预报(默认:1d)
示例回复:
Weather forecast for London:
2024-10-19T15:00:00Z: 16°C, Partly Cloudy. Humidity: 63%, Precipitation: 10%, Wind: 3.1 m/s
2024-10-20T00:00:00Z: 12°C, Cloudy. Humidity: 72%, Precipitation: 20%, Wind: 2.8 m/s
...环境变量
WEATHER_API_KEY您的Tomorrow.io API密钥(必需)
许可证
麻省理工学院(MIT)
