Skip to main content
Glama
akdrione

Weather MCP Server

by akdrione

天气 MCP 服务器

一个支持 OpenAPI 的天气数据模型上下文协议 (MCP) 服务器。该服务器提供来自 OpenWeatherMap API 的天气信息,并可供 LLM 智能体通过 MCP 使用。

功能特性

  • MCP stdio 传输,用于 LLM 智能体集成

  • HTTP REST API,带有 OpenAPI 3.0 规范

  • 4 个天气工具

    1. 按城市获取当前天气

    2. 按坐标获取当前天气

    3. 获取天气预报(5 天,3 小时间隔)

    4. 获取温度范围摘要

  • 模拟数据支持,无需 API 密钥即可进行测试

  • TypeScript 实现,具有完整的类型安全

安装

cd weather-mcp-server
npm install
npm run build

使用方法

1. MCP 服务器 (stdio 传输)

为 LLM 智能体运行 MCP 服务器:

npm start

或在开发模式下运行:

npm run dev

2. 带 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_here

MCP 工具

服务器提供以下 MCP 工具:

工具名称

描述

参数

weather_get_current_by_city

按城市获取当前天气

city: string

weather_get_current_by_coords

按坐标获取当前天气

latitude: number, longitude: number

weather_get_forecast

获取天气预报

city: string, days?: number (1-10, default: 5)

weather_get_temperature_range

获取温度范围摘要

city: string

API 端点

HTTP REST API

所有端点均返回具有以下结构的 JSON:

{
  "success": true,
  "data": { ... }
}

1. 按城市获取当前天气

GET /api/v1/weather/current/{city}

示例:

curl http://localhost:3000/api/v1/weather/current/London

2. 按坐标获取当前天气

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 SDK

  • express - HTTP 服务器框架

  • axios - 用于 API 调用的 HTTP 客户端

  • zod - 模式验证

  • typescript - TypeScript 编译器

许可证

MIT

-
security - not tested
F
license - not found
-
quality - not tested

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/akdrione/weather-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server