Skip to main content
Glama

web_search

Search the web for information using customizable parameters like language, site restrictions, and search engines to retrieve relevant results for queries.

Instructions

Alias of web.search

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
qYes
maxNo
langNo
siteNo
enginesNo
kNo
limitNo

Implementation Reference

  • Core handler function for web search using multiple engines (DuckDuckGo HTML scraping and SearXNG JSON API), with deduplication and ranking.
    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 defining input parameters for the web_search tool, including aliases like k and limit for max.
    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:56-62 (registration)
    MCP server registration for the 'web_search' tool, which wraps the webSearch handler.
    server.tool('web_search', 'Alias of web.search', 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) }] }; } );
  • src/server.ts:49-55 (registration)
    Primary MCP server registration for the related 'web.search' tool (web_search is an alias).
    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) }] }; } );
  • Helper function to deduplicate search results by URL domain 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