Skip to main content
Glama

index_build

Create and manage search indexes for local LLMs by specifying root directories. Simplify information retrieval and enhance document accessibility within the TOOL4LM server environment.

Instructions

Alias of index.build

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rootNo

Implementation Reference

  • The core handler function `indexBuild` that scans the specified root directory (or sandbox default), extracts text from supported files (txt, md, html, pdf), builds a MiniSearch index, and saves it 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:150-156 (registration)
    Registration of the 'index_build' tool (alias), which invokes the `indexBuild` handler with the optional `root` parameter.
    server.tool('index_build', 'Alias of index.build', indexBuildShape, OPEN, async ({ root }) => { const res = await indexBuild(root); return { content: [{ type: 'text', text: JSON.stringify(res) }] }; } );
  • Zod schema defining the input for indexBuild tools: optional `root` directory path.
    const indexBuildShape = { root: z.string().optional() };
  • src/server.ts:143-149 (registration)
    Primary registration of the 'index.build' tool, which the 'index_build' alias references; invokes the `indexBuild` handler.
    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) }] }; } );

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