get_alerts
Retrieve weather alerts for any US state with ease. Integrate into automated workflows or AI systems to monitor and respond to severe weather updates in real-time.
Instructions
Get weather alerts for a US state.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| state | Yes |
Implementation Reference
- src/claude_tools/weather.py:33-42 (handler)The main handler function for the 'get_alerts' tool. Fetches active weather alerts for a given US state using the National Weather Service (NWS) API, formats them, and returns a string summary.async def get_alerts(state: str) -> str: """Get weather alerts for a US state.""" 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)
- src/claude_tools/weather.py:71-74 (registration)The registration function for weather tools, including applying the mcp.tool() decorator to get_alerts.def register_weather_tools(mcp): """Register all weather tools with the MCP server.""" mcp.tool()(get_alerts) mcp.tool()(get_forecast)
- src/claude_tools/main.py:20-20 (registration)Invocation of the register_weather_tools function during MCP server initialization, which registers the get_alerts tool.register_weather_tools(mcp)
- src/claude_tools/weather.py:22-31 (helper)Helper function used by get_alerts to format individual alert data into a 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 instructions provided')} """
- src/claude_tools/weather.py:8-20 (helper)Helper function used by get_alerts to make HTTP requests to the NWS API with 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: return None