Skip to main content
Glama

web_search

Search the web with customizable parameters including query, language, site, and engines. Returns relevant results for integration into LLM workflows.

Instructions

Alias of web.search

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
qYes
maxNo
langNo
siteNo
enginesNo
kNo
limitNo

Implementation Reference

  • Main handler function that executes web search across multiple engines (SearXNG and DuckDuckGo), then deduplicates and ranks 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);
    }
  • Input validation schema (Zod) for the web_search tool, defining parameters q, max, lang, site, engines, k, limit.
    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)
    Registration of the 'web_search' tool (alias of 'web.search') on the MCP server with its schema and handler invocation.
    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)
    Registration of the 'web.search' tool (primary name) on the MCP server with its schema and handler invocation.
    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) }] };
      }
    );
  • Deduplicates and ranks search results by URL, ensuring no duplicates and assigning sequential 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 }));
    }
  • Helper function that performs web search via DuckDuckGo HTML scraping.
    async function searchDuckDuckGo(query: string, lang?: string, site?: string, max = 10): Promise<SearchResult[]> {
      const q = encodeURIComponent((site ? `site:${site} ` : '') + query);
      const url = `https://html.duckduckgo.com/html/?q=${q}&kl=${lang || ''}`;
      const res = await fetchWithLimits(url, 8000, 512*1024);
      if (!res.body) return [];
      const html = res.body.toString('utf-8');
      const $ = cheerioLoad(html);
      const items: SearchResult[] = [];
      $('a.result__a').each((i, el) => {
        const a = $(el);
        const title = a.text().trim();
        const href = a.attr('href') || '';
        const snippet = a.closest('.result').find('.result__snippet').text().trim() || '';
        if (href && title) {
          items.push({ title, url: href, snippet, source: 'duckduckgo', rank: i+1 });
        }
      });
      return items.slice(0, max);
    }
  • Helper function that performs web search via SearXNG JSON API.
    async function searchSearxng(query: string, lang?: string, site?: string, max = 10): Promise<SearchResult[]> {
      const endpoints = CONFIG.searxngEndpoints; if (!endpoints.length) return [];
      const q = (site ? `site:${site} ` : '') + query;
      const endpoint = endpoints[Math.floor(Math.random()*endpoints.length)];
      const url = `${endpoint}?q=${encodeURIComponent(q)}&format=json&language=${encodeURIComponent(lang || CONFIG.langDefault)}&safesearch=1`;
      const res = await fetchWithLimits(url, 8000, 1024*1024);
      if (!res.body) return [];
      try {
        const data = JSON.parse(res.body.toString('utf-8'));
        const results = data?.results || [];
        return results.slice(0, max).map((r: any, i: number) => ({
          title: r.title || r.pretty_url || r.url,
          url: r.url, snippet: r.content || r.snippet || '',
          source: 'searxng', rank: i+1
        }));
      } catch { return []; }
    }
Behavior2/5

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

Beyond the annotations (openWorldHint), the description adds no behavioral context. It does not disclose any traits such as authentication needs, rate limits, or side effects.

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

Conciseness2/5

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

The description is extremely short but under-specified. It lacks sufficient information to be useful, thus it is not concise in a meaningful way.

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

Completeness1/5

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

With 7 parameters, no output schema, and zero schema coverage, the description is completely inadequate. It provides no context for usage, parameters, or return values.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, and the description does not mention any parameters. It fails to add meaning beyond the input schema, leaving all parameters unexplained.

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

Purpose2/5

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

The description says 'Alias of web.search', which indicates it is an alias but does not state what the tool does. It is vague and fails to specify the verb and resource clearly. The purpose is implied but not explicit.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It merely states it is an alias, without any context on use cases or when not to use it.

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

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