Skip to main content
Glama

search_news

Search news articles using the Brave News API to find relevant information based on user queries, returning results with titles, sources, dates, and descriptions.

Instructions

Search news using Brave News API

Args:
    query (str): The search query for news
    
Returns:
    str: News search results including titles, sources, dates and descriptions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes

Implementation Reference

  • The handler function for the 'search_news' tool. Decorated with @mcp.tool() for registration in MCP. Takes a query string and delegates to the _do_news_search helper function to perform the actual search.
    @mcp.tool()
    def search_news(query: str) -> str:
        """Search news using Brave News API
        
        Args:
            query (str): The search query for news
            
        Returns:
            str: News search results including titles, sources, dates and descriptions
        """
        return _do_news_search(query)
  • The core helper function implementing the Brave News API search logic. Handles query encoding, language detection, API request, result parsing, formatting news items with title, source, date, URL, description, and error handling.
    def _do_news_search(query: str, country: str = "all", search_lang: str = None) -> str:
        """Internal function to handle news search using Brave News API"""
        try:
            query = query.encode('utf-8').decode('utf-8')
            
            # 如果未指定语言,自动检测
            if search_lang is None:
                search_lang = _detect_language(query)
                logger.debug(f"Detected language: {search_lang} for query: {query}")
            
            url = "https://api.search.brave.com/res/v1/news/search"
            
            headers = {
                "Accept": "application/json",
                "Accept-Encoding": "gzip",
                "X-Subscription-Token": API_KEY
            }
            
            params = {
                "q": query,
                "count": 10,
                "country": country,
                "search_lang": search_lang,
                "spellcheck": 1
            }
            
            logger.debug(f"Searching news for query: {query}")
            response = requests.get(url, headers=headers, params=params)
            response.raise_for_status()
            data = response.json()
            
            # 处理新闻搜索结果
            results = []
            if 'results' in data:
                for news in data['results']:
                    title = news.get('title', 'No title').encode('utf-8').decode('utf-8')
                    url = news.get('url', 'No URL')
                    description = news.get('description', 'No description').encode('utf-8').decode('utf-8')
                    date = news.get('published_time', 'Unknown date')
                    source = news.get('source', {}).get('name', 'Unknown source')
                    
                    news_item = [
                        f"- {title}",
                        f"  Source: {source}",
                        f"  Date: {date}",
                        f"  URL: {url}",
                        f"  Description: {description}\n"
                    ]
                    results.append("\n".join(news_item))
            
            if not results:
                return "No news found for your query."
                
            return "News Results:\n\n" + "\n".join(results)
            
        except requests.exceptions.RequestException as e:
            logger.error(f"News API request error: {str(e)}")
            return f"Error searching news: {str(e)}"
        except Exception as e:
            logger.error(f"News search error: {str(e)}")
            logger.exception("Detailed error trace:")
            return f"Error searching news: {str(e)}"
Behavior2/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. While it mentions the API source and return format, it doesn't describe important behavioral aspects like rate limits, authentication requirements, error handling, pagination, or whether this is a read-only operation. For a search tool with zero annotation coverage, this leaves significant gaps.

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 sized and well-structured with clear sections for Args and Returns. The first sentence establishes the core purpose, followed by structured parameter and return documentation. There's no wasted text, though the structure could be slightly more front-loaded with key behavioral information.

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?

Given no annotations, no output schema, and minimal parameter documentation, the description is incomplete for effective tool use. It doesn't explain the return format beyond mentioning it includes 'titles, sources, dates and descriptions' - no structure details, error cases, or limitations. For a search tool that likely has rate limits and specific behavior, this leaves too many unknowns.

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

Parameters3/5

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

With 0% schema description coverage, the description adds value by documenting the single parameter 'query' and its purpose ('The search query for news'). However, it doesn't provide additional context about query formatting, length limits, supported operators, or examples. The baseline would be lower without this parameter documentation, but it's minimal compensation for the schema coverage gap.

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: 'Search news using Brave News API' - a specific verb ('Search') and resource ('news') with the API source identified. It distinguishes from some siblings like 'get_url_content_direct' or 'url_content' but doesn't explicitly differentiate from 'search_news_info' which appears to be a related news search tool.

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?

No guidance is provided about when to use this tool versus alternatives. With siblings like 'search_news_info' and 'search_brave_with_summary' available, the description doesn't indicate whether this is the primary news search tool, when to choose it over other search tools, or what specific use cases it serves.

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/mcp2everything/mcp2brave'

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