Skip to main content
Glama

web.rich

Retrieve detailed web data through Brave Search by enabling callback flow and fetching rich results for specific queries.

Instructions

Brave Rich Search via callback flow. First enables rich callback, then fetches rich data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
qYes

Implementation Reference

  • Handler function that executes the web.rich tool: performs initial web search with rich callback enabled, extracts callback key, fetches rich results, and returns JSON.
    async handler(args) { const first = await braveGet('https://api.search.brave.com/res/v1/web/search', { q: args.q, enable_rich_callback: 1, }); const callbackKey = (first as any)?.rich?.hint?.callback_key; if (!callbackKey) { return { content: [{ type: 'text', text: 'No rich results available for this query.' }] }; } const rich = await braveGet('https://api.search.brave.com/res/v1/web/rich', { callback_key: callbackKey, }); return { content: [{ type: 'text', text: JSON.stringify({ hint: (first as any)?.rich?.hint, rich }) }] }; },
  • Input schema for the web.rich tool, defining a required 'q' query string.
    const richCallbackSchema = { type: 'object', properties: { q: { type: 'string', minLength: 1 } }, required: ['q'], additionalProperties: false, } as const;
  • src/index.ts:122-141 (registration)
    The web.rich tool is registered as part of the toolDefs array, which populates toolList for listing and toolMap for dispatching calls.
    { name: 'web.rich', description: 'Brave Rich Search via callback flow. First enables rich callback, then fetches rich data', inputSchema: richCallbackSchema, async handler(args) { const first = await braveGet('https://api.search.brave.com/res/v1/web/search', { q: args.q, enable_rich_callback: 1, }); const callbackKey = (first as any)?.rich?.hint?.callback_key; if (!callbackKey) { return { content: [{ type: 'text', text: 'No rich results available for this query.' }] }; } const rich = await braveGet('https://api.search.brave.com/res/v1/web/rich', { callback_key: callbackKey, }); return { content: [{ type: 'text', text: JSON.stringify({ hint: (first as any)?.rich?.hint, rich }) }] }; }, }, ];
  • Helper utility braveGet used by web.rich (and other tools) to make authenticated API requests to Brave Search endpoints.
    async function braveGet(url: string, params: Record<string, string | number | boolean | undefined>) { const apiKey = process.env.EARCH_MCP_API_KEY || process.env.BRAVE_API_KEY || process.env.BRAVE_SEARCH_API_KEY; if (!apiKey) { throw new Error('Missing API key. Set EARCH_MCP_API_KEY or BRAVE_API_KEY.'); } const headers: Record<string, string> = { Accept: 'application/json', 'Accept-Encoding': 'gzip', 'X-Subscription-Token': apiKey, }; const usp = new URLSearchParams(); for (const [k, v] of Object.entries(params)) { if (v === undefined) continue; usp.set(k, String(v)); } const endpoint = `${url}?${usp.toString()}`; const res = await fetch(endpoint, { headers }); if (!res.ok) { const body = await res.text().catch(() => ''); throw new Error(`Brave API error ${res.status}: ${body}`); } return res.json(); }
  • src/index.ts:158-172 (registration)
    MCP server request handler for tool calls, which dispatches to the specific tool handler via toolMap (including web.rich).
    server.setRequestHandler(CallToolRequestSchema, async (request) => { const name = request.params.name; const args = request.params.arguments ?? {}; const tool = toolMap.get(name); if (!tool) { return { content: [{ type: 'text', text: `Unknown tool: ${name}` }] } as unknown as typeof CallToolResultSchema._type; } try { const result = await tool.handler(args); return result as unknown as typeof CallToolResultSchema._type; } catch (err: any) { const message = err?.message ?? String(err); return { content: [{ type: 'text', text: `Error: ${message}` }] } as unknown as typeof CallToolResultSchema._type; } });

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

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