Skip to main content
Glama
hafizrahman

Weather & WordPress MCP Server

by hafizrahman

get-alerts

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

Instructions

Get weather alerts for a state

Input Schema

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

Implementation Reference

  • The async handler function that fetches weather alerts from the NWS API for the specified state, formats them using formatAlert, and returns formatted text content.
    async ({ state }) => {
        const stateCode = state.toUpperCase();
        const alertsUrl = `${NWS_API_BASE}/alerts?area=${stateCode}`;
        const alertsData = await fetchJson<AlertsResponse>(alertsUrl, {
            Accept: "application/geo+json",
        });
    
        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);
        return {
            content: [{ type: "text", text: `Active alerts for ${stateCode}:\n\n${formattedAlerts.join("\n")}` }],
        };
    }
  • Input schema for the get-alerts tool, defining the 'state' parameter as a 2-letter string.
    {
        state: z.string().length(2).describe("Two-letter state code (e.g. CA, NY)"),
    },
  • src/index.ts:79-110 (registration)
    Registration of the 'get-alerts' tool using server.tool, including 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 fetchJson<AlertsResponse>(alertsUrl, {
                Accept: "application/geo+json",
            });
    
            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);
            return {
                content: [{ type: "text", text: `Active alerts for ${stateCode}:\n\n${formattedAlerts.join("\n")}` }],
            };
        }
    );
  • Helper function to format a single weather alert feature into a multi-line string.
    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");
    }
  • Shared helper function used to fetch and parse JSON from APIs, with error handling.
    async function fetchJson<T>(url: string, headers: Record<string, string> = {}): Promise<T | null> {
        try {
            const response = await fetch(url, { headers: { "User-Agent": USER_AGENT, ...headers } });
            if (!response.ok) throw new Error(`HTTP error ${response.status}`);
            return (await response.json()) as T;
        } catch (err) {
            console.error("Fetch error:", err);
            return null;
        }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't describe traits like whether it's read-only, requires authentication, has rate limits, returns structured data, or handles errors. For a tool with zero annotation coverage, this leaves significant gaps in understanding its operational 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 a single, efficient sentence with zero wasted words. It's front-loaded with the core purpose and appropriately sized for a simple tool with one parameter. Every word earns its place.

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 simplicity (one parameter, no output schema, no annotations), the description is minimally adequate. It covers the basic purpose but lacks behavioral context and usage guidelines. For a tool with no output schema, it doesn't describe return values, which would be helpful but isn't strictly required for a 3 score.

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?

Schema description coverage is 100%, with the single parameter 'state' fully documented in the schema (two-letter code format). The description adds no additional parameter semantics beyond implying the tool filters alerts by state. Baseline 3 is appropriate when the schema does the heavy lifting.

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 verb ('Get') and resource ('weather alerts for a state'), making the purpose immediately understandable. It doesn't explicitly distinguish from siblings like 'get-forecast' or 'get-latest-posts', but the domain (weather alerts) is specific enough to imply differentiation. A 5 would require explicit sibling comparison.

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 like 'get-forecast' or other sibling tools. It doesn't mention prerequisites, exclusions, or contextual triggers for selecting this specific tool. The agent must infer usage from the purpose alone.

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/hafizrahman/wp-mcp'

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