Skip to main content
Glama

index_build

Build a searchable index from a root directory, enabling local LLMs to retrieve documents for context-aware responses.

Instructions

Alias of index.build

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rootNo

Implementation Reference

  • The core handler function for indexBuild. It collects text files (.txt, .md, .html, .pdf) from the sandbox directory (or a given root), reads each file's content, creates a MiniSearch full-text index, and persists the index 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 };
    }
  • Schema definition for index.build / index_build: accepts an optional 'root' string parameter.
    const indexBuildShape = { root: z.string().optional() };
  • src/server.ts:143-149 (registration)
    Registration of the 'index.build' tool (dotted name) on the MCP server, mapping to 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) }] };
      }
    );
  • src/server.ts:150-156 (registration)
    Registration of the 'index_build' alias (underscore name) on the MCP server, also mapping to the indexBuild handler.
    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) }] };
      }
    );
  • Helper function collectFiles: recursively walks a directory and collects file paths matching .txt, .md, .html, or .pdf extensions.
    async function collectFiles(root: string): Promise<string[]> {
      const out: string[] = [];
      async function walk(dir: string) {
        const ents = await fs.readdir(dir, { withFileTypes: true });
        for (const e of ents) {
          const p = path.join(dir, e.name);
          if (e.isDirectory()) await walk(p);
          else if (/(\.txt|\.md|\.html?|\.pdf)$/i.test(e.name)) out.push(p);
        }
      }
      await walk(root);
      return out;
    }
  • Helper function fileToText: reads a file and extracts its title and text content, handling .pdf (via pdf-parse), .html (via JSDOM + Readability), and plain text files.
    async function fileToText(p: string): Promise<{ title: string, text: string }> {
      const buf = await fs.readFile(p);
      const name = path.basename(p);
      if (/\.pdf$/i.test(p)) {
        try { const parsed = await pdfParseLazy(buf as unknown as Buffer); return { title: name, text: parsed.text || '' }; }
        catch { return { title: name, text: '' }; }
      }
      const s = buf.toString('utf-8');
      if (/\.html?$/i.test(p)) {
        const dom = new JSDOM(s, { url: 'file://' + p });
        const reader = new Readability(dom.window.document);
        const art = reader.parse();
        return { title: art?.title || name, text: art?.textContent || dom.window.document.body.textContent || s };
      }
      return { title: name, text: s };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotation includes openWorldHint but description adds no behavioral detail. No mention of side effects, permissions, or output.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is very short but at the expense of informativeness. It is under-specified, not concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple tool with one parameter and no output schema, the description still fails to explain the tool's purpose or parameter meaning.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters1/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The sole parameter 'root' is undocumented. With 0% schema description coverage, the description should add meaning but does not.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

Description says 'Alias of index.build' but does not state what the tool does. It relies on the user knowing index.build, so purpose is unclear.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use this alias versus index.build or other sibling tools. No context for selection.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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