Skip to main content
Glama

Distance Matrix

get_distance_matrix

Calculate travel distances and times between multiple origins and destinations using Google Maps data for route planning and logistics analysis.

Instructions

Calculate distance and time between multiple origins and destinations

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
originsYesList of origin addresses or coordinates
destinationsYesList of destination addresses or coordinates
modeNoTravel modedriving

Implementation Reference

  • Implements the core logic for calculating distance matrix between multiple origins and destinations using the Google Maps Distance Matrix API.
    async calculateDistanceMatrix(
        origins: string[],
        destinations: string[],
        mode: TravelMode = TravelMode.driving
    ): Promise<ServiceResponse<DistanceMatrixResult>> {
        try {
            const response = await this.client.distancematrix({
                params: {
                    key: config.googleMapsApiKey,
                    origins,
                    destinations,
                    mode,
                    language: config.defaultLanguage as Language,
                },
            });
    
            return {
                success: true,
                data: {
                    originAddresses: response.data.origin_addresses,
                    destinationAddresses: response.data.destination_addresses,
                    rows: response.data.rows,
                },
            };
        } catch (error) {
            return handleError(error);
        }
    }
  • Registers the 'get_distance_matrix' tool with MCP server, providing schema and wrapper handler that delegates to PlacesSearcher.calculateDistanceMatrix.
    server.registerTool(
        "get_distance_matrix",
        {
            title: "Distance Matrix",
            description:
                "Calculate distance and time between multiple origins and destinations",
            inputSchema: DistanceMatrixSchema,
        },
        async (args) => {
            try {
                const result = await placesSearcher.calculateDistanceMatrix(
                    args.origins,
                    args.destinations,
                    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 the input parameters for the get_distance_matrix tool: origins, destinations, and optional mode.
    export const DistanceMatrixSchema = {
      origins: z.array(z.string()).describe("List of origin addresses or coordinates"),
      destinations: z.array(z.string()).describe("List of destination addresses or coordinates"),
      mode: TravelModeSchema.optional().describe("Travel mode")
    };
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool calculates distance and time, but doesn't mention performance characteristics (e.g., rate limits, latency), error handling, or output format details. For a tool with no annotations, this leaves significant gaps in understanding its behavior.

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 unnecessary words. It's front-loaded with the core functionality, making it easy for an agent to parse quickly.

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

Completeness3/5

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

Given no annotations and no output schema, the description is minimally adequate for a calculation tool but lacks completeness. It doesn't explain what the output looks like (e.g., matrix format, units), error conditions, or limitations (e.g., maximum origins/destinations). For a tool with 3 parameters and no structured output documentation, more context would be helpful.

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%, so the schema already documents all parameters thoroughly. The description adds no additional parameter semantics beyond what's in the schema (e.g., it doesn't explain format requirements for addresses/coordinates or clarify the 'mode' enum). Baseline 3 is appropriate when the schema does the heavy lifting.

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 'calculate' and the resources 'distance and time between multiple origins and destinations', which is specific and actionable. However, it doesn't explicitly distinguish this tool from sibling tools like 'get_directions' or 'get_map_with_directions', which might offer similar routing 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_directions' or 'get_map_with_directions'. It lacks context about use cases, prerequisites, or exclusions, leaving the agent to infer usage from the tool name and parameters alone.

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