Skip to main content
Glama
Weather MCP Server

Weather MCP Server

by akdrione

Weather MCP Server

OpenAPIサポートを備えた気象データ用のModel Context Protocol (MCP) サーバーです。このサーバーはOpenWeatherMap APIから気象情報を提供し、MCPを通じてLLMエージェントが利用できます。

機能

  • LLMエージェント統合のための MCP stdioトランスポート

  • OpenAPI 3.0仕様を備えた HTTP REST API

  • 4つの気象ツール:

    1. 都市名による現在の天気の取得

    2. 座標による現在の天気の取得

    3. 天気予報の取得(5日間、3時間間隔)

    4. 気温範囲の概要取得

  • 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 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, デフォルト: 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

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • F
      license
      B
      quality
      D
      maintenance
      Enables 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
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Wraps the OpenWeatherMap API to provide weather data through MCP, enabling AI agents to query current conditions, forecasts, and other weather information via natural language.
      256 npm
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Provides weather data from WeatherAPI.com through MCP, enabling AI agents to query current conditions and forecasts via natural language.
      146 npm
      MIT
    • F
      license
      B
      quality
      D
      maintenance
      Provides real-time weather information for cities worldwide using the OpenWeatherMap API, accessible through natural language queries via the MCP protocol.
      1
      -