Skip to main content
Glama

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
NameRequiredDescriptionDefault
originYesStarting point address or coordinates
destinationYesDestination address or coordinates
modeNoTravel modedriving

Implementation Reference

  • 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); } }
  • 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, }; } } );
  • 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") };
  • 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; }>; }>; }>; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BACH-AI-Tools/MCP-Google-Maps'

If you have feedback or need assistance with the MCP directory API, please join our Discord server