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
| Name | Required | Description | Default |
|---|---|---|---|
| origin | Yes | 出发点经度,纬度,坐标格式为:经度,纬度 | |
| destination | Yes | 目的地经度,纬度,坐标格式为:经度,纬度 |
Implementation Reference
- build/index.js:543-591 (handler)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, };
- build/index.js:117-135 (schema)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, }));
- build/streamable-http.js:337-390 (handler)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, };