isochrone
Calculate travel-time or distance-based reachable areas from a location using specified transportation modes, returning GeoJSON polygons for visualization and analysis.
Instructions
Generate isochrone contours showing areas reachable within specified time or distance constraints from a single location. Returns GeoJSON polygons representing the reachable areas.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| location | Yes | A geographic coordinate pair. | |
| costing | Yes | The method of travel to use for isochrone calculation (auto = automobile). | |
| contours | Yes | Array of 1-4 contours. All contours must be of the same type (all time or all distance). |
Implementation Reference
- src/tools/isochrone.ts:68-101 (handler)Main handler function that constructs an IsochroneRequest, calls the Stadia Maps API, processes the response using a helper, or handles errors.export async function isochrone({ location, costing, contours, }: IsochroneParams): Promise<CallToolResult> { return handleToolError( async () => { const request: IsochroneRequest = { locations: [location], costing, contours, }; const response = await routeApi.isochrone({ isochroneRequest: request }); if (instanceOfIsochroneResponse(response)) { return isochroneToolResult(response); } else { return { content: [ { type: "text", text: "Unexpected response format from isochrone API.", }, ], }; } }, { contextMessage: "Isochrone calculation failed", enableLogging: true, }, ); }
- src/index.ts:91-100 (registration)Registers the 'isochrone' MCP tool with name, description, input schema (using imported zod schemas), and the handler function.server.tool( "isochrone", "Generate isochrone contours showing areas reachable within specified time or distance constraints from a single location. Returns GeoJSON polygons representing the reachable areas.", { location: coordinatesSchema, costing: isochroneCostingSchema, contours: contoursSchema, }, isochrone, );
- src/schemas.ts:118-122 (schema)Zod schema for the costing model parameter used in the isochrone tool.export const isochroneCostingSchema = z .nativeEnum(IsochroneCostingModel) .describe( "The method of travel to use for isochrone calculation (auto = automobile).", );
- src/schemas.ts:149-166 (schema)Zod schema for the contours array parameter, including validation for consistency in time/distance types.export const contoursSchema = z .array(contourSchema) .min(1) .max(4) .describe( "Array of 1-4 contours. All contours must be of the same type (all time or all distance).", ) .refine( (contours) => { const hasTime = contours.some((c) => c.time !== undefined); const hasDistance = contours.some((c) => c.distance !== undefined); return !(hasTime && hasDistance); }, { message: "All contours must be of the same type (either all time-based or all distance-based).", }, );
- src/tools/isochrone.ts:22-66 (helper)Helper function to format the IsochroneResponse into a CallToolResult text summary, extracting contour info and GeoJSON geometries.function isochroneToolResult(response: IsochroneResponse): CallToolResult { if (!response.features || !response.features.length) { return { content: [ { type: "text", text: "No isochrone results found.", }, ], }; } const results = response.features .map((feature, index) => { const properties = feature.properties; if (!properties) return `Invalid result (no properties): ${index}`; const contourInfo = `Contour ${properties.contour}`; let metricInfo = ""; if (properties?.metric === "time") { metricInfo = `Time: ${properties.contour} minutes`; } else if (properties?.metric === "distance") { metricInfo = `Distance: ${properties.contour} km`; } return [ `${contourInfo}`, metricInfo ? `${metricInfo}` : "", `GeoJSON Geometry: ${JSON.stringify(feature.geometry)}`, ] .filter(Boolean) .join("\n"); }) .join("\n---\n"); return { content: [ { type: "text", text: `Isochrone Results:\n---\n${results}`, }, ], }; }