Skip to main content
Glama

Get Directions

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;
                }>;
            }>;
        }>;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. While 'get directions' implies a read-only operation, it doesn't specify whether this requires authentication, has rate limits, returns structured vs. textual directions, includes estimated times/costs, or handles errors. For a tool with 3 parameters and no annotation coverage, this leaves significant behavioral gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that communicates the core purpose without any wasted words. It's appropriately sized for a straightforward tool and gets directly to the point.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a directions tool with 3 parameters, no annotations, and no output schema, the description is insufficient. It doesn't explain what format the directions are returned in (textual, structured, with waypoints), whether it includes real-time traffic, or what the typical response looks like. The agent would have to invoke the tool blindly to understand its behavior.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with all parameters well-documented in the schema itself. The description adds no additional parameter information beyond what's already in the schema (origin, destination, mode with enum values). This meets the baseline expectation when schema coverage is complete.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'get' and resource 'directions' with the scope 'between two locations', making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'get_distance_matrix' or 'get_map_with_directions' which might provide similar or overlapping functionality.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives like 'get_distance_matrix' (which might provide distance/time without full directions) or 'get_map_with_directions' (which might include visual output). There's no mention of prerequisites, limitations, or appropriate contexts for choosing this specific tool.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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