天气预报MCP服务器

天气预报MCP服务器

一个提供全球天气预报和当前天气状况的MCP服务器。

快速入门

  1. 安装依赖: pip install mcp-server requests pydantic

  2. 获取 OpenWeatherMap API Key: 访问 OpenWeatherMap 注册并获取 API Key。

  3. 启动服务:

    • 使用环境变量: export OPENWEATHER_API_KEY="your_api_key" # Linux/Mac set OPENWEATHER_API_KEY=your_api_key # Windows python weather_mcp_server.py
    • 或直接运行并提供参数。
  4. 配置 MCP 客户端: 在支持的客户端中添加配置,例如: { "weather_forecast": { "command": "python", "args": ["/path/weather_mcp_server.py"], "env": {"OPENWEATHER_API_KEY": "your_key"}, "disabled": false, "autoApprove": ["get_weather", "get_current_weather"] } }

  5. 调用工具:

    • get_weather: 查询指定地点的天气和预报。
    • get_current_weather: 查询指定地点的当前天气。
  6. 示例: AI助手调用示例: User: 纽约现在天气如何? AI: [调用 get_current_weather("New York", timezone_offset=-4)] 当前纽约天气:18°C,部分多云,湿度65%,风速3.5m/s。