route-overview
Get routing information between locations including travel time, distance, and route geometry for various travel methods.
Instructions
Get high-level routing information between two or more locations. Includes travel time, distance, and an encoded polyline of the route. The result is JSON.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| locations | Yes | ||
| costing | Yes | The method of travel to use when routing (auto = automobile). | |
| units | Yes | The unit to report distances in. |
Implementation Reference
- src/tools/routing.ts:21-98 (handler)The handler function that executes the route-overview tool. It constructs a RouteRequest for the Stadia Maps Routing API, fetches the route, processes the summary to compute travel time and distance, extracts bounding box and polyline, and returns structured JSON content.export async function routeOverview({ locations, costing, units, }: RouteOverviewParams): Promise<CallToolResult> { const req: RouteRequest = { locations, directionsType: "none", units, costing, }; return handleToolError( async () => { const res = await routeApi.route({ routeRequest: req }); if (instanceOfRouteResponse(res)) { if (res.trip.status != 0) { return { content: [ { type: "text", text: "No routes found.", }, ], }; } const trip = res.trip; const summary = trip.summary; let travelTime: string; if (summary.time < 60) { travelTime = "less than a minute"; } else { const minutes = Math.round(summary.time / 60); travelTime = `${minutes} minutes`; } const route = { distance: `${summary.length} ${units}`, time: travelTime, bbox_w_s_n_e: [ summary.minLon, summary.minLat, summary.maxLon, summary.maxLat, ], polyline6: trip.legs[0].shape, }; return { structuredContent: route, content: [ { type: "text", text: JSON.stringify(route), }, ], }; } else { console.error("Unexpected response:", res); return { content: [ { type: "text", text: "Unexpected response format.", }, ], }; } }, { contextMessage: "Route calculation failed", enableLogging: true, }, ); }
- src/index.ts:80-89 (registration)Registers the 'route-overview' tool with the MCP server, providing the tool name, description, input schema using Zod, and references the routeOverview handler function.server.tool( "route-overview", "Get high-level routing information between two or more locations. Includes travel time, distance, and an encoded polyline of the route. The result is JSON.", { locations: z.array(coordinatesSchema).min(2), costing: costingSchema, units: unitsSchema, }, routeOverview, );
- src/index.ts:83-87 (schema)Defines the input schema for the route-overview tool using Zod schemas for locations (array of coordinates, min 2), costing model, and units.{ locations: z.array(coordinatesSchema).min(2), costing: costingSchema, units: unitsSchema, },
- src/schemas.ts:22-27 (schema)Zod schema for coordinates used in route-overview locations.export const coordinatesSchema = z .object({ lat: latitudeSchema, lon: longitudeSchema, }) .describe("A geographic coordinate pair.");
- src/schemas.ts:109-111 (schema)Zod schema for costing model used in route-overview.export const costingSchema = z .nativeEnum(CostingModel) .describe("The method of travel to use when routing (auto = automobile).");
- src/schemas.ts:113-116 (schema)Zod schema for units used in route-overview.export const unitsSchema = z .nativeEnum(DistanceUnit) .describe("The unit to report distances in.");