Skip to main content
Glama
arben-adm

Brave Search MCP Server

brave_local_search

Find nearby businesses and locations using Brave Search. Enter location terms to get relevant local results.

Instructions

Search for local businesses and places

        Args:
            query: Location terms
            count: Results (1-20
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
countNo

Implementation Reference

  • Main handler for the 'brave_local_search' tool. Decorated with @self.mcp.tool() for registration. Implements local business search logic: queries Brave API for locations, paginates if needed, fetches POI/details, formats output, falls back to web search.
    @self.mcp.tool() 
    async def brave_local_search(
        query: str,
        count: Optional[int] = 20  # Changed default from 5 to 20
    ) -> str:
        """Search for local businesses and places
        
        Args:
            query: Location terms
            count: Results (1-20
        """
        self.rate_limit.check()
    
        # Initial location search
        params = {
            "q": query,
            "search_lang": "en",
            "result_filter": "locations",
            "count": 20  # Always request maximum results
        }
    
        client = self.get_client()
        response = await client.get(
            f"{self.base_url}/web/search",
            params=params
        )
        response.raise_for_status()
        data = response.json()
    
        location_ids = self._extract_location_ids(data)
        if not location_ids:
            # If no local results found, fallback to web search
            # with minimum 10 results
            return await brave_web_search(query, 20)
    
        # If we have less than 10 location IDs, try to get more
        offset = 0
        while len(location_ids) < 10 and offset < 40:
            offset += 20
            additional_response = await client.get(
                f"{self.base_url}/web/search",
                params={
                    "q": query,
                    "search_lang": "en",
                    "result_filter": "locations",
                    "count": 20,
                    "offset": offset
                }
            )
            additional_data = additional_response.json()
            location_ids.extend(self._extract_location_ids(additional_data))
    
        # Get details for at least 10 locations
        pois, descriptions = await self._get_location_details(
            location_ids[:max(10, len(location_ids))]
        )
        return self._format_local_results(pois, descriptions)
  • Helper function to fetch detailed POI (points of interest) and description data for location IDs using parallel asyncio.gather calls to Brave API.
    async def _get_location_details(
        self,
        ids: List[str]
    ) -> Tuple[Dict[str, Any], Dict[str, Any]]:
        """Fetch POI and description data for locations"""
        client = self.get_client()
        pois_response, desc_response = await asyncio.gather(
            client.get(
                f"{self.base_url}/local/pois",
                params={"ids": ids}
            ),
            client.get(
                f"{self.base_url}/local/descriptions",
                params={"ids": ids}
            )
        )
        return (
            pois_response.json(),
            desc_response.json()
        )
  • Helper to extract location IDs from the initial web search response filtered by 'locations'.
    def _extract_location_ids(self, data: Dict) -> List[str]:
        """Extract location IDs from search response"""
        return [
            result["id"] 
            for result in data.get("locations", {}).get("results", [])
            if "id" in result
        ]
  • Helper to format the retrieved POI data and descriptions into a readable multi-line string output separated by ---.
    def _format_local_results(
        self,
        pois: Dict[str, Any],
        descriptions: Dict[str, Any]
    ) -> str:
        """Format local search results with details"""
        results = []
        for poi in pois.get("results", []):
            location = {
                "name": poi.get("name", "N/A"),
                "address": self._format_address(poi.get("address", {})),
                "phone": poi.get("phone", "N/A"),
                "rating": self._format_rating(poi.get("rating", {})),
                "price": poi.get("priceRange", "N/A"),
                "hours": ", ".join(poi.get("openingHours", [])) or "N/A",
                "description": descriptions.get("descriptions", {}).get(
                    poi["id"], "No description available"
                )
            }
            
            results.append(
                f"Name: {location['name']}\n"
                f"Address: {location['address']}\n"
                f"Phone: {location['phone']}\n"
                f"Rating: {location['rating']}\n"
                f"Price Range: {location['price']}\n"
                f"Hours: {location['hours']}\n"
                f"Description: {location['description']}"
            )
  • Helper utility to format address dictionary into a comma-separated string.
    def _format_address(self, addr: Dict) -> str:
        """Format address components"""
        components = [
            addr.get("streetAddress", ""),
            addr.get("addressLocality", ""),
            addr.get("addressRegion", ""),
            addr.get("postalCode", "")
        ]
        return ", ".join(filter(None, components)) or "N/A"
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. While 'Search' implies a read-only operation, it doesn't specify authentication requirements, rate limits, data sources, or what happens when no results are found. The description provides minimal behavioral context beyond the basic operation.

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

Conciseness4/5

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

The description is appropriately concise with a clear purpose statement followed by parameter explanations. The formatting with 'Args:' section is helpful, though the incomplete 'Results (1-20' text suggests a typographical error that slightly detracts from professionalism.

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

Completeness2/5

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

For a search tool with 2 parameters, 0% schema description coverage, no annotations, and no output schema, the description is insufficient. It doesn't explain what information is returned, result format, error conditions, or how this differs from the sibling web search tool, leaving significant gaps for an AI agent.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It provides basic explanations for both parameters ('Location terms' for query, 'Results (1-20' for count), but these are minimal and don't explain format expectations, what constitutes valid 'Location terms', or how the count parameter works with the default value of 20.

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

Purpose4/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 as 'Search for local businesses and places' which is a specific verb+resource combination. However, it doesn't explicitly differentiate from its sibling 'brave_web_search' which likely searches the broader web rather than local businesses.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus its sibling 'brave_web_search' or any alternatives. There's no mention of appropriate contexts, prerequisites, or exclusions for using this local search functionality.

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/arben-adm/brave-mcp-search'

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