get_weather_alerts
Retrieve active weather alerts, road condition warnings, and incidents for British Columbia highways. Filter by region, alert type, or severity to monitor winter conditions, avalanche warnings, fog advisories, and weather-related incidents.
Instructions
Get active weather alerts, incidents, and road condition warnings across BC. Includes winter conditions, avalanche warnings, fog advisories, and weather-related incidents.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | No | Filter by BC region (optional) | |
| alertType | No | Type of alert to retrieve (default: all weather-related) | |
| severityMinimum | No | Minimum severity level (default: MINOR) |
Implementation Reference
- src/tools/weather-alerts.ts:56-120 (handler)The main handler function that fetches weather events using getEvents, filters by region, type, severity, and weather-related keywords, sorts by severity, and formats the output.export async function handleWeatherAlerts(args: { region?: string; alertType?: EventType; severityMinimum?: 'MINOR' | 'MODERATE' | 'MAJOR'; }): Promise<string> { try { const params: EventQueryParams = { status: 'ACTIVE', }; if (args.region) { const regionId = findRegionId(args.region); if (!regionId) { return `Invalid region "${args.region}". Please use a valid BC region name.`; } params.area_id = regionId; } if (args.alertType) { params.event_type = args.alertType; } const events = await getEvents(params); let filteredEvents = events; if (!args.alertType) { filteredEvents = events.filter(isWeatherRelated); } const severityOrder = { MAJOR: 0, MODERATE: 1, MINOR: 2, UNKNOWN: 3 }; const minimumSeverity = args.severityMinimum ?? 'MINOR'; const minLevel = severityOrder[minimumSeverity]; filteredEvents = filteredEvents.filter( event => severityOrder[event.severity] <= minLevel ); const sortedEvents = filteredEvents.sort( (a, b) => severityOrder[a.severity] - severityOrder[b.severity] ); if (sortedEvents.length === 0) { const filters = []; if (args.region) filters.push(`region: ${args.region}`); if (args.alertType) filters.push(`type: ${args.alertType}`); const filterStr = filters.length > 0 ? ` (${filters.join(', ')})` : ''; return `No weather alerts found${filterStr}.`; } const lines: string[] = []; lines.push(`Found ${sortedEvents.length} weather alert(s):\n`); sortedEvents.forEach((event, index) => { lines.push(`${index + 1}. ${formatWeatherAlert(event)}`); lines.push(''); }); return lines.join('\n'); } catch (error) { if (error instanceof Error) { return `Error fetching weather alerts: ${error.message}`; } return 'Error fetching weather alerts: Unknown error'; } }
- src/tools/weather-alerts.ts:6-29 (schema)The tool definition including name, description, and input schema for validation.export const weatherAlertsTool = { name: 'get_weather_alerts', description: 'Get active weather alerts, incidents, and road condition warnings across BC. Includes winter conditions, avalanche warnings, fog advisories, and weather-related incidents.', inputSchema: { type: 'object' as const, properties: { region: { type: 'string', description: 'Filter by BC region (optional)', }, alertType: { type: 'string', enum: ['WEATHER_CONDITION', 'ROAD_CONDITION', 'INCIDENT'], description: 'Type of alert to retrieve (default: all weather-related)', }, severityMinimum: { type: 'string', enum: ['MINOR', 'MODERATE', 'MAJOR'], description: 'Minimum severity level (default: MINOR)', }, }, required: [], }, };
- src/index.ts:39-48 (registration)Registration of the tool in the ListToolsRequest handler, making it discoverable.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ highwayConditionsTool, regionalConditionsTool, roadClosuresTool, weatherAlertsTool, ], }; });
- src/index.ts:69-72 (registration)Dispatch registration in the CallToolRequest switch statement, invoking the handler.case 'get_weather_alerts': result = await handleWeatherAlerts(args as any); break;
- src/tools/weather-alerts.ts:31-54 (helper)Helper function to filter events that are weather-related by type or keywords.function isWeatherRelated(event: Event): boolean { const weatherKeywords = [ 'weather', 'snow', 'ice', 'avalanche', 'fog', 'rain', 'wind', 'storm', 'winter', 'slippery', 'visibility', ]; const weatherTypes: EventType[] = ['WEATHER_CONDITION', 'ROAD_CONDITION']; if (weatherTypes.includes(event.event_type)) { return true; } const textToCheck = `${event.headline} ${event.description || ''}`.toLowerCase(); return weatherKeywords.some(keyword => textToCheck.includes(keyword)); }