Skip to main content
Glama
SandroSD

MCP Weather Server

by SandroSD

get_alerts

Retrieve current weather alerts for any US state by providing the two-letter state code to monitor severe conditions and stay informed.

Instructions

Get weather alerts for a state

Input Schema

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

Implementation Reference

  • The handler function for the 'get_alerts' tool. Fetches active weather alerts from the National Weather Service API for a specified US state, handles errors and empty results, formats the alerts using formatAlert helper, and returns a formatted text response.
    async ({ state }) => {
      const stateCode = state.toUpperCase();
      const alertsUrl = `${CONFIG.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,
          },
        ],
      };
    },
  • Input schema for the 'get_alerts' tool using Zod: requires a 2-character string for the US state code.
    {
      state: z
        .string()
        .length(2)
        .describe("Two-letter state code (e.g. CA, NY)"),
    },
  • Tool registration function that defines and registers the 'get_alerts' tool on an MCP server instance, including name, description, input schema, and handler.
    export const getAlertsTool = (server: McpServer) =>
      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 = `${CONFIG.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,
              },
            ],
          };
        },
      );
  • Invokes the getAlertsTool function to register the 'get_alerts' tool on the main MCP server.
    getAlertsTool(server);
  • Helper function used by the get_alerts handler to format individual alert features into a readable string.
    // Format alert data
    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");
    }
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 mentions 'get' which implies a read operation, but doesn't specify whether this requires authentication, has rate limits, returns real-time or historical data, or what format the alerts come in. For a tool with zero annotation coverage, this leaves significant behavioral gaps.

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 communicates the core functionality without unnecessary words. It's appropriately sized for a simple tool with one parameter and gets straight to the point.

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?

For a simple read operation with one well-documented parameter and no output schema, the description is minimally adequate. However, the lack of annotations means the description should do more to explain behavioral aspects, and the absence of sibling differentiation is a notable gap given the related 'get_forecast' tool exists.

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 schema has 100% description coverage, with the single parameter 'state' clearly documented as a two-letter code. The description adds no additional parameter information beyond what the schema provides, so it meets the baseline for high schema coverage but doesn't enhance parameter understanding.

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') with a specific scope ('for a state'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from its sibling tool 'get_forecast', which appears to be related but serves a different function (forecasts vs alerts).

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 its sibling 'get_forecast', nor does it mention any prerequisites, limitations, or alternative scenarios. It simply states what the tool does without contextual usage information.

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/SandroSD/MCP'

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