Skip to main content
Glama
sun873087

MCP Weather Sample

by sun873087

get_alerts

Retrieve weather alerts for a specific U.S. state by providing its two-letter abbreviation to access current warnings and advisories.

Instructions

獲取美國特定州份的警報資料.

Args:
    state (str): 美國州份的縮寫 (e.g., "CA", "TX", "NY")
    
Returns:
    str: 警報資料的文字描述

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stateYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • get_alerts handler for stdio transport - fetches weather alerts from NOAA API for a given US state code. Uses @mcp.tool() decorator for registration.
    @mcp.tool()
    async def get_alerts(state: str) -> str:
        """
        獲取美國特定州份的警報資料.
    
        Args:
            state (str): 美國州份的縮寫 (e.g., "CA", "TX", "NY")
            
        Returns:
            str: 警報資料的文字描述
        """
        url = f"{NWS_API_BASE_URL}/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 found for the given state."
        
        alerts = [format_alert(feature) for feature in data["features"]]
        return "\n\n".join(alerts)
  • get_alerts handler for streamable-http transport - similar logic with added Context parameter for logging via ctx.info(). Uses @mcp.tool() decorator.
    @mcp.tool()
    async def get_alerts(state: str, ctx: Context) -> str:
        """Get weather alerts for a US state.
    
        Args:
            state: Two-letter US state code (e.g. CA, NY)
        """
        await ctx.info(f"Fetching alerts for state: {state}")
        url = f"{NWS_API_BASE}/alerts/active/area/{state}"
        data = await make_nws_request(url)
    
        await ctx.info(f"Received data: {data}")
    
        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)
  • get_alerts handler for SSE transport - identical to streamable-http version with Context parameter for logging. Uses @mcp.tool() decorator.
    @mcp.tool()
    async def get_alerts(state: str, ctx: Context) -> str:
        """Get weather alerts for a US state.
    
        Args:
            state: Two-letter US state code (e.g. CA, NY)
        """
        await ctx.info(f"Fetching alerts for state: {state}")
        url = f"{NWS_API_BASE}/alerts/active/area/{state}"
        data = await make_nws_request(url)
    
        await ctx.info(f"Received data: {data}")
    
        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)
  • Helper function make_nws_request - handles HTTP requests to NOAA API with proper headers and error handling.
    async def make_nws_request(url: str) -> dict[str, Any] | None:
        """
        發送 HTTP 請求到 NOAA 天氣 API 並返回 JSON 響應
        """
        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:
                print(f"HTTP error occurred: {e}")
                return None
  • Helper function format_alert - formats individual alert feature into readable string with event, area, severity, description, and instructions.
    def format_alert(feature: dict) -> str:
        """
        格式化 NOAA 警報資料
        """
        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")}
    """
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions what the tool does but doesn't describe important behavioral aspects: whether this is a read-only operation, what permissions might be needed, rate limits, error conditions, or what happens with invalid state codes. For a tool with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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

Conciseness4/5

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

The description is appropriately concise with three clear sections: purpose statement, Args section with parameter details, and Returns section. Each sentence earns its place by providing essential information. The structure is logical and front-loaded with the main purpose. Minor improvement could be made by integrating the parameter details more seamlessly.

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 has 1 parameter with 0% schema coverage but an output schema exists (returns string), the description provides adequate basic context. It covers the purpose and parameter semantics reasonably well. However, for a tool with no annotations, it should ideally include more behavioral context about what happens with invalid inputs, authentication needs, or rate limits to be fully complete.

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 beyond the input schema, which has 0% description coverage. It specifies that the 'state' parameter should be a US state abbreviation and provides examples ('CA', 'TX', 'NY'). This clarifies the expected format and valid values, compensating well for the schema's lack of descriptions. However, it doesn't mention whether all 50 states are supported or if there are restrictions.

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 '獲取美國特定州份的警報資料' (Get alert data for specific US states), which is a specific verb+resource combination. It distinguishes from the sibling tool 'get_forecast' by focusing on alerts rather than weather forecasts. However, it doesn't explicitly mention what type of alerts (weather, emergency, etc.), keeping it from a perfect score.

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

Usage Guidelines3/5

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

The description implies usage context by specifying '美國特定州份' (specific US states), suggesting it should be used for US state alerts. However, it provides no explicit guidance on when to use this versus the 'get_forecast' sibling tool, nor does it mention any prerequisites or exclusions. The usage is implied but not clearly articulated.

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/sun873087/mcp-sample'

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