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
| Name | Required | Description | Default |
|---|---|---|---|
| state | Yes | Two-letter state code (e.g. CA, NY) |
Implementation Reference
- src/tools/get-alerts.ts:17-56 (handler)The handler function that implements the core logic of the 'get-alerts' tool: fetches weather alerts from NWS API for a given state, handles errors and empty results, formats alerts, and returns a markdown text response.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/tools/get-alerts.ts:13-15 (schema)Zod input schema defining the 'state' parameter as a 2-character string.inputSchema: z.object({ state: z.string().length(2).describe('Two-letter state code (e.g. CA, NY)'), }),
- src/tools/get-alerts.ts:8-57 (registration)The server.registerTool call that registers the 'get-alerts' tool with its name, metadata, schema, and handler function.server.registerTool( 'get-alerts', { title: 'Weather alerts', description: 'Get weather alerts for a state', inputSchema: z.object({ 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, }, ], } }, )
- src/index.ts:9-9 (registration)Invocation of registerGetAlerts() to perform the tool registration when the server starts.registerGetAlerts()