Skip to main content
Glama
modelcontextprotocol

MCP-Brave-Search

brave_web_search

Search the web for general queries, news, articles, and online content using Brave Search API. Gather broad information, find recent events, and access diverse web sources with pagination and filtering options.

Instructions

Performs a web search using the Brave Search API, ideal for general queries, news, articles, and online content. Use this for broad information gathering, recent events, or when you need diverse web sources. Supports pagination, content filtering, and freshness controls. Maximum 20 results per request, with offset for pagination.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesSearch query (max 400 chars, 50 words)
countNoNumber of results (1-20, default 10)
offsetNoPagination offset (max 9, default 0)

Implementation Reference

  • Core handler function that performs the Brave web search API call, processes the response, and formats results for the brave_web_search tool.
    async function performWebSearch(query: string, count: number = 10, offset: number = 0) {
      checkRateLimit();
      const url = new URL('https://api.search.brave.com/res/v1/web/search');
      url.searchParams.set('q', query);
      url.searchParams.set('count', Math.min(count, 20).toString()); // API limit
      url.searchParams.set('offset', offset.toString());
    
      const response = await fetch(url, {
        headers: {
          'Accept': 'application/json',
          'Accept-Encoding': 'gzip',
          'X-Subscription-Token': BRAVE_API_KEY
        }
      });
    
      if (!response.ok) {
        throw new Error(`Brave API error: ${response.status} ${response.statusText}\n${await response.text()}`);
      }
    
      const data = await response.json() as BraveWeb;
    
      // Extract just web results
      const results = (data.web?.results || []).map(result => ({
        title: result.title || '',
        description: result.description || '',
        url: result.url || ''
      }));
    
      return results.map(r =>
        `Title: ${r.title}\nDescription: ${r.description}\nURL: ${r.url}`
      ).join('\n\n');
    }
  • Entry point handler in the CallToolRequestSchema switch statement that validates arguments and invokes the performWebSearch function for brave_web_search.
    case "brave_web_search": {
      if (!isBraveWebSearchArgs(args)) {
        throw new Error("Invalid arguments for brave_web_search");
      }
      const { query, count = 10 } = args;
      const results = await performWebSearch(query, count);
      return {
        content: [{ type: "text", text: results }],
        isError: false,
      };
    }
  • Tool definition including name, description, and inputSchema for brave_web_search (used for registration and schema validation).
    const WEB_SEARCH_TOOL: Tool = {
      name: "brave_web_search",
      description:
        "Performs a web search using the Brave Search API, ideal for general queries, news, articles, and online content. " +
        "Use this for broad information gathering, recent events, or when you need diverse web sources. " +
        "Supports pagination, content filtering, and freshness controls. " +
        "Maximum 20 results per request, with offset for pagination. ",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Search query (max 400 chars, 50 words)"
          },
          count: {
            type: "number",
            description: "Number of results (1-20, default 10)",
            default: 10
          },
          offset: {
            type: "number",
            description: "Pagination offset (max 9, default 0)",
            default: 0
          },
        },
        required: ["query"],
      },
    };
  • Runtime type guard for validating input arguments to brave_web_search.
    function isBraveWebSearchArgs(args: unknown): args is { query: string; count?: number } {
      return (
        typeof args === "object" &&
        args !== null &&
        "query" in args &&
        typeof (args as { query: string }).query === "string"
      );
    }
  • Registers the brave_web_search tool (via WEB_SEARCH_TOOL) in the ListToolsRequestHandler.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [WEB_SEARCH_TOOL, LOCAL_SEARCH_TOOL],
    }));
Behavior4/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. It discloses key behavioral traits: supports pagination, content filtering, and freshness controls; maximum 20 results per request; and offset for pagination. This covers operational limits and features beyond basic search, though it could add more on error handling or response format. No contradiction with annotations exists.

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 with three sentences, front-loaded with the core purpose. Each sentence adds value: first states purpose and ideal use cases, second provides usage context, third details behavioral traits. It avoids redundancy and is efficient, though could be slightly more structured for clarity.

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 moderate complexity (3 parameters, no output schema, no annotations), the description is fairly complete. It covers purpose, usage, and key behaviors like pagination and limits. However, it lacks details on output format (e.g., what results look like) and error cases, which would be helpful since there's no output schema. It compensates well but has minor gaps.

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?

Schema description coverage is 100%, so the schema fully documents parameters (query, count, offset). The description adds marginal value by mentioning 'pagination' and 'maximum 20 results per request', which relate to count and offset, but does not provide additional syntax or meaning beyond the schema. Baseline 3 is appropriate as the schema does the heavy lifting.

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 'performs a web search using the Brave Search API', specifying the verb ('performs'), resource ('web search'), and technology ('Brave Search API'). It distinguishes from the sibling 'brave_local_search' by focusing on general web content rather than local results, though the distinction could be more explicit. The purpose is specific and actionable.

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: 'ideal for general queries, news, articles, and online content' and 'for broad information gathering, recent events, or when you need diverse web sources'. It implies an alternative (the sibling 'brave_local_search') by emphasizing web content, but does not explicitly state when not to use it or name the alternative directly, missing full explicit guidance.

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/modelcontextprotocol/servers-archived'

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