get_reverse_geocode
Convert geographic coordinates into a human-readable address using Google Maps data. Input latitude and longitude values to retrieve location information.
Instructions
Convert coordinates to an address
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| latitude | Yes | Latitude coordinate | |
| longitude | Yes | Longitude coordinate |
Implementation Reference
- src/services/places.ts:222-254 (handler)Core implementation of reverse geocoding logic using Google Maps Places API client. Validates coordinates, calls reverseGeocode API, processes the first result, and handles errors.async reverseGeocode( latitude: number, longitude: number ): Promise<ServiceResponse<Location>> { try { validateCoordinates(latitude, longitude); const response = await this.client.reverseGeocode({ params: { key: config.googleMapsApiKey, latlng: { lat: latitude, lng: longitude }, language: config.defaultLanguage as Language, }, }); if (response.data.results.length === 0) { throw new Error("No results found for the given coordinates"); } const result = response.data.results[0]; return { success: true, data: { lat: latitude, lng: longitude, address: result.formatted_address, placeId: result.place_id, }, }; } catch (error) { return handleError(error); } }
- src/mcp/create-server.ts:129-163 (registration)Registers the 'get_reverse_geocode' tool with MCP server, including schema reference and a thin async handler that delegates to PlacesSearcher.reverseGeocode and formats the response.server.registerTool( "get_reverse_geocode", { title: "Reverse Geocode", description: "Convert coordinates to an address", inputSchema: ReverseGeocodeSchema, }, async (args) => { try { const result = await placesSearcher.reverseGeocode( args.latitude, args.longitude ); 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:26-29 (schema)Zod schema defining the input parameters for the get_reverse_geocode tool: latitude and longitude numbers.export const ReverseGeocodeSchema = { latitude: z.number().describe("Latitude coordinate"), longitude: z.number().describe("Longitude coordinate") };