get_alerts
Retrieve weather alerts for any US state by providing its two-letter code. This tool helps users stay informed about active weather warnings and advisories.
Instructions
Get weather alerts for a US state.
Args: state: Two-letter US state code (e.g. CA, NY)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| state | Yes |
Implementation Reference
- server/weather.py:38-55 (handler)The main handler function for the 'get_alerts' tool. It is decorated with @mcp.tool() for registration and implements the logic to fetch active weather alerts for a given US state using the National Weather Service API, formatting and returning the results.@mcp.tool() async def get_alerts(state: str) -> str: """Get weather alerts for a US state. Args: state: Two-letter US state code (e.g. CA, NY) """ url = f"{NWS_API_BASE}/alerts/active/area/{state}" data = await make_nws_request(url) if not data or "features" not in data: return "Unable to fetch alerts or no alerts found." if not data["features"]: return "No active alerts for this state." alerts = [format_alert(feature) for feature in data["features"]] return "\n---\n".join(alerts)