Skip to main content
Glama
masx200

AMap Maps MCP Server

by masx200

maps_direction_driving

Plan driving routes between coordinates to generate car commuting directions and travel data for personal vehicles.

Instructions

驾车路径规划 API 可以根据用户起终点经纬度坐标规划以小客车、轿车通勤出行的方案,并且返回通勤方案的数据。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
originYes出发点经度,纬度,坐标格式为:经度,纬度
destinationYes目的地经度,纬度,坐标格式为:经度,纬度

Implementation Reference

  • Handler function that fetches driving directions from Amap API using origin and destination coordinates, processes the response, and returns formatted route data or error.
    async function handleDriving(origin, destination) {
      const url = new URL("https://restapi.amap.com/v3/direction/driving");
      url.searchParams.append("key", AMAP_MAPS_API_KEY);
      url.searchParams.append("origin", origin);
      url.searchParams.append("destination", destination);
      url.searchParams.append("source", "ts_mcp");
      const response = await fetch(url.toString());
      const data = await response.json();
      if (data.status !== "1") {
        return {
          content: [{
            type: "text",
            text: `Direction Driving failed: ${data.info || data.infocode}`,
          }],
          isError: true,
        };
      }
      return {
        content: [{
          type: "text",
          text: JSON.stringify(
            {
              route: {
                origin: data.route.origin,
                destination: data.route.destination,
                paths: data.route.paths.map((path) => {
                  return {
                    path: path.path,
                    distance: path.distance,
                    duration: path.duration,
                    steps: path.steps.map((step) => {
                      return {
                        instruction: step.instruction,
                        road: step.road,
                        distance: step.distance,
                        orientation: step.orientation,
                        duration: step.duration,
                      };
                    }),
                  };
                }),
              },
            },
            null,
            2,
          ),
        }],
        isError: false,
      };
  • Tool schema definition including name, description, and input schema for origin and destination coordinates.
    const DRIVING_TOOl = {
      name: "maps_direction_driving",
      description:
        "驾车路径规划 API 可以根据用户起终点经纬度坐标规划以小客车、轿车通勤出行的方案,并且返回通勤方案的数据。",
      inputSchema: {
        type: "object",
        properties: {
          origin: {
            type: "string",
            description: "出发点经度,纬度,坐标格式为:经度,纬度",
          },
          destination: {
            type: "string",
            description: "目的地经度,纬度,坐标格式为:经度,纬度",
          },
        },
        required: ["origin", "destination"],
      },
    };
  • build/index.js:882-885 (registration)
    Registration of the tool handler in the CallToolRequestSchema switch statement.
    case "maps_direction_driving": {
      const { origin, destination } = request.params.arguments;
      return await handleDriving(origin, destination);
    }
  • build/index.js:848-850 (registration)
    Registration in ListToolsRequestSchema handler which includes the tool in MAPS_TOOLS array.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: MAPS_TOOLS,
    }));
  • Identical handler function in the HTTP streamable version of the server.
    async function handleDriving(origin, destination) {
      const AMAP_MAPS_API_KEY = getApiKey();
      const url = new URL("https://restapi.amap.com/v3/direction/driving");
      url.searchParams.append("key", AMAP_MAPS_API_KEY);
      url.searchParams.append("origin", origin);
      url.searchParams.append("destination", destination);
      url.searchParams.append("source", "ts_mcp");
      const response = await fetch(url.toString());
      const data = await response.json();
      if (data.status !== "1") {
        return {
          content: [
            {
              type: "text",
              text: `Direction Driving failed: ${data.info || data.infocode}`,
            },
          ],
          isError: true,
        };
      }
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(
              {
                route: {
                  origin: data.route.origin,
                  destination: data.route.destination,
                  paths: data.route.paths.map((path) => {
                    return {
                      path: path.path,
                      distance: path.distance,
                      duration: path.duration,
                      steps: path.steps.map((step) => {
                        return {
                          instruction: step.instruction,
                          road: step.road,
                          distance: step.distance,
                          orientation: step.orientation,
                          duration: step.duration,
                        };
                      }),
                    };
                  }),
                },
              },
              null,
              2,
            ),
          },
        ],
        isError: false,
      };

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/masx200/amap-maps-mcp-server'

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