mcp-weather-connector
mcp-weather-connector
MCP-サーバーで、AIエージェントに Open-Meteo 経由で天気予報へのアクセスを提供します。Open-Meteo は、APIキーも登録も不要な公開APIです。
意図的に小さく設計されています。このリポジトリのテーマは、エージェント向けのツールレイヤーがどのように構成されるかであり、天気ではありません。ここでの天気は、モデルと外部の世界との間にある信頼の境界を示すための、分かりやすい題材です。
これは何のためか
Model Context Protocol とは、言語モデルに外部のサービスでアクションを実行する権限を与える方法です。その権利が出現すると、「モデルがツールに無効なデータを渡し、その瞬間に外部のサービスが503を返したらどうなるのか」という問題が生じます。
このコードで明示的に示されている3つの判断は次のとおりです。
モデルからの入力は信頼されていません。 モデルは空文字列、10キロバイトの巨大な文字列、制御文字を渡す可能性があります。そうしたものはすべて、外部のAPIではなく、server.py 内でネットワーク呼び出しの前に切り捨てられます。
Errorの種類に応じて区別されます。 4xx を再試行しても意味がありません。リクエスト側のエラーであり、再試行で修正されるものではないからです。5xx は一時的な障害が多いため、間隔を置いて 1 回だけ再試行します。この判断は _get_json にあり、呼び出し回数を検証するテストで確認されています。
外部には生のJSONではなくテキストが渡されます。 エージェントには補って解釈する余地がなく、言い換えて伝える際に誤る可能性もありません。必須フィールドがない200応答は、空の値を返す理由ではなく、障害として扱われます。
もう1点、範囲外の日数はエラーとして扱われるのではなく、境界値に丸められます。モデルが30日分の予報を求めてきた場合、エラーメッセージで対話を終わらせるよりは、7日分を返す方が有益です。
Related MCP server: open-meteo-mcp-server
ツール
ツール | 説明 |
| 現在の天気: 気温、体感温度、湿度、風 |
| 1〜7日間の予報(降水を含む) |
| 都市が存在するかを確認し、国を補足する |
locate はただ1つのシナリオのために存在します。エージェントが表記に確信が持てないときは、静かに別の都市の天気を返すよりも、ユーザーに確認する方が良い、というものです。
Инструкция インストール
pip install -e .Claude Desktop への接続
claude_desktop_config.json 内:
{
"mcpServers": {
"weather": {
"command": "mcp-weather"
}
}
}アプリを再起動すると、ツールが利用可能なリストに表示されます。
開発
pip install -e ".[dev]"
pytest
ruff check .テストでは、実際に壊れがちなケースをカバーしています: 空の入力、過大サイズの入力、数値以外の日数、再試行なしの4xx、1回だけ再試行される5xx、2回目の試行で成功、ペイロードがない200応答、未知の天気コードです。HTTP は respx でモックされているため、テストでネットワークは必要ありません。
構造
src/mcp_weather/
client.py — работа с Open-Meteo: типы, повторы, разбор ответа
server.py — MCP-слой: валидация входа и форматирование вывода
tests/
test_tools.pyネットワークコードは意図的にMCPレイヤーから分離されています。クライアント自体は単体でテストでき、エージェント用ツールは、明確な関数に対する薄いラッパーのままです。
ライセンス
MIT
Available Tools
3 toolscurrent_weatherB
Текущая погода в указанном городе.
Args: city: Название населённого пункта, например «Ижевск» или «Berlin».
Inputs: city (required). Returns: result
forecastA
Прогноз погоды на несколько дней вперёд.
Args: city: Название населённого пункта. days: Сколько дней показать, от 1 до 7. Значения вне диапазона приводятся к границе, а не считаются ошибкой.
Inputs: city (required), days. Returns: result
locateA
Проверяет, что населённый пункт существует, и уточняет страну.
Полезно, когда агент не уверен в написании: лучше уточнить у пользователя, чем молча выдать погоду не того города.
Inputs: query (required). Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 3 tools
Each tool has a clearly distinct purpose: current conditions, multi-day forecast, and location validation. There is no overlap or ambiguity between them, even though two tools accept a city argument.
Naming is readable but inconsistent: current_weather is a noun phrase, forecast is a bare noun, and locate is a verb. A more consistent pattern like get_current_weather, get_forecast, and validate_location would be clearer.
Three tools is well-scoped for a weather connector. Each tool covers a necessary function without unnecessary overlap or bloat.
The core weather workflows are covered: current conditions and multi-day forecasts, with optional location validation. Minor gaps exist, such as lacking unit selection or weather alerts, but these are not essential for most use cases.
Maintenance
Related MCP Connectors
Global weather via Open-Meteo: forecast, historical, marine, air quality, geocoding, elevation.
Current weather and forecast lookup as an agent tool.
US weather & geo for AI agents: forecasts, alerts, earthquakes, elevation, geocoding. No keys.
US weather & geo for AI agents: forecasts, alerts, earthquakes, elevation, geocoding. No keys.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to retrieve current weather, forecasts, and summaries for any global location using the Open-Meteo API, with no API key required.Creative Commons Zero v1.0 Universal
- AlicenseAqualityDmaintenanceProvides comprehensive access to Open-Meteo weather APIs, including forecasts, historical data, air quality, marine weather, and geocoding, enabling LLMs to retrieve weather information and location data.17MIT
- AlicenseNot gradedqualityDmaintenanceProvides live weather data (current conditions, forecasts) and city geocoding through Open-Meteo API, enabling AI assistants to answer weather queries without an API key.MIT
- AlicenseAqualityDmaintenanceProvides weather forecasts and geocoding lookup using free Open-Meteo APIs, enabling LLMs to query real-time weather and multi-day forecasts for any location.1ISC