get_geocode
Convert addresses or place names into geographic coordinates for mapping and location-based applications.
Instructions
Convert an address to coordinates
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | Address or place name to convert |
Implementation Reference
- src/mcp/create-server.ts:96-127 (registration)Registers the 'get_geocode' tool with the MCP server, including title, description, input schema, and a handler function that calls placesSearcher.geocode and formats the response.server.registerTool( "get_geocode", { title: "Geocode Address", description: "Convert an address to coordinates", inputSchema: GeocodeSchema, }, async (args) => { try { const result = await placesSearcher.geocode(args.address); 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, }; } } );
- src/schemas/tool-schemas.ts:22-24 (schema)Defines the input schema for the 'get_geocode' tool using Zod, requiring an 'address' string.export const GeocodeSchema = { address: z.string().describe("Address or place name to convert") };
- src/services/places.ts:190-220 (handler)Implements the core geocoding logic in the PlacesSearcher class by calling the Google Maps Geocoding API, extracting the first result's location data, and returning it in the ServiceResponse format.async geocode(address: string): Promise<ServiceResponse<Location>> { try { validateRequiredString(address, "Address"); const response = await this.client.geocode({ params: { key: config.googleMapsApiKey, address: address, language: config.defaultLanguage as Language, region: config.defaultRegion, }, }); if (response.data.results.length === 0) { throw new Error("No results found for the given address"); } const location = response.data.results[0].geometry.location; return { success: true, data: { lat: location.lat, lng: location.lng, address: response.data.results[0].formatted_address, placeId: response.data.results[0].place_id, }, }; } catch (error) { return handleError(error); } }