Skip to main content
Glama

get_alerts

Retrieve weather alerts for specific US states by providing a two-letter state code. This tool helps users stay informed about critical weather updates directly through the Weather MCP Server.

Instructions

Get weather alerts for US state Args: state: Two letter US state code (e.g CA, NY etc)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stateYes

Implementation Reference

  • The handler function decorated with @mcp.tool() that implements the get_alerts tool logic: fetches active weather alerts for a US state from NWS API, formats them, and returns as string.
    @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)
  • Helper function to format individual alert features into readable text.
    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")} """
  • Helper function to make HTTP requests to the NWS API with headers 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
  • Alternative implementation of the get_alerts handler in the stdio server version.
    @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)

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/suryanshp1/mcpcrashcourse'

If you have feedback or need assistance with the MCP directory API, please join our Discord server