Skip to main content
Glama

brave_web_search

Search the web using Brave Search API to gather diverse results, track recent events, or explore broad topics. Supports up to 20 results per query with pagination options.

Instructions

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

Input Schema

NameRequiredDescriptionDefault
countNoThe number of results to return, minimum 1, maximum 20
offsetNoThe offset for pagination, minimum 0
queryYesThe term to search the internet for

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "count": { "default": 10, "description": "The number of results to return, minimum 1, maximum 20", "maximum": 20, "minimum": 1, "type": "number" }, "offset": { "default": 0, "description": "The offset for pagination, minimum 0", "minimum": 0, "type": "number" }, "query": { "description": "The term to search the internet for", "type": "string" } }, "required": [ "query" ], "type": "object" }

Implementation Reference

  • The executeCore method implements the core logic of the brave_web_search tool, performing the web search via BraveSearch API, processing results, and returning formatted text content.
    public async executeCore(input: z.infer<typeof webSearchInputSchema>) { const { query, count, offset, freshness } = input; const results = await this.braveSearch.webSearch(query, { count, offset, safesearch: SafeSearchLevel.Strict, ...(freshness ? { freshness } : {}), }); if (!results.web || results.web?.results.length === 0) { this.braveMcpServer.log(`No results found for "${query}"`); const text = `No results found for "${query}"`; return { content: [{ type: 'text' as const, text }] }; } const text = results.web.results.map(result => `Title: ${result.title}\nURL: ${result.url}\nDescription: ${result.description}`).join('\n\n'); return { content: [{ type: 'text' as const, text }] }; }
  • Zod input schema defining parameters for the brave_web_search tool: query, count, offset, and freshness.
    const webSearchInputSchema = z.object({ query: z.string().describe('The term to search the internet for'), count: z.number().min(1).max(20).default(10).optional().describe('The number of results to return, minimum 1, maximum 20'), offset: z.number().min(0).default(0).optional().describe('The offset for pagination, minimum 0'), freshness: z.union([ z.enum(['pd', 'pw', 'pm', 'py']), z.string().regex(/^\d{4}-\d{2}-\d{2}to\d{4}-\d{2}-\d{2}$/, 'Date range must be in format YYYY-MM-DDtoYYYY-MM-DD') ]) .optional() .describe( `Filters search results by when they were discovered. The following values are supported: - pd: Discovered within the last 24 hours. - pw: Discovered within the last 7 Days. - pm: Discovered within the last 31 Days. - py: Discovered within the last 365 Days. - YYYY-MM-DDtoYYYY-MM-DD: Custom date range (e.g., 2022-04-01to2022-07-30)`, ), });
  • src/server.ts:52-57 (registration)
    Registration of the brave_web_search tool with the MCP server using server.tool(), binding the tool's name, description, input schema, and execute method.
    this.server.tool( this.webSearchTool.name, this.webSearchTool.description, this.webSearchTool.inputSchema.shape, this.webSearchTool.execute.bind(this.webSearchTool), );
  • src/server.ts:37-37 (registration)
    Instantiation of the BraveWebSearchTool instance used for the brave_web_search tool.
    this.webSearchTool = new BraveWebSearchTool(this, this.braveSearch);
  • The BraveWebSearchTool class definition, including name 'brave_web_search', description, inputSchema, constructor, and executeCore handler method.
    export class BraveWebSearchTool extends BaseTool<typeof webSearchInputSchema, any> { public readonly name = 'brave_web_search'; public readonly description = 'Performs a web search using the Brave Search API, ideal for general queries, and online content. ' + 'Use this for broad information gathering, recent events, or when you need diverse web sources. ' + 'Maximum 20 results per request '; public readonly inputSchema = webSearchInputSchema; constructor(private braveMcpServer: BraveMcpServer, private braveSearch: BraveSearch) { super(); } public async executeCore(input: z.infer<typeof webSearchInputSchema>) { const { query, count, offset, freshness } = input; const results = await this.braveSearch.webSearch(query, { count, offset, safesearch: SafeSearchLevel.Strict, ...(freshness ? { freshness } : {}), }); if (!results.web || results.web?.results.length === 0) { this.braveMcpServer.log(`No results found for "${query}"`); const text = `No results found for "${query}"`; return { content: [{ type: 'text' as const, text }] }; } const text = results.web.results.map(result => `Title: ${result.title}\nURL: ${result.url}\nDescription: ${result.description}`).join('\n\n'); return { content: [{ type: 'text' as const, text }] }; }

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/mikechao/brave-search-mcp'

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