Skip to main content
Glama
cablate

MCP Google Map Server

maps_distance_matrix

Calculate travel distances and times between multiple origins and destinations using driving, walking, bicycling, or transit modes for efficient route planning.

Instructions

計算多個起點和終點之間的距離和時間

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
destinationsYes終點地址或座標列表
modeNo交通模式driving
originsYes起點地址或座標列表

Implementation Reference

  • The ACTION function implements the core logic of the 'maps_distance_matrix' tool. It creates a PlacesSearcher instance, calls calculateDistanceMatrix with the provided origins, destinations, and mode, and returns the formatted result or error.
    async function ACTION(params: any): Promise<{ content: any[]; isError?: boolean }> {
      try {
        // Create a new PlacesSearcher instance with the current request's API key
        const apiKey = getCurrentApiKey();
        const placesSearcher = new PlacesSearcher(apiKey);
        const result = await placesSearcher.calculateDistanceMatrix(params.origins, params.destinations, params.mode);
    
        if (!result.success) {
          return {
            content: [{ type: "text", text: result.error || "Failed to calculate distance matrix" }],
            isError: true,
          };
        }
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result.data, null, 2),
            },
          ],
          isError: false,
        };
      } catch (error: any) {
        const errorMessage = error instanceof Error ? error.message : JSON.stringify(error);
        return {
          isError: true,
          content: [{ type: "text", text: `Error calculating distance matrix: ${errorMessage}` }],
        };
      }
    }
  • Zod schema defining the input parameters for the tool: origins (array of strings), destinations (array of strings), and mode (enum with default 'driving').
    const SCHEMA = {
      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: z.enum(["driving", "walking", "bicycling", "transit"]).default("driving").describe("Travel mode for calculation"),
    };
  • src/config.ts:47-52 (registration)
    Tool registration in the server configuration, importing and defining the tool using NAME, DESCRIPTION, SCHEMA, and ACTION from DistanceMatrix export.
    {
      name: DistanceMatrix.NAME,
      description: DistanceMatrix.DESCRIPTION,
      schema: DistanceMatrix.SCHEMA,
      action: (params: DistanceMatrixParams) => DistanceMatrix.ACTION(params),
    },
  • Supporting method in PlacesSearcher class that wraps the low-level Google Maps distance matrix call and handles errors.
    async calculateDistanceMatrix(origins: string[], destinations: string[], mode: "driving" | "walking" | "bicycling" | "transit" = "driving"): Promise<DistanceMatrixResponse> {
      try {
        const result = await this.mapsTools.calculateDistanceMatrix(origins, destinations, mode);
    
        return {
          success: true,
          data: result,
        };
      } catch (error) {
        return {
          success: false,
          error: error instanceof Error ? error.message : "An error occurred while calculating distance matrix",
        };
      }
    }
Behavior2/5

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

With no annotations provided, the description carries full burden but only states what the tool does without behavioral details. It doesn't disclose rate limits, authentication requirements, cost implications, error conditions, or output format. For a tool that likely calls an external API with potential usage constraints, this is inadequate.

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 extremely concise - a single sentence that directly states the tool's purpose. There's no wasted language or unnecessary elaboration, making it easy to parse and understand at a glance.

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 insufficient. It doesn't explain what the output looks like (matrix format? units?), doesn't mention API limitations or costs, and doesn't provide context about when this tool is preferable to sibling tools. The 100% schema coverage helps, but the description should do more heavy lifting.

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 doesn't add any meaningful parameter semantics beyond what's in the schema - it just restates the core functionality without explaining parameter interactions or constraints.

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 tool's purpose as calculating distances and times between multiple origins and destinations, which is specific (verb+resource). However, it doesn't distinguish this from sibling tools like maps_directions, which might provide similar routing functionality but with different output formats or use cases.

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 maps_directions or search_nearby. It doesn't mention prerequisites, typical use cases, or limitations, 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

Related 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/cablate/mcp-google-map'

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