Skip to main content
Glama
transparentlyok

MCP Context Manager

index_repository

Index or re-index a repository to enable code navigation and retrieval tools. Uses cached index for unchanged files to reduce token usage when querying specific code symbols.

Instructions

🔧 REQUIRED FIRST STEP: Index or re-index the repository to enable all context-manager tools. Uses cached index if files haven't changed. ALWAYS call this when starting work on a repository or if files have changed significantly. Fast (<2s for most repos).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathNoPath to repository root. Default: process.cwd()
forceReindexNoForce re-indexing even if cache is available. Default: false

Implementation Reference

  • The handler for the index_repository tool which parses the arguments and calls the indexer.indexRepository method.
    case 'index_repository': {
      const path = (args as any).path || process.cwd();
      const forceReindex = (args as any).forceReindex || false;
      await indexer.indexRepository(path, forceReindex);
      return {
        content: [
          {
            type: 'text',
            text: `Repository indexed successfully.\nFiles: ${indexer.getStats().totalFiles}\nSymbols: ${indexer.getStats().totalSymbols}`,
          },
        ],
      };
  • src/index.ts:126-142 (registration)
    The definition of the index_repository tool in the tools array.
    {
      name: 'index_repository',
      description: '🔧 REQUIRED FIRST STEP: Index or re-index the repository to enable all context-manager tools. Uses cached index if files haven\'t changed. ALWAYS call this when starting work on a repository or if files have changed significantly. Fast (<2s for most repos).',
      inputSchema: {
        type: 'object',
        properties: {
          path: {
            type: 'string',
            description: 'Path to repository root. Default: process.cwd()',
          },
          forceReindex: {
            type: 'boolean',
            description: 'Force re-indexing even if cache is available. Default: false',
          },
        },
      },
    },
  • The implementation of indexRepository in the Indexer class, which handles the actual indexing logic.
    async indexRepository(rootPath: string, forceReindex: boolean = false): Promise<void> {
      this.rootPath = rootPath;
    
      // Try to load from cache if not forcing re-index
      if (!forceReindex) {
        const loaded = await this.loadFromCache(rootPath);
        if (loaded) {
          console.error(`Loaded from cache: ${this.index.size} files with ${this.getTotalSymbols()} symbols`);
          return;
        }
      }
    
      // Clear existing index
      this.index.clear();
      this.symbolMap.clear();
    
      // Load ignore patterns
      await this.loadIgnorePatterns();
    
      // Index all files
      await this.indexDirectory(rootPath);
    
      console.error(`Indexed ${this.index.size} files with ${this.getTotalSymbols()} symbols`);
    
      // Save to cache
      await this.saveToCache(rootPath);
    }
    
    private async loadIgnorePatterns(): Promise<void> {
      const gitignorePath = path.join(this.rootPath, '.gitignore');
    
      // Default patterns
      this.ignorePatterns = [
        'node_modules',
        '.git',
        'dist',
        'build',
        'coverage',
        '.next',
        '.nuxt',
        'out',
        '.cache',
        '*.min.js',
        '*.map',
        'package-lock.json',
        'yarn.lock',
        'pnpm-lock.yaml',
      ];
    
      try {
        const gitignore = await fs.readFile(gitignorePath, 'utf-8');
        const lines = gitignore
          .split('\n')

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/transparentlyok/mcp-context-manager'

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