index.build
Build a MiniSearch index for documents in a sandbox directory to enable fast text search and retrieval within local files.
Instructions
Build MiniSearch index for documents in sandbox directory.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| root | No |
Implementation Reference
- src/tools/doc.ts:58-76 (handler)Core handler function that builds MiniSearch index: collects eligible files (txt/md/html/pdf), extracts readable text (using pdf-parse, Readability for HTML), constructs index, persists to .cache/index.json.export async function indexBuild(root?: string) { const base = root ? path.resolve(root) : CONFIG.sandboxDir; const files = await collectFiles(base); const docs: DocRecord[] = []; for (const p of files) { const { title, text } = await fileToText(p); docs.push({ id: p, path: p, title, text }); } const mini = new MiniSearch({ fields: ['title','text'], storeFields: ['path','title'], searchOptions: { boost: { title: 2 } } }); mini.addAll(docs); const payload = { docs, index: mini.toJSON() }; await fs.mkdir(path.dirname(INDEX_PATH), { recursive: true }).catch(()=>{}); await fs.writeFile(INDEX_PATH, JSON.stringify(payload)); return { ok: true, indexed: docs.length }; }
- src/server.ts:143-149 (registration)Registers the MCP tool 'index.build' using the indexBuild handler function, with description and input schema.server.tool('index.build', 'Build MiniSearch index for documents in sandbox directory.', indexBuildShape, OPEN, async ({ root }) => { const res = await indexBuild(root); return { content: [{ type: 'text', text: JSON.stringify(res) }] }; } );
- src/server.ts:142-142 (schema)Input schema using Zod: optional 'root' string for the directory to index.const indexBuildShape = { root: z.string().optional() };