Skip to main content
Glama
jagan-shanmugam

OpenStreetMap MCP Server

search_category

Find specific types of places like restaurants, schools, or parks within a defined geographic area using OpenStreetMap data.

Instructions

Search for specific types of places within a defined geographic area.

This tool allows targeted searches for places matching specific categories within a rectangular geographic region. It's particularly useful for filtering places by type (restaurants, schools, parks, etc.) within a neighborhood or city district. Results include complete location details and metadata about each matching place.

Args: category: Main OSM category to search for (e.g., "amenity", "shop", "tourism", "building") min_latitude: Southern boundary of search area (decimal degrees) min_longitude: Western boundary of search area (decimal degrees) max_latitude: Northern boundary of search area (decimal degrees) max_longitude: Eastern boundary of search area (decimal degrees) subcategories: Optional list of specific subcategories to filter by (e.g., ["restaurant", "cafe"])

Returns: Structured results including: - Query parameters - Count of matching places - List of matching places with coordinates, names, and metadata

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
categoryYes
min_latitudeYes
min_longitudeYes
max_latitudeYes
max_longitudeYes
subcategoriesNo

Implementation Reference

  • The main execution logic for the 'search_category' MCP tool. It constructs a bounding box from input coordinates, calls the helper method to query OSM features, processes the results to extract coordinates and metadata, and returns a structured response with query details, results list, and count.
    async def search_category(
        category: str,
        min_latitude: float,
        min_longitude: float,
        max_latitude: float,
        max_longitude: float,
        ctx: Context,
        subcategories: List[str] = None
    ) -> Dict[str, Any]:
        """
        Search for specific types of places within a defined geographic area.
        
        This tool allows targeted searches for places matching specific categories within
        a rectangular geographic region. It's particularly useful for filtering places by type
        (restaurants, schools, parks, etc.) within a neighborhood or city district. Results include
        complete location details and metadata about each matching place.
        
        Args:
            category: Main OSM category to search for (e.g., "amenity", "shop", "tourism", "building")
            min_latitude: Southern boundary of search area (decimal degrees)
            min_longitude: Western boundary of search area (decimal degrees)
            max_latitude: Northern boundary of search area (decimal degrees)
            max_longitude: Eastern boundary of search area (decimal degrees)
            subcategories: Optional list of specific subcategories to filter by (e.g., ["restaurant", "cafe"])
            
        Returns:
            Structured results including:
            - Query parameters
            - Count of matching places
            - List of matching places with coordinates, names, and metadata
        """
        osm_client = ctx.request_context.lifespan_context.osm_client
        
        bbox = (min_longitude, min_latitude, max_longitude, max_latitude)
        
        ctx.info(f"Searching for {category} in bounding box")
        features = await osm_client.search_features_by_category(bbox, category, subcategories)
        
        # Process results
        results = []
        for feature in features:
            tags = feature.get("tags", {})
            
            # Get coordinates based on feature type
            coords = {}
            if feature.get("type") == "node":
                coords = {
                    "latitude": feature.get("lat"),
                    "longitude": feature.get("lon")
                }
            # For ways and relations, use center coordinates if available
            elif "center" in feature:
                coords = {
                    "latitude": feature.get("center", {}).get("lat"),
                    "longitude": feature.get("center", {}).get("lon")
                }
            
            # Only include features with valid coordinates
            if coords:
                results.append({
                    "id": feature.get("id"),
                    "type": feature.get("type"),
                    "name": tags.get("name", "Unnamed"),
                    "coordinates": coords,
                    "category": category,
                    "subcategory": tags.get(category),
                    "tags": tags
                })
        
        return {
            "query": {
                "category": category,
                "subcategories": subcategories,
                "bbox": {
                    "min_latitude": min_latitude,
                    "min_longitude": min_longitude,
                    "max_latitude": max_latitude,
                    "max_longitude": max_longitude
                }
            },
            "results": results,
            "count": len(results)
        }
  • Supporting method in the OSMClient class that constructs and executes an Overpass API query to fetch OSM nodes, ways, and relations matching the specified category (and optional subcategories) within the given bounding box.
    async def search_features_by_category(self, 
                                         bbox: Tuple[float, float, float, float],
                                         category: str,
                                         subcategories: List[str] = None) -> List[Dict]:
        """Search for OSM features by category and subcategories"""
        if not self.session:
            raise RuntimeError("OSM client not connected")
        
        overpass_url = "https://overpass-api.de/api/interpreter"
        
        # Build query for specified category and subcategories
        if subcategories:
            subcategory_filters = " or ".join([f'"{category}"="{sub}"' for sub in subcategories])
            query_filter = f'({subcategory_filters})'
        else:
            query_filter = f'"{category}"'
        
        query = f"""
        [out:json];
        (
          node[{query_filter}]({bbox[1]},{bbox[0]},{bbox[3]},{bbox[2]});
          way[{query_filter}]({bbox[1]},{bbox[0]},{bbox[3]},{bbox[2]});
          relation[{query_filter}]({bbox[1]},{bbox[0]},{bbox[3]},{bbox[2]});
        );
        out body;
        """
        
        async with self.session.post(overpass_url, data={"data": query}) as response:
            if response.status == 200:
                data = await response.json()
                return data.get("elements", [])
            else:
                raise Exception(f"Failed to search features by category: {response.status}")
  • The @mcp.tool() decorator registers the search_category function as an MCP tool.
    async def search_category(
Behavior3/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It describes the tool's function and output format ('Results include complete location details and metadata'), but lacks details on permissions, rate limits, error handling, or pagination. For a search tool with no annotations, this is adequate but leaves gaps in operational 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 appropriately sized and front-loaded, starting with a clear purpose statement, followed by usage context, parameter details, and return information. Every sentence adds value without redundancy, and the structured 'Args' and 'Returns' sections enhance readability without unnecessary verbosity.

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 complexity (6 parameters, no output schema, no annotations), the description is largely complete, covering purpose, usage, parameters, and return structure. It adequately informs an agent, but could improve by addressing potential limitations like result limits or error cases, which would enhance completeness for a search operation.

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

Parameters4/5

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

With 0% schema description coverage and 6 parameters, the description compensates well by explaining all parameters in the 'Args' section, adding meaning beyond the bare schema. It clarifies 'category' as OSM categories with examples, defines geographic boundaries, and explains 'subcategories' as optional filters. However, it doesn't specify units or constraints for coordinates, leaving some semantic gaps.

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 with specific verbs ('search for specific types of places') and resources ('within a defined geographic area'), distinguishing it from siblings like 'find_nearby_places' or 'explore_area' by emphasizing category-based filtering within a rectangular region. It explicitly mentions what makes it unique: targeted searches by type (restaurants, schools, etc.) within geographic boundaries.

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 ('particularly useful for filtering places by type within a neighborhood or city district'), but does not explicitly state when not to use it or name specific alternatives among the sibling tools. It implies usage based on category-based geographic searches without detailing exclusions or direct comparisons to other tools.

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