maps_geocode
Convert addresses or landmark names into precise geographic coordinates using the MCP Google Map Server, enabling accurate location-based applications and services.
Instructions
將地址轉換為座標
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | 要轉換的地址或地標名稱 |
Implementation Reference
- src/tools/maps/geocode.ts:14-44 (handler)Main handler function (ACTION) for the maps_geocode tool. It creates a PlacesSearcher instance, calls geocode on the provided address, and returns the result as MCP content or error.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.geocode(params.address); if (!result.success) { return { content: [{ type: "text", text: result.error || "Failed to geocode address" }], 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 geocoding address: ${errorMessage}` }], }; } }
- src/tools/maps/geocode.ts:8-13 (schema)Zod schema definition for input parameters (address) and TypeScript type inference for GeocodeParams.const SCHEMA = { address: z.string().describe("Address or place name to convert to coordinates"), }; export type GeocodeParams = z.infer<z.ZodObject<typeof SCHEMA>>;
- src/config.ts:35-40 (registration)Tool registration in server configuration, referencing the Geocode module's NAME, DESCRIPTION, SCHEMA, and ACTION.{ name: Geocode.NAME, description: Geocode.DESCRIPTION, schema: Geocode.SCHEMA, action: (params: GeocodeParams) => Geocode.ACTION(params), },
- src/config.ts:6-6 (registration)Import of the Geocode tool module and its params type.import { Geocode, GeocodeParams } from "./tools/maps/geocode.js";