get_directions
Calculate travel routes between locations using driving, walking, bicycling, or transit modes to plan journeys efficiently.
Instructions
Get directions between two locations
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| origin | Yes | Starting point address or coordinates | |
| destination | Yes | Destination address or coordinates | |
| mode | No | Travel mode | driving |
Implementation Reference
- src/services/places.ts:285-331 (handler)Core implementation of getDirections: validates inputs, calls Google Directions API, processes routes/legs/steps, handles errors.async getDirections( origin: string, destination: string, mode: TravelMode = TravelMode.driving ): Promise<ServiceResponse<DirectionsResult>> { try { validateRequiredString(origin, "Origin"); validateRequiredString(destination, "Destination"); const response = await this.client.directions({ params: { key: config.googleMapsApiKey, origin, destination, mode, language: config.defaultLanguage as Language, }, }); if (response.data.routes.length === 0) { throw new Error("No route found"); } return { success: true, data: { routes: response.data.routes.map((route) => ({ summary: route.summary, legs: route.legs.map((leg) => ({ distance: leg.distance, duration: leg.duration, startAddress: leg.start_address, endAddress: leg.end_address, steps: leg.steps.map((step) => ({ distance: step.distance, duration: step.duration, instructions: step.html_instructions, travelMode: step.travel_mode, })), })), })), }, }; } catch (error) { return handleError(error); } }
- src/mcp/create-server.ts:203-238 (registration)Registers the 'get_directions' tool with the MCP server, using DirectionsSchema for input validation and delegating execution to PlacesSearcher.getDirections.server.registerTool( "get_directions", { title: "Get Directions", description: "Get directions between two locations", inputSchema: DirectionsSchema, }, async (args) => { try { const result = await placesSearcher.getDirections( args.origin, args.destination, args.mode as TravelMode | undefined ); return { content: [ { type: "text", text: JSON.stringify(result, null, 2) }, ], isError: !result.success, }; } catch (error) { const errorResponse = handleError(error); return { content: [ { type: "text", text: errorResponse.error || "An unknown error occurred", }, ], isError: true, }; } } );
- src/schemas/tool-schemas.ts:37-41 (schema)Zod schema defining input parameters for get_directions tool: origin, destination (strings), optional mode.export const DirectionsSchema = { origin: z.string().describe("Starting point address or coordinates"), destination: z.string().describe("Destination address or coordinates"), mode: TravelModeSchema.optional().describe("Travel mode") };
- src/types/index.ts:46-62 (schema)TypeScript interface defining the structure of the directions result data returned by the tool.export interface DirectionsResult { routes: Array<{ summary: string; legs: Array<{ distance: { text: string; value: number }; duration: { text: string; value: number }; startAddress: string; endAddress: string; steps: Array<{ distance: { text: string; value: number }; duration: { text: string; value: number }; instructions: string; travelMode: string; }>; }>; }>; }