isochrone
Create isochrone contours to visualize areas accessible within a set time or distance from a specific location. Supports multiple travel methods and returns GeoJSON polygons for 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 |
|---|---|---|---|
| contours | Yes | Array of 1-4 contours. All contours must be of the same type (all time or all distance). | |
| costing | Yes | The method of travel to use for isochrone calculation (auto = automobile). | |
| location | Yes | A geographic coordinate pair. |
Implementation Reference
- src/tools/isochrone.ts:68-101 (handler)Main handler function for the 'isochrone' tool. Constructs the API request using provided parameters, calls the Stadia Maps Routing API, processes the response using isochroneToolResult 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/tools/isochrone.ts:22-66 (helper)Helper function to format the IsochroneResponse from the API into a structured CallToolResult with text description of contours 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}`, }, ], }; }
- src/index.ts:91-100 (registration)Registers the 'isochrone' tool with the MCP server, specifying name, description, input schema, 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 (travel mode) used in the isochrone tool input.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 in the isochrone tool input, validating 1-4 contours all of same type (time or distance).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).", }, );