Skip to main content
Glama
gifflet
by gifflet

get-alerts

Retrieve weather alerts for any US state using its two-letter code to monitor active warnings and advisories.

Instructions

Get weather alerts for a state

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stateYesTwo-letter state code (e.g. CA, NY)

Implementation Reference

  • Executes the get-alerts tool: fetches weather alerts from NWS API for a given state code, handles errors and empty results, formats alerts using helper functions, and returns formatted text content.
    async ({ state }) => {
        const stateCode = state.toUpperCase();
        const alertsUrl = `${NWS_API_BASE}/alerts?area=${stateCode}`;
        const alertsData = await makeNWSRequest<AlertsResponse>(alertsUrl);
    
        if (!alertsData) {
            return {
                content: [
                    {
                        type: "text",
                        text: "Failed to retrieve alerts data",
                    },
                ],
            };
        }
    
        const features = alertsData.features || [];
        if (features.length === 0) {
            return {
                content: [
                    {
                        type: "text",
                        text: `No active alerts for ${stateCode}`,
                    },
                ],
            };
        }
    
        const formattedAlerts = features.map(formatAlert);
        const alertsText = `Active alerts for ${stateCode}:\n\n${formattedAlerts.join("\n")}`;
    
        return {
            content: [
                {
                    type: "text",
                    text: alertsText,
                },
            ],
        };
    },
  • src/index.ts:27-73 (registration)
    Registers the 'get-alerts' tool with the MCP server, specifying name, description, input schema, and handler function.
    server.tool(
        "get-alerts",
        "Get weather alerts for a state",
        {
            state: z.string().length(2).describe("Two-letter state code (e.g. CA, NY)"),
        },
        async ({ state }) => {
            const stateCode = state.toUpperCase();
            const alertsUrl = `${NWS_API_BASE}/alerts?area=${stateCode}`;
            const alertsData = await makeNWSRequest<AlertsResponse>(alertsUrl);
    
            if (!alertsData) {
                return {
                    content: [
                        {
                            type: "text",
                            text: "Failed to retrieve alerts data",
                        },
                    ],
                };
            }
    
            const features = alertsData.features || [];
            if (features.length === 0) {
                return {
                    content: [
                        {
                            type: "text",
                            text: `No active alerts for ${stateCode}`,
                        },
                    ],
                };
            }
    
            const formattedAlerts = features.map(formatAlert);
            const alertsText = `Active alerts for ${stateCode}:\n\n${formattedAlerts.join("\n")}`;
    
            return {
                content: [
                    {
                        type: "text",
                        text: alertsText,
                    },
                ],
            };
        },
    );
  • Zod schema for input validation: requires a 2-letter state code.
    {
        state: z.string().length(2).describe("Two-letter state code (e.g. CA, NY)"),
    },
  • Helper function to format an individual alert feature into a multi-line string summary.
    export function formatAlert(feature: AlertFeature): string {
        const props = feature.properties;
        return [
            `Event: ${props.event || "Unknown"}`,
            `Area: ${props.areaDesc || "Unknown"}`,
            `Severity: ${props.severity || "Unknown"}`,
            `Status: ${props.status || "Unknown"}`,
            `Headline: ${props.headline || "No headline"}`,
            "---",
        ].join("\n");
    }
  • Generic helper for making authenticated fetch requests to NWS API endpoints.
    export async function makeNWSRequest<T>(url: string): Promise<T | null> {
        const USER_AGENT = "weather-app/1.0";
        const headers = {
            "User-Agent": USER_AGENT,
            Accept: "application/geo+json",
        };
    
        try {
            const response = await fetch(url, { headers });
            if (!response.ok) {
                throw new Error(`HTTP error! status: ${response.status}`);
            }
            return (await response.json()) as T;
        } catch (error) {
            console.error("Error making NWS request:", error);
            return null;
        }
    }
  • TypeScript interface defining the structure of the NWS alerts API response.
    export interface AlertsResponse {
        features: AlertFeature[];
    }
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 states what the tool does but doesn't describe how it behaves—such as whether it returns active alerts only, historical data, error handling, or rate limits. This leaves significant gaps for a tool that might involve external data fetching.

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 a single, efficient sentence that directly states the tool's purpose without any wasted words. It's front-loaded and appropriately sized for a simple tool, earning full marks for conciseness.

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, no output schema, no annotations), the description is minimally adequate. However, it lacks details on what the output contains (e.g., alert types, severity) and behavioral context, making it incomplete for fully informed use without additional assumptions.

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

Parameters3/5

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

The input schema has 100% description coverage, fully documenting the single 'state' parameter. The description adds no additional meaning beyond what the schema provides, such as examples of state codes or context about alert types. Baseline 3 is appropriate when the schema does all the work.

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 action ('Get') and resource ('weather alerts for a state'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from the sibling tool 'get-forecast', which likely provides different weather data, so it doesn't reach the highest score.

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 the sibling 'get-forecast' or any alternatives. It lacks context about when alerts are relevant (e.g., severe weather) or any prerequisites, leaving usage entirely implicit.

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/gifflet/weather-mcp'

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