Skip to main content
Glama

mapbox_directions_by_places

Calculate navigation routes between multiple locations using place names. Supports driving, walking, cycling, and traffic-aware routing modes for trip planning.

Instructions

Get navigation route between multiple places using their names

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
placesYesArray of place names to route between
profileNoNavigation modedriving
languageNoLanguage for geocoding results

Implementation Reference

  • The main handler function that implements the mapbox_directions_by_places tool logic. It geocodes place names to coordinates, validates results, and calls the directions API to calculate routes between places.
    export async function handleDirectionsByPlaces(
      args: z.infer<typeof DirectionsByPlacesArgsSchema>
    ) {
      const { places, profile, language } = args;
      const errors: DirectionsByPlacesError[] = [];
      const coordinates: { longitude: number; latitude: number }[] = [];
      const geocodingResults: Record<string, any> = {};
    
      // 1. Geocode each place
      for (const place of places) {
        try {
          const geocodingResult = await handleGeocoding({
            searchText: place,
            limit: 1,
            language,
            fuzzyMatch: true,
          });
    
          if (geocodingResult.isError || !geocodingResult.content[0]) {
            errors.push({
              place,
              error: `Geocoding failed: ${
                JSON.parse(geocodingResult.content[0].text).message ||
                "No results found"
              }`,
            });
            geocodingResults[place] = null;
            continue;
          }
    
          const feature = JSON.parse(geocodingResult.content[0].text).results[0];
          geocodingResults[place] = feature;
          coordinates.push(feature.coordinates);
        } catch (error) {
          errors.push({
            place,
            error: `Geocoding failed: ${
              error instanceof Error ? error.message : String(error)
            }`,
          });
          geocodingResults[place] = null;
        }
      }
    
      // 2. If we don't have enough valid coordinates, return error
      if (coordinates.length < 2) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                geocodingResults,
                directionsResult: null,
                errors: [
                  ...errors,
                  {
                    place: "general",
                    error: "Not enough valid coordinates to calculate route",
                  },
                ],
              }),
            },
          ],
          isError: true,
        };
      }
    
      // 3. Get directions using the coordinates
      try {
        const directionsResult = await handleDirections(coordinates, profile);
    
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                geocodingResults,
                directionsResult: directionsResult.isError
                  ? null
                  : JSON.parse(directionsResult.content[0].text),
                errors: errors.length > 0 ? errors : undefined,
              }),
            },
          ],
          isError: directionsResult.isError,
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify({
                geocodingResults,
                directionsResult: null,
                errors: [
                  ...errors,
                  {
                    place: "general",
                    error: `Directions calculation failed: ${
                      error instanceof Error ? error.message : String(error)
                    }`,
                  },
                ],
              }),
            },
          ],
          isError: true,
        };
      }
    }
  • Zod schema for validating the mapbox_directions_by_places tool arguments, including places array, profile enum, and optional language parameter.
    export const DirectionsByPlacesArgsSchema = z.object({
      places: z
        .array(z.string())
        .min(2)
        .describe("Array of place names to route between"),
      profile: z
        .enum(["driving-traffic", "driving", "walking", "cycling"])
        .default("driving"),
      language: z
        .string()
        .regex(/^[a-z]{2}$/)
        .optional()
        .describe("Language for geocoding results"),
    });
  • Registration and routing handler that processes the mapbox_directions_by_places tool call, validates arguments using the schema, and delegates to the handler function.
    case "mapbox_directions_by_places": {
      const validatedArgs = DirectionsByPlacesArgsSchema.parse(args);
      return await handleDirectionsByPlaces(validatedArgs);
    }
  • MCP tool definition that defines the input schema and description for the mapbox_directions_by_places tool exposed to clients.
    export const DIRECTIONS_BY_PLACES_TOOL: Tool = {
      name: "mapbox_directions_by_places",
      description: "Get navigation route between multiple places using their names",
      inputSchema: {
        type: "object",
        properties: {
          places: {
            type: "array",
            items: {
              type: "string",
            },
            minItems: 2,
            description: "Array of place names to route between",
          },
          profile: {
            type: "string",
            description: "Navigation mode",
            enum: ["driving-traffic", "driving", "walking", "cycling"],
            default: "driving",
          },
          language: {
            type: "string",
            description: "Language for geocoding results",
            pattern: "^[a-z]{2}$",
          },
        },
        required: ["places"],
      },
    };
  • Type definitions for the direction-by-places tool including DirectionsByPlacesError interface and DirectionsByPlacesResponse interface.
    export interface DirectionsByPlacesError {
      place: string;
      error: string;
    }
    
    export interface DirectionsByPlacesResponse {
      geocodingResults: {
        [place: string]: MapboxGeocodingResponse["features"][0] | null;
      };
      directionsResult: MapboxDirectionsResponse | null;
      errors?: DirectionsByPlacesError[];
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

C2.9/5.0
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure but offers minimal information. It mentions geocoding ('using their names') which implies place name resolution, but doesn't disclose rate limits, authentication needs, error handling, or what the route output includes (e.g., distance, duration, geometry). For a navigation tool with zero annotation coverage, 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 a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's appropriately sized and front-loaded, with every word contributing to understanding the core functionality.

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 navigation routing tool with no annotations and no output schema, the description is incomplete. It doesn't explain what the route output contains (e.g., waypoints, instructions, polyline), performance characteristics, or common failure modes. The geocoding aspect is hinted at but not elaborated, leaving significant gaps for agent understanding.

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 fully documents all three parameters. The description adds no additional parameter semantics beyond implying that 'places' are resolved via geocoding. Since the schema does the heavy lifting, the baseline score of 3 is appropriate.

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 action ('Get navigation route') and resource ('between multiple places using their names'), making the purpose understandable. However, it doesn't explicitly differentiate from sibling tools like 'mapbox_directions' or 'mapbox_matrix_by_places', which likely have overlapping functionality with different input approaches.

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 'mapbox_directions' (which might use coordinates instead of place names) or 'mapbox_matrix_by_places' (which might handle multiple routes). There's no mention of prerequisites, limitations, or typical use cases beyond the basic functionality.

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