weather-alert-mcp-v2
weather-alert-mcp v2 — 1つのMCPツール、2つの実装
米国国立気象局のリアルタイムの気象警報を呼び出し可能なツールとして公開するMCP(Model Context Protocol)サーバー。Claude Desktop、Claude Code、SDKクライアントなど、あらゆるMCPクライアントが州別にアクティブな気象警報を照会できます。
2回実装されています。1回はPython、もう1回はTypeScriptで、同じツール契約に基づいています。クライアントはどちらと通信しているかを区別できません。これがAPIではなくプロトコルに基づいて構築する意味であり、この2つの実装こそがMCPの興味深い部分です。
v1(Pythonのみ)はweather-alert-mcpにあり、変更されていません。このリポジトリはその続きです。
ツール
ツール | 引数 | 戻り値 |
|
| 最大5件のアクティブな警報:イベント、深刻度、影響地域、見出し |
データソース:https://api.weather.gov/alerts/active — 公開、APIキー不要、サインアップ不要。
Related MCP server: Weather MCP Server
同じ契約、2つの方法で導出
Python( | TypeScript( | |
スキーマソース | 型ヒントから生成 |
|
引数検証 | クライアントのスキーマ準拠を信頼 | 境界で検証し、HTTP呼び出しの前に拒否 |
トランスポート | stdio | stdio |
オフラインモード |
|
|
ツール契約 |
|
|
どちらも、クライアントが見るJSONスキーマを別途保守するのではなく、実装から導出するため、契約がコードから乖離することはありません。
TypeScriptサーバーはさらに、プロトコル境界で検証します。{"state": "Illinois"}はネットワークリクエストが行われる前にプロトコルレベルのエラーとして返されるため、不正なツール呼び出しはコストがかかりません:
MCP error -32602: Input validation error: Invalid arguments for tool get_alertsPython
pip install -r requirements.txt
python server.py # speaks MCP over stdio; a client launches this検証 — test_client.pyは実際のMCPクライアントです。サーバーをサブプロセスとして起動し、initializeハンドシェイクを完了し、アドバタイズされたツールを一覧表示し、1つを呼び出します。
python test_client.py # live
WX_MOCK=1 python test_client.py # protocol only, no networkTOOLS: ['get_alerts']
DESC: Get active National Weather Service alerts for a US state.
SCHEMA: {'properties': {'state': {'title': 'State', 'type': 'string'}}, 'required': ['state'], ...}
RESULT for IL:
Severe Thunderstorm Warning (Severe) — Lake County, IL
Severe Thunderstorm Warning issued for Lake County until 7:15 PM CDTTypeScript
cd ts
npm install
npm run build
node build/index.js # speaks MCP over stdio検証 — ts/test-client.mjsは同じラウンドトリップを実行し、さらに不正な引数が拒否されることを検証します:
cd ts
WX_MOCK=1 node test-client.mjs # protocol only, no network
node test-client.mjs TX # live NWS dataTOOLS: [ 'get_alerts' ]
SCHEMA: {"type":"object","properties":{"state":{"type":"string","minLength":2,"maxLength":2,
"pattern":"^[A-Za-z]{2}$","description":"Two-letter US state code, e.g. \"IL\" or \"CA\""}},
"required":["state"],"additionalProperties":false}
RESULT:
Severe Thunderstorm Warning (Severe) — Lake County, IL
Severe Thunderstorm Warning issued for Lake County until 7:15 PM CDT
VALIDATION: rejected bad input as expected — MCP error -32602: Input validation errorTypeScript実装の詳細はts/README.mdを参照してください。
Claude Desktopから使用する
claude_desktop_config.jsonにいずれか(または両方)を追加します:
{
"mcpServers": {
"weather-alerts": {
"command": "python",
"args": ["/absolute/path/to/server.py"]
},
"weather-alerts-ts": {
"command": "node",
"args": ["/absolute/path/to/ts/build/index.js"]
}
}
}どちらも同じツール名を登録するため、比較しない限りは一度に1つずつ実行してください。
メモ
stdoutはプロトコルチャネルです。 ここに何かを書き込むとJSON-RPCストリームが破損するため、起動ログはstderrに出力されます。エラーは握りつぶさずに表面化されます。 上流のAPI障害は「警報なし」を返すのではなくクライアントに通知されます。「警報なし」は実際に静かな状態と区別がつかないためです。
WX_MOCK=1はネットワーク呼び出しなしで完全なパスを実行します — CIで役立ち、問題発生時にプロトコル障害と上流API障害を切り分けるのに役立ちます。警報は最初の5フィーチャーに切り詰められ、ツール出力が妥当なコンテキスト予算内に収まるようにしています。
既知の制限事項
読み取り専用ツールが1つ。リソース、プロンプト、サンプリングはありません。ツール登録以外のMCPの部分はここでは使用されていません。
stdioトランスポートのみ。HTTP/SSEトランスポートはありません。
NWSエンドポイントは
User-Agentを必要とします。APIの規定ポリシーに従い、両実装で連絡先文字列に設定されています。
This server cannot be deployed
Maintenance
Related MCP Connectors
US weather for AI agents: active NWS alerts by state, 5-period forecasts by lat/lon. Paid per call.
Hosted MCP server for Xweather weather data: conditions, forecasts, alerts, and more.
US weather alerts (NWS): warnings, watches. $0.01/query. Register in-session — free testnet funds.
Get US weather forecasts, active alerts, and current observations.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceThis is a Model Context Protocol (MCP) server that provides weather information using the National Weather Service (NWS) API. Features Get weather alerts for a US state Get weather forecast for a specific location (using latitude and longitude)-
- AlicenseNot gradedqualityDmaintenanceProvides weather forecasts and active alerts for US locations using the National Weather Service API. It supports both local stdio and remote HTTP/SSE transport modes for flexible integration with MCP clients.159 npmGPL 3.0
- FlicenseBqualityDmaintenanceProvides weather forecasts and alerts for US locations using the National Weather Service API. Enables users to retrieve active alerts by state and detailed forecasts by coordinates via MCP tools.2-
- FlicenseNot gradedqualityDmaintenanceReal-time US weather data via MCP tools: fetch weather alerts by state and forecasts by coordinates using the NOAA NWS API.-