wiki.search
Search Wikipedia titles to find articles by query and language, enabling quick access to encyclopedia content for research and information retrieval.
Instructions
Wikipedia title search (public API).
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | ||
| lang | No |
Implementation Reference
- src/tools/scholar.ts:4-15 (handler)Core implementation of wikiSearch: queries Wikipedia REST API for title search, parses JSON response, and returns formatted results with 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:193-193 (schema)Zod schema defining input parameters for wiki.search tool: query string 'q' (required) and optional language 'lang'.const wikiSearchShape = { q: z.string(), lang: z.string().optional() };
- src/server.ts:194-200 (registration)Registers the 'wiki.search' tool with server.tool, providing description, schema, and a wrapper handler that calls wikiSearch and formats response as MCP content.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) }] }; } );
- src/server.ts:201-207 (registration)Registers the alias 'wiki_search' tool, identical to 'wiki.search'.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) }] }; } );