Skip to main content
Glama
leehanchung

Bing Search MCP Server

by leehanchung

bing_news_search

Search for current news articles by specifying a query, result count, market, and freshness period using the Bing News Search API.

Instructions

Searches for news articles using Bing News Search API for current events and timely information.

Args:
    query: News search query (required)
    count: Number of results (1-50, default 10)
    market: Market code like en-US, en-GB, etc.
    freshness: Time period of news (Day, Week, Month)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNo
freshnessNoDay
marketNoen-US
queryYes

Implementation Reference

  • The primary handler for the 'bing_news_search' tool. Decorated with @server.tool() for registration in FastMCP. Implements the core logic: API key check, rate limiting, HTTP request to Bing News Search endpoint, parses JSON response, formats results with title, URL, description, date, and provider.
    @server.tool()
    async def bing_news_search(
        query: str, count: int = 10, market: str = "en-US", freshness: str = "Day"
    ) -> str:
        """Searches for news articles using Bing News Search API for current
        events and timely information.
    
        Args:
            query: News search query (required)
            count: Number of results (1-50, default 10)
            market: Market code like en-US, en-GB, etc.
            freshness: Time period of news (Day, Week, Month)
        """
        # 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()
    
            # News search has a different endpoint
            news_url = f"{BING_API_URL}v7.0/news/search"
    
            headers = {
                "User-Agent": USER_AGENT,
                "Ocp-Apim-Subscription-Key": api_key,
                "Accept": "application/json",
            }
    
            params = {
                "q": query,
                "count": min(count, 50),
                "mkt": market,
                "freshness": freshness,
            }
    
            async with httpx.AsyncClient() as client:
                response = await client.get(
                    news_url, headers=headers, params=params, timeout=10.0
                )
    
                response.raise_for_status()
                data = response.json()
    
                if "value" not in data:
                    return "No news results found."
    
                results = []
                for result in data["value"]:
                    published_date = result.get("datePublished", "Unknown date")
                    provider_info = result.get("provider", [{"name": "Unknown"}])
                    # Handle potential empty provider list
                    provider_name = (
                        provider_info[0]["name"] if provider_info else "Unknown"
                    )
                    results.append(
                        f"Title: {result['name']}\n"
                        f"URL: {result['url']}\n"
                        f"Description: {result['description']}\n"
                        f"Published: {published_date}\n"
                        f"Provider: {provider_name}"
                    )
    
                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)}"
  • Input schema and documentation for bing_news_search tool, defining parameters query (str required), count (int default 10, 1-50), market (str default en-US), freshness (str default Day), returning formatted string of news results.
    async def bing_news_search(
        query: str, count: int = 10, market: str = "en-US", freshness: str = "Day"
    ) -> str:
        """Searches for news articles using Bing News Search API for current
        events and timely information.
    
        Args:
            query: News search query (required)
            count: Number of results (1-50, default 10)
            market: Market code like en-US, en-GB, etc.
            freshness: Time period of news (Day, Week, Month)
        """
  • Shared helper function check_rate_limit() used by bing_news_search (and other tools) to enforce rate limits (1/sec, 15k/month). Called before API requests.
    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_news_search function as an MCP tool in the FastMCP server.
    @server.tool()
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