reverse_geocode
Transforms latitude and longitude into a detailed address and location description, providing building, street, city, administrative boundaries, and OSM metadata, ideal for converting GPS coordinates to human-readable places.
Instructions
Convert geographic coordinates to a detailed address and location description.
This tool takes a specific point on Earth (latitude and longitude) and returns comprehensive information about that location, including its address, nearby landmarks, administrative boundaries, and other contextual information. Useful for translating GPS coordinates into human-readable locations.
Args: latitude: The latitude coordinate (decimal degrees, WGS84) longitude: The longitude coordinate (decimal degrees, WGS84)
Returns: Detailed address and location information including: - Formatted address - Building, street, city, state, country - Administrative hierarchy - OSM metadata - Postal code and other relevant identifiers
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| latitude | Yes | ||
| longitude | Yes |
Implementation Reference
- src/osm_mcp_server/server.py:238-262 (handler)The MCP tool handler for 'reverse_geocode'. Retrieves OSM client from context and calls its reverse_geocode method to convert lat/lon to address using Nominatim.@mcp.tool() async def reverse_geocode(latitude: float, longitude: float, ctx: Context) -> Dict: """ Convert geographic coordinates to a detailed address and location description. This tool takes a specific point on Earth (latitude and longitude) and returns comprehensive information about that location, including its address, nearby landmarks, administrative boundaries, and other contextual information. Useful for translating GPS coordinates into human-readable locations. Args: latitude: The latitude coordinate (decimal degrees, WGS84) longitude: The longitude coordinate (decimal degrees, WGS84) Returns: Detailed address and location information including: - Formatted address - Building, street, city, state, country - Administrative hierarchy - OSM metadata - Postal code and other relevant identifiers """ osm_client = ctx.request_context.lifespan_context.osm_client return await osm_client.reverse_geocode(latitude, longitude)
- src/osm_mcp_server/server.py:45-63 (helper)Supporting method in OSMClient class that implements the reverse geocoding logic by querying the Nominatim reverse API.async def reverse_geocode(self, lat: float, lon: float) -> Dict: """Reverse geocode coordinates to address""" if not self.session: raise RuntimeError("OSM client not connected") nominatim_url = "https://nominatim.openstreetmap.org/reverse" async with self.session.get( nominatim_url, params={ "lat": lat, "lon": lon, "format": "json" }, headers={"User-Agent": "OSM-MCP-Server/1.0"} ) as response: if response.status == 200: return await response.json() else: raise Exception(f"Failed to reverse geocode ({lat}, {lon}): {response.status}")
- src/osm_mcp_server/server.py:238-238 (registration)The @mcp.tool() decorator registers the reverse_geocode function as an MCP tool.@mcp.tool()