get_alerts
Retrieve active weather alerts for a specific state from the National Weather Service to monitor severe conditions and stay informed about potential hazards.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| state | Yes |
Implementation Reference
- tools/weather_tools.py:6-18 (handler)The core handler function for the 'get_alerts' tool. It fetches active weather alerts for a specified state using the National Weather Service (NWS) API, formats them, and returns a string summary.@mcp.tool() async def get_alerts(state: str) -> str: 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 not 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)
- utils/weather_utils.py:7-16 (helper)Helper utility to perform asynchronous HTTP requests to the NWS API, handling errors and returning JSON data or None.async def make_nws_request(url: str) -> dict[str, Any] | None: 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
- utils/weather_utils.py:17-25 (helper)Helper function to format a single weather alert feature into a human-readable string.def format_alert(feature: dict) -> str: props = feature["properties"] return f""" Event: {props.get('event', 'Unknown')} Area: {props.get('areaDesc', 'Unknown')} Severity: {props.get('severity', 'Unknown')} Descripton: {props.get('description', 'No description')} Instructions: {props.get('instruction', 'No specific instruction')} """
- tools/weather_tools.py:4-6 (registration)The FastMCP instance is created and the tool is registered via the @mcp.tool() decorator.mcp = FastMCP("weather") @mcp.tool()