doc.find
Search and retrieve documents from a local sandbox directory. Automatically builds search index when needed to find relevant files based on queries.
Instructions
Search local documents within sandbox directory. Builds index if missing.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | ||
| top | No | ||
| limit | No |
Implementation Reference
- src/tools/doc.ts:85-99 (handler)Core handler for 'doc.find': loads/builds MiniSearch index of sandbox docs (txt/md/html/pdf), searches with fuzzy prefix matching boosted on title, extracts snippets around query.export async function docFind(q: string, top = 5) { let idx = loadIndex(); if (!idx) { await indexBuild(CONFIG.sandboxDir); idx = loadIndex(); } if (!idx) return []; const res = idx.mini.search(q, { prefix: true, fuzzy: 0.2, boost: { title: 2 } }).slice(0, top); return res.map((r: any) => { const doc = idx.docs.find(d => d.id === r.id)!; const text = doc.text || ''; const i = text.toLowerCase().indexOf(q.toLowerCase()); const start = Math.max(0, i - 80); const end = Math.min(text.length, i + 80); const snippet = text.slice(start, end).replace(/\s+/g, ' '); return { path: doc.path, score: r.score, snippet }; }); }
- src/server.ts:104-108 (schema)Zod input schema for doc.find tool parameters.const docFindShape = { q: z.string(), top: z.number().int().optional(), limit: z.number().int().optional() };
- src/server.ts:109-115 (registration)MCP server tool registration for 'doc.find', wrapping docFind handler with MCP response format.server.tool('doc.find', 'Search local documents within sandbox directory. Builds index if missing.', docFindShape, OPEN, async ({ q, top, limit }) => { const res = await docFind(q, top ?? limit ?? 5); return { content: [{ type: 'text', text: JSON.stringify(res) }] }; } );