Skip to main content
Glama

get_alerts

Retrieve weather alerts for any US state using two-letter state codes to monitor hazardous conditions and stay informed about local warnings.

Instructions

Get weather alerts for a US state.

Args:
    state: Two-letter US state code (e.g. CA, NY, TX)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stateYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function for the 'get_alerts' tool. It validates the US state code, fetches active weather alerts from the National Weather Service API, formats them using helper functions, and returns a formatted string response.
    @mcp.tool()
    async def get_alerts(state: str) -> str:
        """Get weather alerts for a US state.
    
        Args:
            state: Two-letter US state code (e.g. CA, NY, TX)
        """
        state = state.upper().strip()
        
        if not validate_state_code(state):
            return f"Error: '{state}' is not a valid US state code. Please use a 2-letter code (e.g., CA, NY, TX)."
        
        url = f"{NWS_API_BASE}/alerts/active/area/{state}"
        data = await make_nws_request(url)
    
        if not data or "features" not in data:
            return f"Unable to fetch alerts for {state}. The location may not be supported or the service is unavailable."
    
        if not data["features"]:
            return f"No active weather alerts for {state}."
    
        alerts = [format_alert(feature) for feature in data["features"]]
        return f"Weather Alerts for {state}:\n\n" + "\n---\n".join(alerts)
  • Helper function to format individual weather alert data into a human-readable string format.
    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')}
    """
  • Helper function to validate if the provided state code is a valid two-letter US state abbreviation. Relies on the US_STATES constant.
    def validate_state_code(state: str) -> bool:
        """Validate that the state code is a valid 2-letter US state code."""
        return state.upper() in US_STATES
  • Helper function to make HTTP requests to the National Weather Service API with proper headers, timeout, and comprehensive 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 httpx.HTTPStatusError as e:
                if e.response.status_code == 404:
                    return None
                return None
            except (httpx.RequestError, httpx.TimeoutException):
                return None
            except Exception:
                return None
  • weather.py:105-105 (registration)
    The @mcp.tool() decorator registers the get_alerts function as an MCP tool in the FastMCP server.
    @mcp.tool()
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves weather alerts but doesn't cover critical aspects like whether it's a read-only operation, potential rate limits, authentication needs, or what happens if the state code is invalid. This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded with the core purpose in the first sentence, followed by a concise parameter explanation. Every sentence earns its place by providing essential information without redundancy, making it efficient and well-structured for quick comprehension.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's low complexity (one parameter) and the presence of an output schema (which handles return values), the description is somewhat complete but lacks depth. It covers the basic purpose and parameter semantics but misses behavioral details and usage guidelines, which are important for a tool with no annotations to guide the agent effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds meaningful context for the single parameter 'state' by specifying it as a 'Two-letter US state code' with examples (e.g., CA, NY, TX), which compensates for the 0% schema description coverage. This clarifies the parameter's format and expected values beyond what the bare schema provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with a specific verb ('Get') and resource ('weather alerts for a US state'), making it immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'get_current_conditions' or 'get_forecast', which might also provide weather-related data but for different aspects.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'compare_weather' or 'get_forecast', nor does it specify scenarios where weather alerts are preferred over other weather data, leaving the agent to infer usage context without explicit direction.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/zayedansari2/MCP_WeatherServer'

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