Weather MCP Server
天气 MCP 服务器
一个支持 OpenAPI 的天气数据模型上下文协议 (MCP) 服务器。该服务器提供来自 OpenWeatherMap API 的天气信息,并可供 LLM 智能体通过 MCP 使用。
功能特性
MCP stdio 传输,用于 LLM 智能体集成
HTTP REST API,带有 OpenAPI 3.0 规范
4 个天气工具:
按城市获取当前天气
按坐标获取当前天气
获取天气预报(5 天,3 小时间隔)
获取温度范围摘要
模拟数据支持,无需 API 密钥即可进行测试
TypeScript 实现,具有完整的类型安全
Related MCP server: mcp-openweather
安装
cd weather-mcp-server
npm install
npm run build使用方法
1. MCP 服务器 (stdio 传输)
为 LLM 智能体运行 MCP 服务器:
npm start或在开发模式下运行:
npm run dev2. 带 OpenAPI 的 HTTP 服务器
运行带有 REST API 的 HTTP 服务器:
npm run dev:http服务器将在 http://localhost:3000 启动,包含:
/health- 健康检查端点/openapi- OpenAPI 规范/api/v1/weather/current/{city}- 按城市获取当前天气/api/v1/weather/current/coordinates- 按坐标获取当前天气/api/v1/weather/forecast/{city}- 天气预报
3. 配置
设置您的 OpenWeatherMap API 密钥(可选 - 如果未提供,将使用模拟数据):
export OPENWEATHER_API_KEY=your_api_key_here或创建一个 .env 文件:
OPENWEATHER_API_KEY=your_api_key_hereMCP 工具
服务器提供以下 MCP 工具:
工具名称 | 描述 | 参数 |
| 按城市获取当前天气 |
|
| 按坐标获取当前天气 |
|
| 获取天气预报 |
|
| 获取温度范围摘要 |
|
API 端点
HTTP REST API
所有端点均返回具有以下结构的 JSON:
{
"success": true,
"data": { ... }
}1. 按城市获取当前天气
GET /api/v1/weather/current/{city}示例:
curl http://localhost:3000/api/v1/weather/current/London2. 按坐标获取当前天气
GET /api/v1/weather/current/coordinates?lat={latitude}&lon={longitude}示例:
curl "http://localhost:3000/api/v1/weather/current/coordinates?lat=51.5074&lon=-0.1276"3. 天气预报
GET /api/v1/weather/forecast/{city}?days={days}示例:
curl "http://localhost:3000/api/v1/weather/forecast/New%20York?days=3"测试
运行测试套件:
npm test运行 MCP 检查器进行调试:
npm run inspect项目结构
weather-mcp-server/
├── src/
│ ├── index.ts # MCP stdio server
│ ├── http-server.ts # HTTP server with OpenAPI
│ ├── types/
│ │ └── weather.ts # TypeScript types and Zod schemas
│ ├── utils/
│ │ └── weather-client.ts # OpenWeatherMap API client
│ └── tools/
│ └── weather-tools.ts # MCP tool definitions
├── dist/ # Compiled JavaScript
├── test/
│ └── test.js # Test suite
├── package.json
├── tsconfig.json
└── README.md依赖项
@modelcontextprotocol/sdk- 用于 TypeScript 的 MCP SDKexpress- HTTP 服务器框架axios- 用于 API 调用的 HTTP 客户端zod- 模式验证typescript- TypeScript 编译器
许可证
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
OpenWeather MCP — wraps the OpenWeatherMap API (openweathermap.org)
Weather, code search, currency & Solana trust scoring as MCP tools. Free, no API key needed.
Hosted MCP server for Xweather weather data: conditions, forecasts, alerts, and more.
OpenWeather data for AI agents: list feeds, sign up, check balance, get a top-up link, fetch data.
Related MCP Servers
- FlicenseBqualityDmaintenanceEnables AI agents to retrieve real-time weather conditions and forecasts via OpenWeatherMap API. Supports interactive weather queries and travel planning through MCP tools, resources, and prompts.2-
- AlicenseNot gradedqualityCmaintenanceWraps the OpenWeatherMap API to provide weather data through MCP, enabling AI agents to query current conditions, forecasts, and other weather information via natural language.5 npmMIT
- AlicenseNot gradedqualityCmaintenanceProvides weather data from WeatherAPI.com through MCP, enabling AI agents to query current conditions and forecasts via natural language.5 npmMIT
- FlicenseBqualityDmaintenanceProvides real-time weather information for cities worldwide using the OpenWeatherMap API, accessible through natural language queries via the MCP protocol.1-