Skip to main content
Glama

web.search

Perform web searches using multiple search engines to retrieve information from the internet for research and data gathering.

Instructions

Multi-engine web search (SearXNG + DuckDuckGo HTML).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
qYes
maxNo
langNo
siteNo
enginesNo
kNo
limitNo

Implementation Reference

  • Implements the core logic for the web.search tool by querying multiple search engines (SearXNG and DuckDuckGo), deduplicating, and ranking results.
    export async function webSearch(args: { q: string, max?: number, lang?: string, site?: string, engines?: string[] }): Promise<SearchResult[]> { const { q, max = 10, lang = CONFIG.langDefault, site, engines } = args; const order = (engines && engines.length ? engines : CONFIG.engineOrder).filter(Boolean); const tasks: Promise<SearchResult[]>[] = []; for (const eng of order) { if (eng === 'searxng') tasks.push(searchSearxng(q, lang, site, max)); if (eng === 'duckduckgo') tasks.push(searchDuckDuckGo(q, lang, site, max)); } const settled = await Promise.allSettled(tasks); const all: SearchResult[] = []; for (const s of settled) if (s.status === 'fulfilled') all.push(...s.value); if (!all.length) return []; return dedupeAndRank(all, max); }
  • Zod schema for input validation of web.search tool parameters.
    const webSearchShape = { q: z.string(), max: z.number().int().optional(), lang: z.string().optional(), site: z.string().optional(), engines: z.array(z.string()).optional(), // extra names model may invent k: z.number().int().optional(), limit: z.number().int().optional() };
  • src/server.ts:49-55 (registration)
    Registers the 'web.search' tool with MCP server, defining its description, input schema, and handler wrapper.
    server.tool('web.search', 'Multi-engine web search (SearXNG + DuckDuckGo HTML).', webSearchShape, OPEN, async ({ q, max, lang, site, engines, k, limit }) => { const res = await webSearch({ q, max: max ?? k ?? limit, lang, site, engines }); return { content: [{ type: 'text', text: JSON.stringify(res) }] }; } );
  • Type definition for search results returned by web.search.
    export interface SearchResult { title: string; url: string; snippet: string; source: string; rank: number; }
  • Helper function to deduplicate search results by URL and assign ranks.
    function dedupeAndRank(all: SearchResult[], max: number): SearchResult[] { const seen = new Set<string>(); const out: SearchResult[] = []; for (const item of all) { const key = item.url.replace(/^https?:\/\//,'').replace(/^www\./,'').replace(/\/$/,'').toLowerCase(); if (seen.has(key)) continue; seen.add(key); out.push(item); if (out.length >= max) break; } return out.map((it, i) => ({ ...it, rank: i+1 })); }

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/khanhs-234/tool4lm'

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