get_trail_closures
Retrieve current Swiss hiking trail closures and detours from official ASTRA data. Filter by closure reason or type to plan safe routes.
Instructions
Get current Swiss hiking trail closures and detours from the official ASTRA/Schweizer Wanderwege dataset. Filter by closure reason (e.g. Steinschlag, Bauarbeiten, Hangrutsch) or type (closure, detour). If no parameters are given, returns all active closures. Data source: swisstopo ch.astra.wanderland-sperrungen_umleitungen.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| reason | No | Optional search term for closure reason (e.g. 'Steinschlag', 'Bauarbeiten', 'Hangrutsch', 'Hochwasser'). Matches against the reason field (German or English). Case-insensitive partial match. | |
| type | No | Optional: filter by type — 'closure' (Sperrung) or 'detour' (Umleitung). If omitted, returns both. | |
| limit | No | Maximum number of results to return. Default: 20. Max: 100. |
Implementation Reference
- src/modules/hiking.ts:176-260 (handler)The implementation of the get_trail_closures tool, which fetches and filters trail closures based on reason and type.
async function handleGetTrailClosures( args: Record<string, unknown> ): Promise<string> { const reason = typeof args.reason === "string" ? args.reason.trim() : undefined; const typeFilter = typeof args.type === "string" ? args.type.trim() : undefined; const limit = Math.min(100, Math.max(1, Number(args.limit) || 20)); let closures: SlimClosure[]; if (reason) { // Search by reason — try reason_de field (primary) and also reason_en const [deResults, enResults] = await Promise.all([ fetchJSON<FindResponse>( buildUrl(`${BASE}/find`, { layer: LAYER, searchText: reason, searchField: "reason_de", returnGeometry: false, }) ), fetchJSON<FindResponse>( buildUrl(`${BASE}/find`, { layer: LAYER, searchText: reason, searchField: "reason_en", returnGeometry: false, }) ), ]); const combined = [...(deResults.results ?? []), ...(enResults.results ?? [])]; closures = deduplicate(combined.map(slimClosure)); } else { // No reason filter — fetch all via sperrungen_type_de field with broad searches const [closureResults, detourResults] = await Promise.all([ fetchJSON<FindResponse>( buildUrl(`${BASE}/find`, { layer: LAYER, searchText: "Sperrung", searchField: "sperrungen_type_de", returnGeometry: false, }) ), fetchJSON<FindResponse>( buildUrl(`${BASE}/find`, { layer: LAYER, searchText: "detour", searchField: "sperrungen_type", returnGeometry: false, }) ), ]); const combined = [...(closureResults.results ?? []), ...(detourResults.results ?? [])]; closures = deduplicate(combined.map(slimClosure)); } // Apply type filter closures = filterByType(closures, typeFilter); // Apply limit const total = closures.length; closures = closures.slice(0, limit); const result = { count: closures.length, total_found: total, filter: { reason: reason ?? null, type: typeFilter ?? null, limit, }, source: "ASTRA / Schweizer Wanderwege (swisstopo ch.astra.wanderland-sperrungen_umleitungen)", closures, }; const json = JSON.stringify(result); if (json.length > 49000) { // Trim descriptions to keep under 50K const trimmed = { ...result, closures: closures.map((c) => ({ ...c, description: c.description.slice(0, 100) })), }; return JSON.stringify(trimmed); } return json; } - src/modules/hiking.ts:325-337 (registration)The dispatcher function that registers and routes calls to get_trail_closures and get_trail_closures_nearby.
export async function handleHiking( name: string, args: Record<string, unknown> ): Promise<string> { switch (name) { case "get_trail_closures": return handleGetTrailClosures(args); case "get_trail_closures_nearby": return handleGetTrailClosuresNearby(args); default: throw new Error(`Unknown hiking tool: ${name}`); } }