Skip to main content
Glama

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
NameRequiredDescriptionDefault
rootNo

Implementation Reference

  • 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) }] }; } );
  • Input schema using Zod: optional 'root' string for the directory to index.
    const indexBuildShape = { root: z.string().optional() };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/khanhs-234/tool4lm'

If you have feedback or need assistance with the MCP directory API, please join our Discord server