Skip to main content
Glama

build_index

Generate a search index for your documents, enabling quick content retrieval. Optionally force a full rebuild.

Instructions

Build search index for docs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
forceNoWhether to force rebuild index

Implementation Reference

  • The tool handler for 'build_index' in the CallToolRequestSchema switch statement. It calls searchEngine.buildIndex(docDir) and returns a response with the count of documents indexed.
    case "build_index": {
      const force = Boolean(request.params.arguments?.force);
      await searchEngine.buildIndex(docDir);
      return {
        content: [{
          type: "text",
          text: `Index built with ${Object.keys(searchEngine['docStore']).length} documents`
        }]
      };
    }
  • The input schema definition for the 'build_index' tool, registered in ListToolsRequestSchema. Defines an optional 'force' property of type boolean.
    {
      name: "build_index",
      description: "Build search index for docs",
      inputSchema: {
        type: "object",
        properties: {
          force: {
            type: "boolean",
            description: "Whether to force rebuild index"
          }
        }
      }
  • src/index.ts:404-531 (registration)
    The duplicate registration of 'build_index' (lines 489-501) in the ListToolsRequestSchema handler, alongside all other tool registrations.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "enable_doc",
            description: "Enable crawling for a specific doc",
            inputSchema: {
              type: "object",
              properties: {
                name: {
                  type: "string",
                  description: "Name of the doc to enable"
                }
              },
              required: ["name"]
            }
          },
          {
            name: "disable_doc",
            description: "Disable crawling for a specific doc",
            inputSchema: {
              type: "object",
              properties: {
                name: {
                  type: "string",
                  description: "Name of the doc to disable"
                }
              },
              required: ["name"]
            }
          },
          {
            name: "crawl_docs",
            description: "Start crawling enabled docs",
            inputSchema: {
              type: "object",
              properties: {
                force: {
                  type: "boolean",
                  description: "Whether to force re-crawl all docs, ignoring previous crawl records"
                }
              }
            }
          },
          {
            name: "build_index",
            description: "Build search index for docs",
            inputSchema: {
              type: "object",
              properties: {
                force: {
                  type: "boolean",
                  description: "Whether to force rebuild index"
                }
              }
            }
          },
          {
            name: "search_docs",
            description: "Search documentation",
            inputSchema: {
              type: "object",
              properties: {
                query: {
                  type: "string",
                  description: "Search query"
                },
                max_results: {
                  type: "number",
                  description: "Maximum number of results",
                  default: 3
                },
                doc_name: {
                  type: "string",
                  description: "Filter by document category"
                },
                offset: {
                  type: "number",
                  description: "Number of results to skip",
                  default: 0
                }
              },
              required: ["query"]
            }
          },
          {
            name: "build_index",
            description: "Build search index for docs",
            inputSchema: {
              type: "object",
              properties: {
                force: {
                  type: "boolean",
                  description: "Whether to force rebuild index"
                }
              }
            }
          },
          {
            name: "list_enabled_docs",
            description: "List all enabled docs with their cache status",
            inputSchema: {
              type: "object",
              properties: {
                verbose: {
                  type: "boolean",
                  description: "Whether to show detailed information",
                  default: false
                }
              }
            }
          },
          {
            name: "list_all_docs",
            description: "List all available docs including disabled ones",
            inputSchema: {
              type: "object",
              properties: {
                verbose: {
                  type: "boolean",
                  description: "Whether to show detailed information",
                  default: false
                }
              }
            }
          }
        ]
      };
  • The actual implementation of the buildIndex method on the SearchEngine class. Collects markdown docs from the docs directory, builds a lunr search index, stores documents, and saves the index to a JSON file.
    async buildIndex(docsDir: string) {
      const docs = await this.collectDocs(docsDir);
      this.index = lunr(function() {
        this.ref('path');
        this.field('title');
        this.field('content');
        
        docs.forEach(doc => {
          this.add(doc);
        });
      });
    
      // Store documents separately
      docs.forEach(doc => {
        this.docStore[doc.path] = doc;
      });
    
      await this.saveIndex();
    }
    
    private async collectDocs(docsDir: string): Promise<DocEntry[]> {
      const docs: DocEntry[] = [];
      const docCategories = await fs.readdir(docsDir);
      
      for (const category of docCategories) {
        const categoryPath = path.join(docsDir, category);
        if ((await fs.stat(categoryPath)).isDirectory()) {
          const files = await fs.readdir(categoryPath);
          
          for (const file of files) {
            if (file.endsWith('.md')) {
              const filePath = path.join(categoryPath, file);
              const content = await fs.readFile(filePath, 'utf-8');
              docs.push({
                path: filePath,
                title: `${category}/${path.basename(file, '.md')}`,
                content
              });
            }
          }
        }
      }
      
      return docs;
    }
    
    private async saveIndex() {
      await fs.writeJson(this.indexPath, {
        version: new Date().toISOString(),
        index: this.index.toJSON(),
        docStore: this.docStore
      });
    }
Behavior2/5

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

No annotations provided, and the description does not disclose any behavioral traits (e.g., destructive potential, permission requirements, effect on existing index). The verb 'build' implies non-destructive creation, but this is insufficient.

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

Conciseness3/5

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

The description is very short (5 words) but lacks any structure or additional context. While concise, it sacrifices completeness for brevity.

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?

Given no annotations, no output schema, and a single optional parameter, the description is too minimal. It fails to explain what happens when the index is built, error conditions, or return values.

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

Parameters3/5

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

The description adds no meaning beyond the input schema, which already describes 'force' as a boolean to force rebuild. Since schema coverage is 100%, a baseline of 3 applies.

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

Purpose4/5

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

The description clearly states 'Build search index for docs', specifying the action and resource. It distinguishes from sibling tools like crawl_docs or search_docs, but lacks nuance like scope of index.

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 tool versus alternatives such as crawl_docs or search_docs. An agent cannot infer prerequisites or context from the description alone.

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/askme765cs/open-docs-mcp'

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