getWeatherAlerts
Retrieve active weather alerts for US states to monitor severe conditions and plan accordingly.
Instructions
Get active weather alerts for a US state
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/plugins/weatherPlugin.ts:51-68 (handler)The core handler function for the getWeatherAlerts tool. Validates the state input using WeatherAlertsSchema, fetches simulated alerts, and returns formatted text response.async (args: { [x: string]: any }) => { const { state }: WeatherAlertsArgs = validateToolArgs( WeatherAlertsSchema, args ); // Simulate alerts API call (replace with actual API) const alerts = await simulateAlertsAPI(); return { content: [ { type: 'text', text: `Weather alerts for ${state}:\n${alerts}`, }, ], }; }
- src/plugins/weatherPlugin.ts:45-69 (registration)Registration of the getWeatherAlerts MCP tool using server.registerTool, including metadata and handler reference.server.registerTool( 'getWeatherAlerts', { title: 'Get Weather Alerts', description: 'Get active weather alerts for a US state', }, async (args: { [x: string]: any }) => { const { state }: WeatherAlertsArgs = validateToolArgs( WeatherAlertsSchema, args ); // Simulate alerts API call (replace with actual API) const alerts = await simulateAlertsAPI(); return { content: [ { type: 'text', text: `Weather alerts for ${state}:\n${alerts}`, }, ], }; } );
- src/schemas/toolSchemas.ts:52-54 (schema)Zod schema defining the input structure for getWeatherAlerts: requires a 'state' field validated by StateSchema.export const WeatherAlertsSchema = z.object({ state: StateSchema, });
- src/plugins/weatherPlugin.ts:102-127 (helper)Supporting function that simulates a weather alerts API call, generating mock active alerts or no alerts message.async function simulateAlertsAPI(): Promise<string> { // Simulate API delay await new Promise(resolve => setTimeout(resolve, 100)); // Generate mock alerts based on state const alerts = [ 'Severe Thunderstorm Warning', 'Flash Flood Watch', 'Heat Advisory', 'Winter Weather Advisory', ]; const hasAlerts = Math.random() > 0.5; if (!hasAlerts) { return '✅ No active weather alerts for this state.'; } const activeAlerts = alerts.filter(() => Math.random() > 0.7).slice(0, 2); if (activeAlerts.length === 0) { return '✅ No active weather alerts for this state.'; } return activeAlerts.map(alert => `⚠️ ${alert}`).join('\n'); }
- src/schemas/commonSchemas.ts:39-43 (schema)Reusable StateSchema Zod validator used in WeatherAlertsSchema for two-letter uppercase US state codes.export const StateSchema = z .string() .length(2, 'State code must be exactly 2 characters') .regex(/^[A-Z]{2}$/, 'State code must be 2 uppercase letters') .describe('Two-letter US state code (e.g., CA, NY, TX)');