Skip to main content
Glama
leehanchung

Bing Search MCP Server

by leehanchung

bing_web_search

Perform a web search via Bing API to retrieve relevant websites and general information by specifying query, result count, offset, and market code.

Instructions

Performs a web search using the Bing Search API for general information and websites.

Args:
    query: Search query (required)
    count: Number of results (1-50, default 10)
    offset: Pagination offset (default 0)
    market: Market code like en-US, en-GB, etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNo
marketNoen-US
offsetNo
queryYes

Implementation Reference

  • The core handler function for the 'bing_web_search' tool. It is registered via the @server.tool() decorator. The function signature with type annotations defines the input schema. It performs the Bing web search API call, applies rate limiting, handles errors, and formats search results as a string.
    @server.tool()
    async def bing_web_search(
        query: str, count: int = 10, offset: int = 0, market: str = "en-US"
    ) -> str:
        """Performs a web search using the Bing Search API for general information
        and websites.
    
        Args:
            query: Search query (required)
            count: Number of results (1-50, default 10)
            offset: Pagination offset (default 0)
            market: Market code like en-US, en-GB, etc.
        """
        # Get API key from environment
        api_key = os.environ.get("BING_API_KEY", "")
    
        if not api_key:
            return (
                "Error: Bing API key is not configured. Please set the "
                "BING_API_KEY environment variable."
            )
    
        try:
            check_rate_limit()
    
            headers = {
                "User-Agent": USER_AGENT,
                "Ocp-Apim-Subscription-Key": api_key,
                "Accept": "application/json",
            }
    
            params = {
                "q": query,
                "count": min(count, 50),  # Bing limits to 50 results max
                "offset": offset,
                "mkt": market,
                "responseFilter": "Webpages",
            }
    
            search_url = f"{BING_API_URL}v7.0/search"
    
            async with httpx.AsyncClient() as client:
                response = await client.get(
                    search_url, headers=headers, params=params, timeout=10.0
                )
    
                response.raise_for_status()
                data = response.json()
    
                if "webPages" not in data:
                    return "No results found."
    
                results = []
                for result in data["webPages"]["value"]:
                    results.append(
                        f"Title: {result['name']}\n"
                        f"URL: {result['url']}\n"
                        f"Description: {result['snippet']}"
                    )
    
                return "\n\n".join(results)
    
        except httpx.HTTPError as e:
            return f"Error communicating with Bing API: {str(e)}"
        except Exception as e:
            return f"Unexpected error: {str(e)}"
  • Helper function for rate limiting, called within bing_web_search to enforce API usage limits.
    def check_rate_limit():
        """Check if we're within rate limits"""
        now = time.time()
        if now - request_count["last_reset"] > 1:
            request_count["second"] = 0
            request_count["last_reset"] = now
    
        if (
            request_count["second"] >= RATE_LIMIT["per_second"]
            or request_count["month"] >= RATE_LIMIT["per_month"]
        ):
            raise Exception("Rate limit exceeded")
    
        request_count["second"] += 1
        request_count["month"] += 1
  • The @server.tool() decorator registers the bing_web_search function as an MCP tool.
    @server.tool()

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Related 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/leehanchung/bing-search-mcp'

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