maps_directions
Generate precise directions between two locations using specified travel modes like driving, walking, bicycling, or transit. Ideal for planning routes with accurate, real-time guidance.
Instructions
獲取兩點之間的路線指引
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| destination | Yes | 終點地址或座標 | |
| mode | No | 交通模式 | driving |
| origin | Yes | 起點地址或座標 |
Implementation Reference
- src/tools/maps/directions.ts:18-53 (handler)The ACTION function that executes the core logic of the 'maps_directions' tool. It uses PlacesSearcher to fetch directions between origin and destination, handles errors, and returns formatted content.async function ACTION(params: any): Promise<{ content: any[]; isError?: boolean }> { try { // Create a new PlacesSearcher instance with the current request's API key const apiKey = getCurrentApiKey(); const placesSearcher = new PlacesSearcher(apiKey); const result = await placesSearcher.getDirections( params.origin, params.destination, params.mode, params.departure_time, params.arrival_time ); if (!result.success) { return { content: [{ type: "text", text: result.error || "Failed to get directions" }], isError: true, }; } return { content: [ { type: "text", text: JSON.stringify(result.data, null, 2), }, ], isError: false, }; } catch (error: any) { const errorMessage = error instanceof Error ? error.message : JSON.stringify(error); return { isError: true, content: [{ type: "text", text: `Error getting directions: ${errorMessage}` }], }; }
- src/tools/maps/directions.ts:8-14 (schema)Zod schema defining the input parameters for the maps_directions tool.const SCHEMA = { origin: z.string().describe("Starting point address or coordinates"), destination: z.string().describe("Destination address or coordinates"), mode: z.enum(["driving", "walking", "bicycling", "transit"]).default("driving").describe("Travel mode for directions"), departure_time: z.string().optional().describe("Departure time (ISO string format)"), arrival_time: z.string().optional().describe("Arrival time (ISO string format)"), };
- src/config.ts:53-58 (registration)Registration of the 'maps_directions' tool in the server configuration array, linking to the Directions module.{ name: Directions.NAME, description: Directions.DESCRIPTION, schema: Directions.SCHEMA, action: (params: DirectionsParams) => Directions.ACTION(params), },
- src/config.ts:9-9 (registration)Import statement for the Directions tool module used in registration.import { Directions, DirectionsParams } from "./tools/maps/directions.js";