wiki_search
Search Wikipedia for articles matching a query. Retrieve summaries and links. Optionally specify language for localized results.
Instructions
Alias of wiki.search
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | ||
| lang | No |
Implementation Reference
- src/tools/scholar.ts:4-15 (handler)The core handler function for wiki_search. Fetches Wikipedia title suggestions via the REST API and returns title, url, snippet, and source.
export async function wikiSearch(q: string, lang = 'vi', top = 5) { const url = `https://${lang}.wikipedia.org/w/rest.php/v1/search/title?q=${encodeURIComponent(q)}&limit=${top}`; const res = await fetchWithLimits(url, 8000, 1024*1024); if (!res.body) return []; const data = JSON.parse(res.body.toString('utf-8')); return (data.pages || []).map((p: any) => ({ title: p.title, url: `https://${lang}.wikipedia.org/wiki/${encodeURIComponent(p.key)}`, snippet: p.description || '', source: 'wikipedia' })); } - src/server.ts:201-207 (registration)Registration of the 'wiki_search' tool as an alias for 'wiki.search'. Defines the shape with 'q' (required string) and 'lang' (optional string), and invokes wikiSearch().
server.tool('wiki_search', 'Alias of wiki.search', wikiSearchShape, OPEN, async ({ q, lang }) => { const res = await wikiSearch(q, lang || 'vi'); return { content: [{ type: 'text', text: JSON.stringify(res) }] }; } ); - src/server.ts:193-193 (schema)Input schema for wiki_search: 'q' (required string) and 'lang' (optional string). Shared by both 'wiki.search' and its alias 'wiki_search'.
const wikiSearchShape = { q: z.string(), lang: z.string().optional() }; - src/utils/http.ts:40-79 (helper)The fetchWithLimits utility used by wikiSearch to make HTTP requests with timeout, size limits, and SSRF protection.
export async function fetchWithLimits(urlStr: string, timeoutMs = CONFIG.fetchTimeoutMs, maxBytes = CONFIG.maxFetchBytes) { const u = new URL(urlStr); await assertNotPrivate(u); const controller = new AbortController(); const timer = setTimeout(() => controller.abort(), timeoutMs); try { const res = await request(urlStr, { method: 'GET', headers: { 'user-agent': 'mcp-multitool/0.2', 'accept': '*/*' }, signal: controller.signal, maxRedirections: 3 }); const status = res.statusCode; const headersRec: Record<string, string> = {}; for (const [k, v] of Object.entries(res.headers)) { headersRec[k] = Array.isArray(v) ? v.join(', ') : String(v ?? ''); } if (status >= 400) { return { status, headers: headersRec, body: null as any }; } const chunks: Buffer[] = []; let total = 0; for await (const chunk of res.body) { const b: Buffer = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk as any); total += b.length; if (total > maxBytes) break; chunks.push(b); } const buf = Buffer.concat(chunks); const contentType = headersRec['content-type'] || 'application/octet-stream'; const finalUrl = headersRec['content-location'] || urlStr; return { status, headers: headersRec, body: buf, finalUrl, contentType }; } finally { clearTimeout(timer); } } - src/server.ts:194-200 (registration)Primary registration of 'wiki.search' tool (the canonical name). wiki_search is an alias that delegates to the same handler.
server.tool('wiki.search', 'Wikipedia title search (public API).', wikiSearchShape, OPEN, async ({ q, lang }) => { const res = await wikiSearch(q, lang || 'vi'); return { content: [{ type: 'text', text: JSON.stringify(res) }] }; } );