Skip to main content
Glama
ricleedo

Google Services MCP Server

by ricleedo

get-directions

Calculate routes between two locations using Google Maps. Provide origin, destination, and travel mode to get detailed directions.

Instructions

Get directions between two locations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
originYesStarting location (address or lat,lng)
destinationYesEnding location (address or lat,lng)
modeNoTravel mode

Implementation Reference

  • The handler function for the 'get-directions' tool. It uses the Google Maps Directions API to compute routes between origin and destination, extracts route data including steps, formats it using formatDirectionsToMarkdown, and returns as Markdown text content.
    export async function getDirections(
      params: z.infer<typeof directionsSchema>,
      extra?: any
    ) {
      const apiKey = process.env.GOOGLE_MAPS_API_KEY;
      if (!apiKey) {
        throw new Error("GOOGLE_MAPS_API_KEY is required");
      }
    
      try {
        const response = await googleMapsClient.directions({
          params: {
            origin: params.origin,
            destination: params.destination,
            mode: (params.mode || "driving") as any,
            key: apiKey,
          },
        });
    
        const routes = response.data.routes;
        if (routes.length === 0) {
          return {
            content: [
              {
                type: "text" as const,
                text: "No routes found between the given locations.",
              },
            ],
          };
        }
    
        const route = routes[0];
        const leg = route.legs[0];
    
        const routeData = {
          distance: leg.distance.text,
          duration: leg.duration.text,
          start_address: leg.start_address,
          end_address: leg.end_address,
          steps: leg.steps.map((step) => ({
            instruction: step.html_instructions.replace(/<[^>]*>/g, ""),
            distance: step.distance.text,
            duration: step.duration.text,
          })),
        };
    
        return {
          content: [
            {
              type: "text" as const,
              text: formatDirectionsToMarkdown(routeData),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text" as const,
              text: `Error getting directions: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    }
  • Zod schema defining the input parameters for the get-directions tool: origin (string), destination (string), and optional mode (enum: driving, walking, bicycling, transit).
    export const directionsSchema = z.object({
      origin: z.string().describe("Starting location (address or lat,lng)"),
      destination: z.string().describe("Ending location (address or lat,lng)"),
      mode: z
        .enum(["driving", "walking", "bicycling", "transit"])
        .optional()
        .describe("Travel mode"),
    });
  • src/index.ts:89-97 (registration)
    Registration of the 'get-directions' tool using McpServer.tool(), providing name, description, input schema from directionsSchema.shape, and handler that calls getDirections.
    // Directions tool
    server.tool(
      "get-directions",
      "Get directions between two locations",
      directionsSchema.shape,
      async (params) => {
        return await getDirections(params);
      }
    );
  • Helper function to format the directions route data (distance, duration, steps) into a structured Markdown string for the tool response.
    function formatDirectionsToMarkdown(route: any): string {
      let markdown = `# Directions: ${route.start_address} → ${route.end_address}\n\n`;
      markdown += `Distance: ${route.distance}  \n`;
      markdown += `Duration: ${route.duration}  \n\n`;
      
      if (route.steps && route.steps.length) {
        markdown += `## Step-by-Step Directions\n\n`;
        route.steps.forEach((step: any, index: number) => {
          markdown += `${index + 1}. ${step.instruction} *(${step.distance}, ${step.duration})*\n`;
        });
      }
      
      return markdown;
    }
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 but offers minimal information. It doesn't mention whether this is a read-only operation, what kind of data is returned (e.g., route steps, duration, distance), error conditions, rate limits, or authentication requirements. The description states what the tool does but not how it behaves.

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 directly states the tool's purpose without any unnecessary words. It's appropriately sized for a simple tool and front-loads the essential information.

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 tool with no annotations and no output schema, the description is insufficiently complete. It doesn't explain what the return value contains (e.g., route details, travel time), error handling, or any behavioral constraints. The agent would need to guess about the output format and operational characteristics.

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?

The input schema has 100% description coverage, with clear documentation for all three parameters (origin, destination, mode with enum values). The description adds no additional parameter semantics beyond what's already in the schema, so it meets the baseline for high schema coverage without compensating value.

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 between two locations'), making the purpose immediately understandable. It doesn't specifically differentiate from sibling tools like 'distance-matrix' or 'geocode', but the core function is unambiguous.

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 'distance-matrix' (which calculates distances/times between multiple points) or 'geocode' (which converts addresses to coordinates). There's no mention of prerequisites, limitations, or typical use cases beyond the basic function.

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/ricleedo/Google-Service-MCP'

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