Skip to main content
Glama
kwp-lab

Brave Search With Proxy

brave_web_search

Search the web for general queries, news, articles, and online content using Brave Search API 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 implementation of the brave_web_search tool: performs API call to Brave Search, handles response, extracts and formats web search results.
    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');
    }
  • MCP CallTool handler case for brave_web_search: validates arguments and calls performWebSearch.
    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 schema definition for brave_web_search, including name, description, and JSON schema for inputs.
    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"],
      },
    };
  • Type guard function for validating brave_web_search arguments.
    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"
      );
    }
  • index.ts:318-320 (registration)
    Registers brave_web_search (via WEB_SEARCH_TOOL) in the MCP listTools handler.
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [WEB_SEARCH_TOOL, LOCAL_SEARCH_TOOL],
    }));

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

A3.9/5.0
Behavior3/5

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

No annotations provided, so description carries full burden. Mentions pagination, content filtering, freshness controls, and maximum results (20). However, does not explicitly state it is a read-only operation or discuss rate limits/auth. Adequate but not comprehensive.

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

Conciseness5/5

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

Three concise sentences: first states purpose, second provides usage scenarios, third mentions capabilities. No fluff, well-structured.

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

Completeness3/5

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

Tool has 3 params and no output schema. Description covers purpose, usage, and constraints but lacks explanation of return value format or structure. Could be more complete for agent usage.

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 coverage is 100%; baseline 3. Description adds slight value by reiterating max 20 results and offset usage, but no new parameter details beyond schema. Content filtering and freshness controls are mentioned but are not parameters.

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

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states 'Performs a web search using the Brave Search API' with specific verb+resource. Distinguishes from siblings like brave_answers and brave_local_search by stating 'ideal for general queries, news, articles, and online content.'

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?

Provides explicit usage context: 'ideal for general queries, news, articles, and online content. Use this for broad information gathering, recent events, or when you need diverse web sources.' Lacks explicit when-not-to-use or alternatives, but context is clear.

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