weather-alert-mcp-v2
weather-alert-mcp v2 — 一个 MCP 工具,两种实现
一个 MCP(模型上下文协议)服务器,将美国国家气象局的实时警报暴露为可调用工具,因此任何 MCP 客户端——Claude Desktop、Claude Code 或 SDK 客户端——都可以按州查询当前生效的天气警报。
实现两次:一次用 Python,一次用 TypeScript,遵循相同的工具契约。客户端无法分辨它正在与哪一个通信。这正是基于协议而非 API 进行构建的意义所在,而这两种实现正是 MCP 的有趣之处变得可见的地方。
v1(仅 Python)位于 weather-alert-mcp,保持 原样不动。本仓库是其延续。
工具
工具 | 参数 | 返回 |
|
| 最多 5 条当前警报:事件、严重程度、影响区域、标题 |
数据源:https://api.weather.gov/alerts/active — 公开,无需 API 密钥,无需注册。
同一契约,两种派生方式
Python ( | TypeScript ( | |
Schema 来源 | 从类型提示生成 | 从 |
参数验证 | 信任客户端对 schema 的符合性 | 在边界处验证,在任何 HTTP 调用之前拒绝 |
传输 | stdio | stdio |
离线模式 |
|
|
工具契约 |
|
|
两者都从实现中派生客户端所看到的 JSON Schema,而不是单独维护它,因此契约不会与代码发生漂移。
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 握手,列出所通告的工具,并调用其中一个。
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 error有关 TypeScript 实现的详细信息,请参阅 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"]
}
}
}两者注册相同的工具名称,因此一次运行一个,除非你想对它们进行比较。
备注
stdout是协议通道。 任何写入那里的内容都会破坏 JSON-RPC 流,这就是启动日志输出到stderr的原因。错误会浮出水面,而不是被吞掉。 上游 API 故障会抛给客户端,而不是返回“无警报”,因为“无警报”与真正平静的状态无法区分。
WX_MOCK=1在没有网络调用的情况下运行完整路径 — 在 CI 中很有用,也用于在出现问题时将协议故障与上游 API 故障区分开来。警报被截断为前 5 个要素,以将工具输出保持在合理的上下文预算之内。
已知限制
只有一个只读工具。没有资源、没有提示、没有采样——MCP 中除工具注册之外的部分未在此处涉及。
仅支持 stdio 传输;不支持 HTTP/SSE 传输。
NWS 端点要求提供
User-Agent;根据 API 的既定政策,两种实现都将其设置为联系字符串。
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Get US weather forecasts, active alerts, and current observations.
US weather, alerts, earthquakes and elevation for AI agents, from NWS/NOAA and USGS. No API keys.
US weather & geo for AI agents: forecasts, alerts, earthquakes, elevation, geocoding. No keys.
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
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/rainygold25/weather-alert-mcp-v2'
If you have feedback or need assistance with the MCP directory API, please join our Discord server