Skip to main content
Glama

Search Any Topic

gt_search
Read-only

Fetches live documentation and best practices for any topic, normalized to current year (2026). Works for libraries, web standards, security, accessibility, performance, and more.

Instructions

Search for latest best practices, docs, or guidance on ANY topic — no library name needed.

Current year: 2026. All searches are normalized to fetch 2026 content.

Works for:

  • Library best practices: "latest React patterns", "Next.js server actions"

  • Web standards: "CSS container queries", "WebSocket API", "Fetch API"

  • Security: "OWASP SQL injection prevention", "JWT security best practices", "CSP headers"

  • Accessibility: "WCAG 2.2 focus indicators", "ARIA roles reference"

  • Performance: "Core Web Vitals optimization", "LCP improvements"

  • APIs & protocols: "REST API design", "HTTP/3 vs HTTP/2", "OpenAPI 3.1"

  • Auth standards: "OAuth 2.1 PKCE", "WebAuthn passkeys", "OIDC"

  • Infrastructure: "Docker best practices", "GitHub Actions CI/CD"

  • Anything else: just ask

Say "use ws" or "ws search [topic]" to invoke.

Examples:

  • gt_search({ query: "latest best practices" }) — auto-detects from project context

  • gt_search({ query: "WCAG 2.2 keyboard navigation" })

  • gt_search({ query: "SQL injection prevention 2026" })

  • gt_search({ query: "CSS container queries browser support" })

  • gt_search({ query: "React Server Components patterns" })

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesWhat you want to know. Can be anything: 'latest React best practices', 'WCAG 2.2 focus indicators', 'OWASP SQL injection prevention', 'CSS container queries browser support', 'JWT security', 'HTTP/3 vs HTTP/2', 'Web Workers API'. No library name required.
tokensNoMax tokens to return (default: 8000, max: 20000)

Implementation Reference

  • The main handler function for the gt_search tool. Receives query and tokens, performs multi-stage search: (1) registry lookup, (2) curated topic URL map, (3) direct URL construction, (4) MDN JSON API, (5) DuckDuckGo Instant Answer, (6) web search (DDG/SearXNG/Mojeek), (7) DevDocs fallback, (8) Jina Reader fallback, (9) MDN search fallback. Returns formatted results or a 'no results' message.
        async ({ query: rawQuery, tokens }) => {
          const query = normalizeQueryYear(rawQuery);
          const results: Array<{ source: string; url: string; content: string }> = [];
    
          // 1. Check registry (library-based query)
          const registryMatches = fuzzySearch(query, 3);
          for (const match of registryMatches) {
            const entry = lookupById(match.id);
            if (!entry) continue;
            try {
              const fetchResult = await fetchDocs(entry.docsUrl, entry.llmsTxtUrl, entry.llmsFullTxtUrl);
              const safe = sanitizeContent(fetchResult.content);
              const { text } = extractRelevantContent(safe, query, Math.floor(tokens / 2));
              if (text.length > 200) {
                results.push({
                  source: entry.name,
                  url: fetchResult.url,
                  content: text,
                });
                break; // one registry match is enough for freeform search
              }
            } catch {
              // try next
            }
          }
    
          // 2. Topic map — curated official docs URLs for non-library topics
          const topicMatches = findTopicUrls(query);
          for (const topic of topicMatches) {
            for (const url of topic.urls.slice(0, 2)) {
              const content = await fetchTopicContent(url, query, Math.floor(tokens / (topicMatches.length + 1)));
              if (content.length > 200) {
                results.push({ source: topic.name, url, content });
                break;
              }
            }
            if (results.length >= 3) break;
          }
    
          // 3. Try direct URL construction for common documentation sites
          if (results.length === 0) {
            const directUrls = buildDirectDocsUrls(query);
            if (directUrls.length > 0) {
              const directResults = await Promise.allSettled(
                directUrls.slice(0, 4).map(async (candidate) => {
                  const content = await fetchTopicContent(candidate.url, query, Math.floor(tokens / 2));
                  if (content.length > 200) {
                    return { source: candidate.name, url: candidate.url, content };
                  }
                  throw new Error("no content");
                }),
              );
              for (const result of directResults) {
                if (result.status === "fulfilled") {
                  results.push(result.value);
                  if (results.length >= 2) break;
                }
              }
            }
          }
    
          // 4. MDN JSON API search — free, structured, no scraping needed
          if (results.length === 0) {
            const mdnResults = await searchMDN(query);
            if (mdnResults.length > 0) {
              const mdnFetchResults = await Promise.allSettled(
                mdnResults.slice(0, 3).map(async (mdn) => {
                  const content = await fetchTopicContent(mdn.url, query, Math.floor(tokens / 2));
                  if (content.length > 200) {
                    return { source: `MDN: ${mdn.title}`, url: mdn.url, content };
                  }
                  throw new Error("no content");
                }),
              );
              for (const result of mdnFetchResults) {
                if (result.status === "fulfilled") {
                  results.push(result.value);
                  if (results.length >= 2) break;
                }
              }
            }
          }
    
          // 4b. DuckDuckGo Instant Answer API — free structured JSON, no HTML scraping
          if (results.length === 0) {
            const ddgUrls = await searchDDGInstant(query);
            if (ddgUrls.length > 0) {
              const ddgFetchResults = await Promise.allSettled(
                ddgUrls.slice(0, 3).map(async (url) => {
                  const content = await fetchTopicContent(url, query, Math.floor(tokens / 2));
                  if (content.length > 200) {
                    let source: string;
                    try { source = new URL(url).hostname; } catch { source = url; }
                    return { source, url, content };
                  }
                  throw new Error("no content");
                }),
              );
              for (const result of ddgFetchResults) {
                if (result.status === "fulfilled") {
                  results.push(result.value);
                  if (results.length >= 2) break;
                }
              }
            }
          }
    
          // 5. If still no results, try web search for authoritative URLs then fetch via Jina
          if (results.length === 0) {
            const searchUrls = await webSearch(query);
            // Fetch top 3 search results in parallel for speed
            const searchResults = await Promise.allSettled(
              searchUrls.slice(0, 3).map(async (url) => {
                const content = await fetchTopicContent(url, query, Math.floor(tokens / 2));
                if (content.length > 200) {
                  let source: string;
                  try { source = new URL(url).hostname; } catch { source = url; }
                  return { source, url, content };
                }
                throw new Error("no content");
              }),
            );
            for (const result of searchResults) {
              if (result.status === "fulfilled") {
                results.push(result.value);
                if (results.length >= 2) break;
              }
            }
          }
    
          // 6. Fallback — try DevDocs (pre-parsed docs for 200+ technologies)
          if (results.length === 0) {
            const queryWords = query.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
            const techSlug = queryWords[0] ?? query.split(" ")[0] ?? "";
            if (techSlug) {
              const devDocsContent = await fetchDevDocs(techSlug, query);
              if (devDocsContent && devDocsContent.length > 200) {
                const safe = sanitizeContent(devDocsContent);
                const { text } = extractRelevantContent(safe, query, tokens);
                if (text.length > 200) {
                  results.push({
                    source: `DevDocs (${techSlug})`,
                    url: `https://devdocs.io/${techSlug}/`,
                    content: text,
                  });
                }
              }
            }
          }
    
          // 7. Fallback — try Jina Reader directly on the query as a URL-like topic
          if (results.length === 0) {
            const jinaDirectUrls = buildJinaFallbackUrls(query);
            for (const candidate of jinaDirectUrls.slice(0, 2)) {
              const content = await fetchTopicContent(candidate.url, query, tokens);
              if (content.length > 200) {
                results.push({ source: candidate.name, url: candidate.url, content });
                break;
              }
            }
          }
    
          // 8. Fallback — try fetching MDN search
          if (results.length === 0) {
            const mdnSearch = `https://developer.mozilla.org/en-US/search?q=${encodeURIComponent(query)}`;
            const content = await fetchTopicContent(mdnSearch, query, tokens);
            if (content.length > 200) {
              results.push({ source: "MDN Web Docs", url: mdnSearch, content });
            }
          }
    
          if (results.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: [
                    `No results found for: "${query}"`,
                    "",
                    "**What to try next:**",
                    "- Be more specific (e.g. 'React hooks best practices' instead of 'React')",
                    "- Include the library name + topic (e.g. 'Next.js middleware authentication')",
                    "- Try gt_resolve_library to find a specific library, then gt_get_docs",
                    "- Try gt_get_docs with a direct URL as the libraryId",
                  ].join("\n"),
                },
              ],
            };
          }
    
          const header = [
            `# Search: ${query}`,
            `> Found ${results.length} source${results.length > 1 ? "s" : ""}`,
            "",
            "---",
            "",
          ].join("\n");
    
          const body = results
            .map((r) => `## ${r.source}\n> Source: ${r.url}\n\n${r.content}\n\n---\n`)
            .join("\n");
    
          return {
            content: [{ type: "text", text: header + body }],
            structuredContent: {
              query,
              sources: results.map((r) => ({ name: r.source, url: r.url, content: r.content })),
            },
          };
        },
      );
    }
  • The registerSearchTool function that registers 'gt_search' as an MCP tool on the McpServer with title, description, inputSchema, annotations, and the handler function.
    export function registerSearchTool(server: McpServer): void {
      const currentYear = new Date().getFullYear();
      server.registerTool(
        "gt_search",
        {
          title: "Search Any Topic",
          description: `Search for latest best practices, docs, or guidance on ANY topic — no library name needed.
    
    Current year: ${currentYear}. All searches are normalized to fetch ${currentYear} content.
    
    Works for:
    - Library best practices: "latest React patterns", "Next.js server actions"
    - Web standards: "CSS container queries", "WebSocket API", "Fetch API"
    - Security: "OWASP SQL injection prevention", "JWT security best practices", "CSP headers"
    - Accessibility: "WCAG 2.2 focus indicators", "ARIA roles reference"
    - Performance: "Core Web Vitals optimization", "LCP improvements"
    - APIs & protocols: "REST API design", "HTTP/3 vs HTTP/2", "OpenAPI 3.1"
    - Auth standards: "OAuth 2.1 PKCE", "WebAuthn passkeys", "OIDC"
    - Infrastructure: "Docker best practices", "GitHub Actions CI/CD"
    - Anything else: just ask
    
    Say "use ws" or "ws search [topic]" to invoke.
    
    Examples:
    - gt_search({ query: "latest best practices" }) — auto-detects from project context
    - gt_search({ query: "WCAG 2.2 keyboard navigation" })
    - gt_search({ query: "SQL injection prevention ${currentYear}" })
    - gt_search({ query: "CSS container queries browser support" })
    - gt_search({ query: "React Server Components patterns" })`,
          inputSchema: InputSchema,
          annotations: {
            readOnlyHint: true,
            destructiveHint: false,
            idempotentHint: false,
            openWorldHint: true,
          },
        },
        async ({ query: rawQuery, tokens }) => {
          const query = normalizeQueryYear(rawQuery);
          const results: Array<{ source: string; url: string; content: string }> = [];
    
          // 1. Check registry (library-based query)
          const registryMatches = fuzzySearch(query, 3);
          for (const match of registryMatches) {
            const entry = lookupById(match.id);
            if (!entry) continue;
            try {
              const fetchResult = await fetchDocs(entry.docsUrl, entry.llmsTxtUrl, entry.llmsFullTxtUrl);
              const safe = sanitizeContent(fetchResult.content);
              const { text } = extractRelevantContent(safe, query, Math.floor(tokens / 2));
              if (text.length > 200) {
                results.push({
                  source: entry.name,
                  url: fetchResult.url,
                  content: text,
                });
                break; // one registry match is enough for freeform search
              }
            } catch {
              // try next
            }
          }
    
          // 2. Topic map — curated official docs URLs for non-library topics
          const topicMatches = findTopicUrls(query);
          for (const topic of topicMatches) {
            for (const url of topic.urls.slice(0, 2)) {
              const content = await fetchTopicContent(url, query, Math.floor(tokens / (topicMatches.length + 1)));
              if (content.length > 200) {
                results.push({ source: topic.name, url, content });
                break;
              }
            }
            if (results.length >= 3) break;
          }
    
          // 3. Try direct URL construction for common documentation sites
          if (results.length === 0) {
            const directUrls = buildDirectDocsUrls(query);
            if (directUrls.length > 0) {
              const directResults = await Promise.allSettled(
                directUrls.slice(0, 4).map(async (candidate) => {
                  const content = await fetchTopicContent(candidate.url, query, Math.floor(tokens / 2));
                  if (content.length > 200) {
                    return { source: candidate.name, url: candidate.url, content };
                  }
                  throw new Error("no content");
                }),
              );
              for (const result of directResults) {
                if (result.status === "fulfilled") {
                  results.push(result.value);
                  if (results.length >= 2) break;
                }
              }
            }
          }
    
          // 4. MDN JSON API search — free, structured, no scraping needed
          if (results.length === 0) {
            const mdnResults = await searchMDN(query);
            if (mdnResults.length > 0) {
              const mdnFetchResults = await Promise.allSettled(
                mdnResults.slice(0, 3).map(async (mdn) => {
                  const content = await fetchTopicContent(mdn.url, query, Math.floor(tokens / 2));
                  if (content.length > 200) {
                    return { source: `MDN: ${mdn.title}`, url: mdn.url, content };
                  }
                  throw new Error("no content");
                }),
              );
              for (const result of mdnFetchResults) {
                if (result.status === "fulfilled") {
                  results.push(result.value);
                  if (results.length >= 2) break;
                }
              }
            }
          }
    
          // 4b. DuckDuckGo Instant Answer API — free structured JSON, no HTML scraping
          if (results.length === 0) {
            const ddgUrls = await searchDDGInstant(query);
            if (ddgUrls.length > 0) {
              const ddgFetchResults = await Promise.allSettled(
                ddgUrls.slice(0, 3).map(async (url) => {
                  const content = await fetchTopicContent(url, query, Math.floor(tokens / 2));
                  if (content.length > 200) {
                    let source: string;
                    try { source = new URL(url).hostname; } catch { source = url; }
                    return { source, url, content };
                  }
                  throw new Error("no content");
                }),
              );
              for (const result of ddgFetchResults) {
                if (result.status === "fulfilled") {
                  results.push(result.value);
                  if (results.length >= 2) break;
                }
              }
            }
          }
    
          // 5. If still no results, try web search for authoritative URLs then fetch via Jina
          if (results.length === 0) {
            const searchUrls = await webSearch(query);
            // Fetch top 3 search results in parallel for speed
            const searchResults = await Promise.allSettled(
              searchUrls.slice(0, 3).map(async (url) => {
                const content = await fetchTopicContent(url, query, Math.floor(tokens / 2));
                if (content.length > 200) {
                  let source: string;
                  try { source = new URL(url).hostname; } catch { source = url; }
                  return { source, url, content };
                }
                throw new Error("no content");
              }),
            );
            for (const result of searchResults) {
              if (result.status === "fulfilled") {
                results.push(result.value);
                if (results.length >= 2) break;
              }
            }
          }
    
          // 6. Fallback — try DevDocs (pre-parsed docs for 200+ technologies)
          if (results.length === 0) {
            const queryWords = query.toLowerCase().split(/\s+/).filter((w) => w.length > 2);
            const techSlug = queryWords[0] ?? query.split(" ")[0] ?? "";
            if (techSlug) {
              const devDocsContent = await fetchDevDocs(techSlug, query);
              if (devDocsContent && devDocsContent.length > 200) {
                const safe = sanitizeContent(devDocsContent);
                const { text } = extractRelevantContent(safe, query, tokens);
                if (text.length > 200) {
                  results.push({
                    source: `DevDocs (${techSlug})`,
                    url: `https://devdocs.io/${techSlug}/`,
                    content: text,
                  });
                }
              }
            }
          }
    
          // 7. Fallback — try Jina Reader directly on the query as a URL-like topic
          if (results.length === 0) {
            const jinaDirectUrls = buildJinaFallbackUrls(query);
            for (const candidate of jinaDirectUrls.slice(0, 2)) {
              const content = await fetchTopicContent(candidate.url, query, tokens);
              if (content.length > 200) {
                results.push({ source: candidate.name, url: candidate.url, content });
                break;
              }
            }
          }
    
          // 8. Fallback — try fetching MDN search
          if (results.length === 0) {
            const mdnSearch = `https://developer.mozilla.org/en-US/search?q=${encodeURIComponent(query)}`;
            const content = await fetchTopicContent(mdnSearch, query, tokens);
            if (content.length > 200) {
              results.push({ source: "MDN Web Docs", url: mdnSearch, content });
            }
          }
    
          if (results.length === 0) {
            return {
              content: [
                {
                  type: "text",
                  text: [
                    `No results found for: "${query}"`,
                    "",
                    "**What to try next:**",
                    "- Be more specific (e.g. 'React hooks best practices' instead of 'React')",
                    "- Include the library name + topic (e.g. 'Next.js middleware authentication')",
                    "- Try gt_resolve_library to find a specific library, then gt_get_docs",
                    "- Try gt_get_docs with a direct URL as the libraryId",
                  ].join("\n"),
                },
              ],
            };
          }
    
          const header = [
            `# Search: ${query}`,
            `> Found ${results.length} source${results.length > 1 ? "s" : ""}`,
            "",
            "---",
            "",
          ].join("\n");
    
          const body = results
            .map((r) => `## ${r.source}\n> Source: ${r.url}\n\n${r.content}\n\n---\n`)
            .join("\n");
    
          return {
            content: [{ type: "text", text: header + body }],
            structuredContent: {
              query,
              sources: results.map((r) => ({ name: r.source, url: r.url, content: r.content })),
            },
          };
        },
      );
    }
  • src/index.ts:68-79 (registration)
    Registration call in the main index file: registerSearchTool(server) is called to register the gt_search tool on the MCP server.
    registerResolveTool(server);
    registerDocsTool(server);
    registerBestPracticesTool(server);
    registerAutoScanTool(server);
    registerSearchTool(server);
    registerAuditTool(server);
    registerChangelogTool(server);
    registerCompatTool(server);
    registerCompareTool(server);
    registerExamplesTool(server);
    registerMigrationTool(server);
    registerBatchResolveTool(server);
  • Input schema (InputSchema) for gt_search: validates 'query' (string 1-500 chars) and optional 'tokens' (number, default 8192, max 32000) using Zod.
    const InputSchema = z.object({
      query: z
        .string()
        .min(1)
        .max(500)
        .describe(
          "What you want to know. Can be anything: 'latest React best practices', 'WCAG 2.2 focus indicators', 'OWASP SQL injection prevention', 'CSS container queries browser support', 'JWT security', 'HTTP/3 vs HTTP/2', 'Web Workers API'. No library name required.",
        ),
      tokens: z
        .number()
        .int()
        .min(1000)
        .max(MAX_TOKEN_LIMIT)
        .default(DEFAULT_TOKEN_LIMIT)
        .describe(`Max tokens to return (default: ${DEFAULT_TOKEN_LIMIT}, max: ${MAX_TOKEN_LIMIT})`),
    });
  • findTopicUrls() helper that matches a query against the curated TOPIC_URL_MAP to find relevant documentation URLs for non-library topics (security, accessibility, CSS, performance, etc.).
    export function findTopicUrls(query: string): Array<{ urls: string[]; name: string }> {
      const q = query.toLowerCase();
      const matches: Array<{ urls: string[]; name: string; score: number }> = [];
    
      for (const topic of TOPIC_URL_MAP) {
        let score = 0;
        for (const pattern of topic.patterns) {
          if (matchesPattern(q, pattern)) {
            score += pattern.split(" ").length; // longer matches score higher
          }
        }
        if (score > 0) {
          matches.push({ ...topic, score });
        }
      }
    
      matches.sort((a, b) => b.score - a.score);
      return matches.slice(0, 3);
    }
Behavior3/5

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

Annotations already declare readOnlyHint and destructiveHint. The description adds that searches are normalized to 2026 content, which is useful. But it does not elaborate on idempotency or the implications of openWorldHint. The description adds marginal value over annotations.

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

Conciseness4/5

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

The description is well-structured with an opening statement, bullet lists, and examples. It is front-loaded but slightly verbose due to multiple examples. Could be trimmed without losing clarity.

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

Completeness5/5

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

For a simple search tool with full schema coverage and annotations, the description is complete. It explains the year normalization, scope, and provides numerous examples. No output schema is present, but the openWorldHint explains variability.

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

Parameters3/5

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

Schema coverage is 100%, so the schema already documents both parameters. The description provides many query examples but does not add new meaning beyond the schema’s description for 'query' and 'tokens'.

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

Purpose5/5

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

The description clearly states the tool's purpose: search for latest best practices, docs, or guidance on any topic. It provides extensive examples across domains and distinguishes it from sibling tools like gt_best_practices or gt_get_docs by emphasizing no library name needed.

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

Usage Guidelines4/5

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

The description gives clear context on when to use the tool (any topic, various domains) and includes invocation hints. However, it does not explicitly state when not to use it or mention alternatives like gt_get_docs for library-specific docs, leaving some ambiguity.

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/rm-rf-prod/ws-mcp'

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