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[];
    }
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. It mentions geocoding implicitly ('using their names'), but doesn't clarify authentication needs, rate limits, error handling, or what the route output includes (e.g., distance, duration, geometry). For a tool that performs geocoding and routing, this is a significant gap.

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 front-loads the core functionality. Every word earns its place, with no redundant or vague phrasing, 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.

Completeness2/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 incomplete for a tool with geocoding and routing complexity. It doesn't explain what the route output includes (e.g., JSON structure, key fields like distance or polyline), error cases (e.g., invalid place names), or behavioral constraints, leaving gaps for agent invocation.

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 parameters. The description adds minimal value beyond the schema—it implies 'places' are names (not coordinates) and mentions geocoding, but doesn't explain parameter interactions or usage nuances. Baseline 3 is appropriate as 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 ('Get navigation route') and resource ('between multiple places'), specifying it uses place names rather than coordinates. However, it doesn't explicitly differentiate from sibling tools like 'mapbox_directions' (which likely uses coordinates) or 'mapbox_matrix_by_places' (which might calculate multiple routes).

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?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention sibling tools like 'mapbox_directions' (for coordinate-based routing) or 'mapbox_matrix_by_places' (which might handle distance matrices between places), leaving the agent without context for tool selection.

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/AidenYangX/mapbox-mcp-server'

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