天气数据服务

一个基于MCP协议的天气数据服务器,提供实时天气和天气预报信息。

  • by sujinnair
  • Rust
  • 本地部署
  • 更新于
在 GitHub 查看 sujinnair/mcp-weather-rust

使用说明

天气MCP服务器

一个使用Tomorrow.io API提供实时天气和预报信息的模型上下文协议(MCP)服务器。

概述

这台服务器实现了MCP协议,以提供两款天气工具:

  • get_realtime_weather获取指定地点的当前天气状况
  • get_weather_forecast获取每小时或每日天气预报

要求

  • Rust 1.70+
  • 一个Tomorrow.io API密钥(免费套餐可在https://www.tomorrow.io获取)

设置

  1. 克隆仓库 并安装依赖项:
   cargo build
  1. 创建一个 .env 文件 在项目根目录中使用您的API密钥:
   echo "WEATHER_API_KEY=your_api_key_here" > .env

重要提示: 永远不要犯下 .env 将文件提交到版本控制系统。它已经在(版本控制系统的)列表中了 .gitignore。

  1. 更新配置 在 config/config.json:
   {
     "weather_forecast_url": "https://api.tomorrow.io/v4/weather/forecast?location={location}&timesteps={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)