Weather API MCP Server について
Weather API MCP Serverは、QWeather APIを通じて現在の天気、予報、都市検索を提供します。天気情報を必要とするMCPクライアント向けで、単位、言語、予報期間を設定できます。
主な機能
- 01現在の天気の取得
- 023~30日間の予報取得
- 03今後24時間の予報取得
- 04都市IDと位置情報の検索
- 05単位と応答言語の設定
活用シーン
- 01指定地点の現在の天気を確認
- 02日別または時間別の予報を取得
- 03都市名からQWeatherの位置IDを検索
MCP 対応
MCPサーバーはgetWeather、getWeatherForecast、getHourlyWeather、lookupCityの4つのツールを公開します。クライアントは都市名、座標、QWeatherの位置IDで呼び出せます。
設定
ローカルサーバーの設定はどのクライアントでも共通です。コピーしてクライアントの MCP 設定ファイルに貼り付けてください。
ツール
ローカルサーバーのツールはマシン上で起動して初めて取得できます。メンテナーはまだツール一覧を提供していません。
詳細
Weather API MCP サーバー
和风天气(QWeather)API を使用して、現在の天気データや予報を提供する、天気情報向けの Model Context Protocol(MCP)サーバー実装です。
機能
- 現在の天気:任意の地域の現在の天気データを取得します
- 天気予報:3 日間から 30 日間の天気予報を取得します
- 時間別予報:24 時間の天気予報を取得します
- 都市の検索:より正確な天気データを取得するため、都市情報や ID を検索します
- オプションのカスタマイズ:単位、言語、追加の詳細を設定できます
- QWeather を利用:和风天气(QWeather)API と連携し、正確な天気データを提供します
インストール
npm install mcp-weather-api
または、npx で直接使用できます。
npx mcp-weather-api
API リファレンス
天気ツール
サーバーは、MCP 経由で呼び出せる 4 つの天気ツールを提供します。
1. 現在の天気を取得
// Tool name: getWeather
{
location: "New York, NY", // Can be city name, coordinates like "119.98,30.24", or QWeather location ID
options: {
units: "metric", // "metric" (Celsius) or "imperial" (Fahrenheit)
language: "en", // Language code (en, zh, etc.)
}
}
2. 天気予報を取得
// Tool name: getWeatherForecast
{
location: "London, UK", // Can be city name, coordinates like "119.98,30.24", or QWeather location ID
options: {
units: "imperial", // "metric" (Celsius) or "imperial" (Fahrenheit)
days: 3, // Supports 3, 7, 10, 15, or 30 days
language: "en" // Language code (en, zh, etc.)
}
}
3. 時間別の天気予報を取得
// Tool name: getHourlyWeather
{
location: "Tokyo, Japan", // Can be city name, coordinates like "119.98,30.24", or QWeather location ID
options: {
units: "metric", // "metric" (Celsius) or "imperial" (Fahrenheit)
hours: 24, // Number of hours (default: 24, max: 24)
language: "ja" // Language code (en, zh, ja, etc.)
}
}
4. 都市の検索
// Tool name: lookupCity
{
location: "Beijing", // City name or coordinates like "119.98,30.24"
options: {
language: "en" // Language code (en, zh, etc.)
}
}
天気オプション
現在の天気ツールのオプション:
interface WeatherOptions {
units?: "metric" | "imperial"; // Temperature units (default: metric)
language?: string; // Response language code
}
予報ツールのオプション:
interface ForecastOptions {
units?: "metric" | "imperial"; // Temperature units (default: metric)
days?: number; // Number of days (default: 3)
language?: string; // Response language code
}
時間別予報ツールのオプション:
interface HourlyForecastOptions {
units?: "metric" | "imperial"; // Temperature units (default: metric)
hours?: number; // Number of hours (default: 24, max: 24)
language?: string; // Response language code
}
都市検索ツールのオプション:
interface CityLookupOptions {
language?: string; // Response language code
}
レスポンス形式
すべてのツールは、次の形式でレスポンスを返します。
{
content: Array<{
type: "text";
text: string;
}>;
}
レスポンスの例
現在の天気のレスポンス
Weather for New York:
Observation Time: 2023-11-15T12:30+08:00
Current Conditions: Partly Cloudy (Icon: 101)
Temperature: 18.5°C
Feels Like: 19.2°C
Wind Information:
- Direction: Northeast (45°)
- Scale: 3
- Speed: 15 km/h
Other Information:
- Humidity: 65%
- Precipitation: 0.0 mm
- Pressure: 1013 hPa
- Visibility: 25 km
- Cloud Cover: 30%
- Dew Point: 12.1°C
Updated: 2023-11-15T12:35+08:00
Data Sources: QWeather
License: QWeather Developers License
天気予報のレスポンス
Weather Forecast for London:
2023-11-15:
Time Information:
- Sunrise: 07:12, Sunset: 16:30
- Moonrise: 15:40, Moonset: 03:25
- Moon Phase: Waxing Gibbous (Icon: 802)
Day Weather:
- Conditions: Rain (Icon: 305)
- Temperature Range: 12.0°F / 7.0°F
- Wind: Northwest (315°)
- Wind Scale: 3, Speed: 18 km/h
Night Weather:
- Conditions: Cloudy (Icon: 101)
- Wind: North (0°)
- Wind Scale: 2, Speed: 10 km/h
Other Information:
- Humidity: 75%
- Precipitation: 5.2 mm
- Pressure: 1008 hPa
- Visibility: 10 km
- Cloud Cover: 85%
- UV Index: 2
...additional days...
Data Sources: QWeather
License: QWeather Developers License
都市検索のレスポンス
Location Information:
1. Beijing (ID: 101010100)
Location: 39.90499, 116.40529
Region: Beijing, Beijing, China
Timezone: Asia/Shanghai (UTC +8.0)
Type: city, Rank: 10
2. Beijing Shi (ID: 101010000)
Location: 39.90998, 116.40529
Region: Beijing, Beijing, China
Timezone: Asia/Shanghai (UTC +8.0)
Type: city, Rank: 10
Note: Use the ID (e.g., "101010100") in other weather tools to get weather information for this location.
Data Sources: QWeather
License: QWeather Developers License
MCP での使用方法
MCP の設定に Weather MCP サーバーを追加します。
{
"mcpServers": {
"weather": {
"command": "npx",
"args": ["-y", "mcp-weather-api"]
}
}
}
QWeather API
このサーバーは、和风天气(QWeather)API を使用して天気データを取得します。デモ用に API キーがパッケージに含まれています。本番環境で使用する場合は、QWeather からご自身の API キーを取得してください。
使用する API エンドポイント
-
現在の天気 -
/weather/now- 現在の天候状況を返します
- レスポンスには、気温や湿度などを含む
nowオブジェクトが含まれます - API ドキュメント
-
天気予報 -
/weather/3d、/weather/7d、/weather/10d、/weather/15d、/weather/30d- さまざまな期間の天気予報を返します
- レスポンスには、日ごとの予報データを含む
daily配列が含まれます - API ドキュメント
-
時間別の天気予報 -
/weather/24h- 今後 24 時間の時間別天気予報を返します
- レスポンスには、時間別の予報データを含む
hourly配列が含まれます - API ドキュメント
-
都市の検索 -
/city/lookup- 名前または座標から都市情報を検索します
- 都市 ID やその他の地域情報を返します
- API ドキュメント
API レスポンスの構造
現在の天気(/weather/now)
{
"code": "200",
"updateTime": "2021-11-15T16:35+08:00",
"now": {
"temp": "22.5",
"humidity": "65",
"text": "Partly cloudy",
"windSpeed": "10.2",
"windDir": "East",
"feelsLike": "24.0",
"pressure": "1012",
"vis": "10",
"cloud": "30",
"dew": "15.5"
}
}
天気予報(/weather/3d)
{
"code": "200",
"updateTime": "2021-11-15T16:35+08:00",
"fxLink": "http://hfx.link/2ax1",
"daily": [
{
"fxDate": "2021-11-15",
"sunrise": "06:58",
"sunset": "16:59",
"moonrise": "15:16",
"moonset": "03:40",
"moonPhase": "盈凸月",
"moonPhaseIcon": "803",
"tempMax": "12",
"tempMin": "-1",
"iconDay": "101",
"textDay": "多云",
"iconNight": "150",
"textNight": "晴",
"wind360Day": "45",
"windDirDay": "东北风",
"windScaleDay": "1-2",
"windSpeedDay": "3",
"wind360Night": "0",
"windDirNight": "北风",
"windScaleNight": "1-2",
"windSpeedNight": "3",
"humidity": "65",
"precip": "0.0",
"pressure": "1020",
"vis": "25",
"cloud": "4",
"uvIndex": "3"
}
// Additional days...
]
}
時間別の天気予報(/weather/24h)
{
"code": "200",
"updateTime": "2021-11-15T16:35+08:00",
"fxLink": "http://hfx.link/2ax1",
"hourly": [
{
"fxTime": "2021-11-15T17:00+08:00",
"temp": "11",
"icon": "150",
"text": "晴",
"wind360": "335",
"windDir": "西北风",
"windScale": "3-4",
"windSpeed": "20",
"humidity": "73",
"pop": "7",
"precip": "0.0",
"pressure": "1013",
"cloud": "10",
"dew": "7"
}
// Additional hours...
]
}
都市の検索(/city/lookup)
{
"code": "200",
"location": [
{
"name": "Beijing",
"id": "101010100",
"lat": "39.90499",
"lon": "116.40529",
"adm2": "Beijing",
"adm1": "Beijing",
"country": "China",
"tz": "Asia/Shanghai",
"utcOffset": "+08:00",
"isDst": "0",
"type": "city",
"rank": "10",
"fxLink": "http://hfx.link/2ax1"
}
// Additional locations...
]
}
設定
環境変数を使って、さまざまなオプションを設定できます。
# API Configuration
export QWEATHER_API_KEY=your-api-key
export QWEATHER_API_URL=https://devapi.qweather.com/v7
export QWEATHER_GEO_API_URL=https://geoapi.qweather.com/v2
export WEATHER_DEFAULT_LOCATION=101010100 # Default location code or coordinates
# Default Options
export WEATHER_DEFAULT_UNITS=metric # or 'imperial'
export WEATHER_DEFAULT_LANGUAGE=en # language code
export WEATHER_INCLUDE_DETAILS=true # or 'false'
export WEATHER_FORECAST_DAYS=3 # number of days (max 30)
または、MCP の設定で指定できます。
{
"mcpServers": {
"weather": {
"command": "npx",
"args": ["-y", "mcp-weather-api"],
"env": {
"QWEATHER_API_KEY": "your-api-key",
"QWEATHER_API_URL": "https://devapi.qweather.com/v7",
"QWEATHER_GEO_API_URL": "https://geoapi.qweather.com/v2",
"WEATHER_DEFAULT_LOCATION": "101010100",
"WEATHER_DEFAULT_UNITS": "imperial",
"WEATHER_DEFAULT_LANGUAGE": "zh",
"WEATHER_INCLUDE_DETAILS": "true",
"WEATHER_FORECAST_DAYS": "7"
}
}
}
}
地域の指定形式
地域は、次の 3 つの形式で指定できます。
- 都市名:例:「New York」、「London」、「Beijing」
- 座標:例:「119.98,30.24」(経度、緯度)
- QWeather の地域 ID:例:「101010100」(北京)
座標を使用する場合、形式は longitude,latitude(例:「119.98,30.24」)である必要があります。この値は QWeather API に直接渡されます。
より正確に地域を指定するには、lookupCity ツールを使用して適切な地域 ID を検索してください。
中国の都市の位置コード
中国の都市では、より正確に位置を指定できる QWeather の位置 ID を使用できます。中国の都市コードの完全な一覧は、QWeather LocationList リポジトリで確認できます。
この CSV ファイルには、中国の都市の位置 ID が次の形式で含まれています。
開発
前提条件
- Node.js 16 以降
- npm または yarn
セットアップ
- リポジトリをクローンします
- 依存関係をインストールします。
npm install
ビルド
npm run build
開発モードでの実行
npm run dev
コメント
AI アプリケーションが外部のツールやデータソースに統一的な方法で接続するためのオープンなプロトコルです。クライアントはモデルとの対話を担い、MCP サーバーはツール・リソース・プロンプトテンプレートを提供します。標準メッセージでやり取りするため、1 つのサーバーを複数のクライアントで再利用できます。