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"); }
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