Skip to main content
Glama
jagan-shanmugam

OpenStreetMap MCP Server

geocode_address

Convert addresses or place names to geographic coordinates with location details for mapping, navigation, and geospatial analysis.

Instructions

Convert an address or place name to geographic coordinates with detailed location information.

This tool takes a text description of a location (such as an address, landmark name, or place of interest) and returns its precise geographic coordinates along with rich metadata. The results can be used for mapping, navigation, location-based analysis, and as input to other geospatial tools.

Args: address: The address, place name, landmark, or description to geocode (e.g., "Empire State Building", "123 Main St, Springfield", "Golden Gate Park, San Francisco")

Returns: List of matching locations with: - Geographic coordinates (latitude/longitude) - Formatted address - Administrative boundaries (city, state, country) - OSM type and ID - Bounding box (if applicable) - Importance ranking

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
addressYes

Implementation Reference

  • The primary handler function for the 'geocode_address' tool. It is registered via the @mcp.tool() decorator and implements the core logic by calling the OSMClient.geocode method, enhancing results with coordinates, and returning the geocoded locations.
    @mcp.tool()
    async def geocode_address(address: str, ctx: Context) -> List[Dict]:
        """
        Convert an address or place name to geographic coordinates with detailed location information.
        
        This tool takes a text description of a location (such as an address, landmark name, or
        place of interest) and returns its precise geographic coordinates along with rich metadata.
        The results can be used for mapping, navigation, location-based analysis, and as input to
        other geospatial tools.
        
        Args:
            address: The address, place name, landmark, or description to geocode (e.g., "Empire State Building", 
                    "123 Main St, Springfield", "Golden Gate Park, San Francisco")
            
        Returns:
            List of matching locations with:
            - Geographic coordinates (latitude/longitude)
            - Formatted address
            - Administrative boundaries (city, state, country)
            - OSM type and ID
            - Bounding box (if applicable)
            - Importance ranking
        """
        osm_client = ctx.request_context.lifespan_context.osm_client
        results = await osm_client.geocode(address)
        
        # Enhance results with additional context
        for result in results:
            if "lat" in result and "lon" in result:
                result["coordinates"] = {
                    "latitude": float(result["lat"]),
                    "longitude": float(result["lon"])
                }
        
        return results
  • The supporting 'geocode' method in the OSMClient class that performs the actual HTTP request to Nominatim API for geocoding the address.
    async def geocode(self, query: str) -> List[Dict]:
        """Geocode an address or place name"""
        if not self.session:
            raise RuntimeError("OSM client not connected")
        
        nominatim_url = "https://nominatim.openstreetmap.org/search"
        async with self.session.get(
            nominatim_url,
            params={
                "q": query,
                "format": "json",
                "limit": 5
            },
            headers={"User-Agent": "OSM-MCP-Server/1.0"}
        ) as response:
            if response.status == 200:
                return await response.json()
            else:
                raise Exception(f"Failed to geocode '{query}': {response.status}")
  • The OSMClient class that manages the HTTP session and provides the geocoding functionality used by the tool handler.
    class OSMClient:
        def __init__(self, base_url="https://api.openstreetmap.org/api/0.6"):
            self.base_url = base_url
            self.session = None
            self.cache = {}  # Simple in-memory cache
        
        async def connect(self):
            self.session = aiohttp.ClientSession()
            
        async def disconnect(self):
            if self.session:
                await self.session.close()
  • The @mcp.tool() decorator registers the geocode_address function as an MCP tool.
    @mcp.tool()
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the core functionality well and mentions the output includes 'List of matching locations' with detailed metadata, which implies it returns multiple results. However, it doesn't disclose important behavioral traits like rate limits, authentication needs, error handling, or whether the tool uses external services (e.g., OSM suggests OpenStreetMap). The description adds value but lacks comprehensive behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured and appropriately sized. It starts with a clear purpose statement, explains usage context, then details parameters and returns in labeled sections. Every sentence adds value: the first defines the tool, the second explains input/output, the third gives use cases, and the parameter/return sections provide essential details without redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (single parameter, no output schema, no annotations), the description is mostly complete. It covers purpose, usage, parameter details, and return format comprehensively. The main gap is the lack of behavioral context (e.g., service limitations, error cases) which would be important for a geocoding tool that likely relies on external services. However, it provides enough information for basic usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description provides excellent parameter semantics beyond the input schema. The schema has 0% description coverage (just 'address' as a string), but the description adds: 'The address, place name, landmark, or description to geocode' with concrete examples ('Empire State Building', '123 Main St, Springfield'). This fully compensates for the schema's lack of documentation, giving clear meaning to the single parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Convert an address or place name to geographic coordinates with detailed location information.' It specifies the verb ('convert'), resource ('address or place name'), and output ('geographic coordinates with detailed location information'), distinguishing it from sibling tools like reverse_geocode (which does the opposite) and other location-based tools that perform different functions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool: 'for mapping, navigation, location-based analysis, and as input to other geospatial tools.' It implicitly distinguishes from siblings by focusing on forward geocoding (address to coordinates) versus reverse_geocode (coordinates to address), but doesn't explicitly state when not to use it or name alternatives beyond the general context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/jagan-shanmugam/open-streetmap-mcp'

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