Skip to main content
Glama

Map with Directions

get_map_with_directions

Generate a static map image with directions overlay between origin and destination points, supporting waypoints and multiple travel modes.

Instructions

Generate a static map with directions overlay

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
originYes
destinationYes
waypointsNo
modeNodriving
sizeNo
scaleNo
mapTypeNo

Implementation Reference

  • Core handler function implementing the tool logic: validates input parameters, generates Google Maps directions URL and static map URL with markers and path overlay.
    async getMapWithDirections(
        params: MapDirectionsParams
    ): Promise<ServiceResponse<MapDirectionsResponse>> {
        try {
            // Validate required fields
            if (
                !params.origin ||
                !params.origin.lat ||
                !params.origin.lng ||
                !params.origin.address
            ) {
                throw new Error("Origin must include address, lat, and lng");
            }
            if (
                !params.destination ||
                !params.destination.lat ||
                !params.destination.lng ||
                !params.destination.address
            ) {
                throw new Error(
                    "Destination must include address, lat, and lng"
                );
            }
    
            // Validate waypoints if provided
            if (params.waypoints) {
                for (const wp of params.waypoints) {
                    if (!wp.lat || !wp.lng || !wp.address) {
                        throw new Error(
                            "Each waypoint must include address, lat, and lng"
                        );
                    }
                }
            }
    
            // Generate URLs
            const googleMapsUrl = this.buildGoogleMapsUrl(params);
            const staticMapUrl = this.generateStaticMapUrl(params);
    
            // Create summary
            const summary = {
                origin: params.origin.address,
                destination: params.destination.address,
                waypoints: params.waypoints?.map((wp) => wp.address),
                mode: params.mode || TravelMode.driving,
            };
    
            return {
                success: true,
                data: {
                    googleMapsUrl,
                    staticMapUrl,
                    summary,
                },
            };
        } catch (error) {
            return handleError(error);
        }
    }
  • Tool registration in MCP server, proxying to MapDirectionsService.getMapWithDirections with error handling and response formatting.
    server.registerTool(
        "get_map_with_directions",
        {
            title: "Map with Directions",
            description: "Generate a static map with directions overlay",
            inputSchema: MapWithDirectionsSchema,
        },
        async (args) => {
            try {
                const result = await mapDirectionsService.getMapWithDirections({
                    ...args,
                    mode: 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 input schema defining parameters for origin, destination, optional waypoints, travel mode, map size, etc.
    export const MapWithDirectionsSchema = {
      origin: z.object({
        address: z.string(),
        lat: z.number(),
        lng: z.number()
      }),
      destination: z.object({
        address: z.string(),
        lat: z.number(),
        lng: z.number()
      }),
      waypoints: z.array(z.object({
        address: z.string(),
        lat: z.number(),
        lng: z.number()
      })).optional(),
      mode: TravelModeSchema.optional(),
      size: z.object({
        width: z.number(),
        height: z.number()
      }).optional(),
      scale: z.number().optional(),
      mapType: z.enum(["roadmap", "satellite", "hybrid", "terrain"]).optional()
    };
  • Helper function to generate the static Google Maps image URL with colored markers for origin/waypoints/destination and a connecting path.
    private generateStaticMapUrl(params: MapDirectionsParams): string {
        const baseUrl = "https://maps.googleapis.com/maps/api/staticmap";
    
        // Build all locations array
        const allLocations = [
            params.origin,
            ...(params.waypoints || []),
            params.destination,
        ];
    
        // Create markers
        const markers = [
            // Origin marker (green, label A)
            `markers=size:mid|color:green|label:A|${params.origin.lat},${params.origin.lng}`,
            // Destination marker (red, with appropriate letter)
            `markers=size:mid|color:red|label:${String.fromCharCode(65 + allLocations.length - 1)}|` +
                `${params.destination.lat},${params.destination.lng}`,
        ];
    
        // Add waypoint markers (blue, labels B, C, etc.)
        if (params.waypoints) {
            params.waypoints.forEach((wp, i) => {
                markers.push(
                    `markers=size:mid|color:blue|label:${String.fromCharCode(66 + i)}|${wp.lat},${wp.lng}`
                );
            });
        }
    
        // Create path connecting all points
        const pathPoints = allLocations
            .map((loc) => `${loc.lat},${loc.lng}`)
            .join("|");
        const path = `path=color:0x4285F4|weight:4|${pathPoints}`;
    
        // Build URL parameters
        const urlParams = new URLSearchParams({
            key: config.googleMapsApiKey,
            size: `${params.size?.width || 640}x${params.size?.height || 480}`,
            scale: (params.scale || 2).toString(),
            maptype: params.mapType || "roadmap",
        });
    
        // Combine everything
        // Caution !!!Do not send this URL to the client directly, as it contains API key!!!
        return `${baseUrl}?${urlParams}&${markers.join("&")}&${path}`;
    }
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. It mentions 'static map' (implying a read-only image output) and 'directions overlay' (suggesting visual routing), but lacks critical details: what format the output takes (image URL? binary data?), whether there are rate limits, authentication requirements, cost implications, or error conditions. For a tool with 7 parameters and complex functionality, 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 maximally concise - a single 6-word sentence that front-loads the core functionality. Every word earns its place: 'Generate' (action), 'static map' (primary output), 'with directions overlay' (key feature). There's zero redundancy or wasted verbiage.

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 the tool's complexity (7 parameters, nested objects, no output schema, no annotations), the description is severely incomplete. It doesn't address output format, error handling, usage constraints, or parameter semantics. While conciseness is good, this tool requires more context for effective use - especially with siblings that handle related geospatial functions where confusion is likely.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0% - none of the 7 parameters have descriptions in the schema. The tool description adds minimal value: it implies 'origin' and 'destination' parameters through 'directions overlay' context, and suggests map customization through 'static map,' but doesn't explain any of the specific parameters (waypoints, mode, size, scale, mapType) or their relationships. With 7 undocumented parameters, the description fails to compensate for the schema gap.

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: 'Generate a static map with directions overlay' - this specifies the action (generate), resource (static map), and key feature (directions overlay). It distinguishes from siblings like 'get_directions' (which likely returns directions data rather than a map) and 'get_distance_matrix' (which calculates distances). However, it doesn't explicitly contrast with these alternatives, keeping it at 4 rather than 5.

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 the 6 sibling tools. There's no mention of alternatives, prerequisites, or specific use cases. The agent must infer from tool names alone, which is insufficient for clear decision-making between similar mapping/direction tools.

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