Search Any Topic
gt_searchFetches 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
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | 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 | No | Max tokens to return (default: 8000, max: 20000) |
Implementation Reference
- src/tools/search.ts:1680-1891 (handler)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 })), }, }; }, ); } - src/tools/search.ts:1643-1891 (registration)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); - src/tools/search.ts:10-25 (schema)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})`), }); - src/tools/search.ts:1205-1223 (helper)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); }