get_alerts
Retrieve weather alerts for any US state by providing its two-letter code to monitor hazardous conditions and stay informed about local weather warnings.
Instructions
Get weather alerts for US state Args: state: Two letter US state code (e.g CA, NY etc)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| state | Yes |
Implementation Reference
- mcpserver/server.py:40-57 (handler)The primary handler function for the 'get_alerts' tool. It fetches active weather alerts for a given US state using the National Weather Service API and formats them for output. Registered via @mcp.tool() decorator.@mcp.tool() async def get_alerts(state: str) -> str: """Get weather alerts for US state Args: state: Two letter US state code (e.g CA, NY etc) """ 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.get("features"): return "No active alerts for this state" alerts = [format_alert(feature) for feature in data.get("features")] return "\n--------------\n".join(alerts)
- mcpserver/server.py:15-27 (helper)Helper function that makes HTTP requests to the NWS API with proper headers, timeout, and error handling.async def make_nws_request(url: str) -> dict[str, Any] | None: """Make a request to the NWS API with proper error handling""" headers = { "User-Agent": USER_AGENT, "Accept": "application/geo+json" } async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, timeout=30.0) response.raise_for_status() return response.json() except Exception as e: return None
- mcpserver/server.py:29-38 (helper)Helper function that formats a single weather alert feature into a human-readable string.def format_alert(feature: dict) -> str: """Format an alert feature into a readable string""" props = feature["properties"] return f""" Event: {props.get("event", "Unknown")} Area: {props.get("areaDesc", "Unknown")} Severity: {props.get("severity", "Unknown")} Description: {props.get("description", "No description available")} Instructions: {props.get("instruction", "No specific instrucy+tion provided")} """
- server/weather.py:38-55 (handler)Duplicate handler function for the 'get_alerts' tool, identical implementation as in mcpserver/server.py, likely for stdio transport usage.@mcp.tool() async def get_alerts(state: str) -> str: """Get weather alerts for US state Args: state: Two letter US state code (e.g CA, NY etc) """ 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.get("features"): return "No active alerts for this state" alerts = [format_alert(feature) for feature in data.get("features")] return "\n--------------\n".join(alerts)
- mcpserver/server.py:42-45 (schema)Input schema defined in the tool's docstring, specifying the 'state' parameter as a two-letter US state code."""Get weather alerts for US state Args: state: Two letter US state code (e.g CA, NY etc) """