Skip to main content
Glama

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
NameRequiredDescriptionDefault
addressYesAddress or place name to convert

Implementation Reference

  • 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, }; } } );
  • 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") };
  • 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); } }

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/BACH-AI-Tools/MCP-Google-Maps'

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