get_road_closures
Retrieve current road closures and major restrictions across British Columbia. Filter results by region, highway, or severity to plan travel routes and avoid disruptions.
Instructions
List all current road closures and major restrictions across BC or filtered by region/highway. Includes full closures, lane closures, and significant restrictions.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| region | No | Filter by BC region (optional) | |
| highway | No | Filter by specific highway (optional) | |
| severityMinimum | No | Minimum severity to include (default: MODERATE) |
Implementation Reference
- src/tools/road-closures.ts:45-106 (handler)Main handler function that fetches active events from DriveBC API, filters for closures, applies severity and location filters, sorts by severity, and formats output.export async function handleRoadClosures(args: { region?: string; highway?: string; 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.highway) { params.road_name = normalizeHighwayName(args.highway); } const events = await getEvents(params); const closureEvents = events.filter(isClosureRelated); const severityOrder = { MAJOR: 0, MODERATE: 1, MINOR: 2, UNKNOWN: 3 }; const minimumSeverity = args.severityMinimum ?? 'MODERATE'; const minLevel = severityOrder[minimumSeverity]; const filteredEvents = closureEvents.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.highway) filters.push(`highway: ${normalizeHighwayName(args.highway)}`); const filterStr = filters.length > 0 ? ` (${filters.join(', ')})` : ''; return `No road closures found${filterStr}.`; } const lines: string[] = []; lines.push(`Found ${sortedEvents.length} road closure(s):\n`); sortedEvents.forEach((event, index) => { lines.push(`${index + 1}. ${formatClosureInfo(event)}`); lines.push(''); }); return lines.join('\n'); } catch (error) { if (error instanceof Error) { return `Error fetching road closures: ${error.message}`; } return 'Error fetching road closures: Unknown error'; } }
- src/tools/road-closures.ts:6-28 (schema)Tool schema defining name, description, and input parameters for region, highway, and severity filters.export const roadClosuresTool = { name: 'get_road_closures', description: 'List all current road closures and major restrictions across BC or filtered by region/highway. Includes full closures, lane closures, and significant restrictions.', inputSchema: { type: 'object' as const, properties: { region: { type: 'string', description: 'Filter by BC region (optional)', }, highway: { type: 'string', description: 'Filter by specific highway (optional)', }, severityMinimum: { type: 'string', enum: ['MINOR', 'MODERATE', 'MAJOR'], description: 'Minimum severity to include (default: MODERATE)', }, }, required: [], }, };
- src/index.ts:39-48 (registration)Registration of the roadClosuresTool in the MCP server's listTools handler.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ highwayConditionsTool, regionalConditionsTool, roadClosuresTool, weatherAlertsTool, ], }; });
- src/index.ts:65-67 (registration)Dispatch routing in the CallToolRequestHandler that calls handleRoadClosures for get_road_closures.case 'get_road_closures': result = await handleRoadClosures(args as any); break;
- src/tools/road-closures.ts:30-43 (helper)Helper function to determine if an event is related to road closures by checking keywords or MAJOR severity.function isClosureRelated(event: Event): boolean { const closureKeywords = [ 'closure', 'closed', 'impassable', 'blocked', 'restricted', 'detour', ]; const textToCheck = `${event.headline} ${event.description || ''}`.toLowerCase(); return closureKeywords.some(keyword => textToCheck.includes(keyword)) || event.severity === 'MAJOR'; }