get_alerts
Fetch real-time weather alerts for a specific state using the Weather MCP Server, ensuring accurate and up-to-date safety notifications.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| state | Yes |
Implementation Reference
- tools/weather_tools.py:6-18 (handler)Handler function for the 'get_alerts' tool. It makes an API request to the National Weather Service for active alerts in the specified state, processes the response, and formats the alerts using helper functions.@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)
- tools/weather_tools.py:4-4 (registration)Initializes the FastMCP server instance named 'weather', which is used to register tools like get_alerts.mcp = FastMCP("weather")
- weather.py:4-4 (registration)Runs the MCP server (with imported mcp instance containing registered tools) using stdio transport.mcp.run(transport='stdio')
- utils/weather_utils.py:7-16 (helper)Helper function to make asynchronous HTTP requests to the NWS API, used by get_alerts.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, used by get_alerts.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')} """