Skip to main content
Glama
rodhayl
by rodhayl

index_symbols

Build an in-memory symbol index for cross-file lookups to enable symbol-aware code analysis and workspace exploration.

Instructions

Build in-memory symbol index for cross-file lookups.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
rootYesRoot directory to index
languagesNoLanguages to index
symbolTypesNoSymbol types to include

Implementation Reference

  • The `indexSymbols` method within the `SymbolIndexer` class performs the indexing logic by scanning the source directory for files, parsing them based on language-specific regex patterns, and caching the results for efficiency.
    indexSymbols(
      root: string,
      options: {
        languages?: string[];
        symbolTypes?: string[];
      } = {}
    ): IndexSymbolsResult {
      const startTime = performance.now();
      const resolvedRoot = this.config.resolveWorkspacePath(root);
    
      if (!this.config.isPathAllowed(resolvedRoot)) {
        throw new Error(`Access denied: Path '${root}' is not in the allowlist`);
      }
    
      const languages = options.languages || ['typescript', 'javascript', 'python'];
    
      // Build language extensions set for filtering
      const langExtensions = new Set<string>();
      for (const lang of languages) {
        const exts = this.languageExtensions[lang];
        if (exts) {
          exts.forEach((ext) => langExtensions.add(ext));
        }
      }
    
      // Check cache - but we still need to filter by language
      const cacheKey = resolvedRoot;
      const cached = this.cache.get(cacheKey);
      if (cached && Date.now() - cached.timestamp < this.cacheTTL) {
        // Filter cached results by language and symbol types
        let symbols = cached.symbols;
    
        // Filter by language
        symbols = symbols.filter((s) => {
          const ext = extname(s.file).toLowerCase();
          return langExtensions.has(ext);
        });
    
        // Filter by symbol types
        if (options.symbolTypes?.length) {
          symbols = symbols.filter((s) => options.symbolTypes!.includes(s.type));
        }
        return {
          indexed: symbols.length,
          symbols,
          indexDuration: 0,
          languages,
        };
      }
    
      // For non-cached case, find and index files
      const files = this.findSourceFiles(resolvedRoot, ['typescript', 'javascript', 'python']); // Always scan all
      const allSymbols: SymbolInfo[] = [];
      const detectedLanguages = new Set<string>();
    
      for (const filePath of files) {
        try {
          const language = this.getLanguage(filePath);
          if (!language) continue;
    
          const content = readFileSync(filePath, 'utf-8');
          const symbols = this.extractSymbols(content, filePath, language);
          allSymbols.push(...symbols);
          if (symbols.length > 0) {
            detectedLanguages.add(language);
          }
        } catch {
          // Skip files we can't read
        }
      }
    
      // Cache the unfiltered results (all languages)
      this.cache.set(cacheKey, {
        symbols: allSymbols,
        timestamp: Date.now(),
        root: resolvedRoot,
      });
    
      // Now filter by requested languages and symbol types
      let filteredSymbols = allSymbols.filter((s) => {
        const ext = extname(s.file).toLowerCase();
        return langExtensions.has(ext);
      });
    
      if (options.symbolTypes?.length) {
        filteredSymbols = filteredSymbols.filter((s) => options.symbolTypes!.includes(s.type));
      }
    
      const duration = Math.max(0.001, performance.now() - startTime);
    
      return {
        indexed: filteredSymbols.length,
        symbols: filteredSymbols,
        indexDuration: duration,
        languages: Array.from(detectedLanguages).filter((lang) => languages.includes(lang)),
      };
    }
Behavior3/5

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

Mentions 'in-memory' which is crucial behavioral context given no annotations, indicating RAM-based storage. However, lacks details on index lifecycle (session duration, idempotency, replacement vs. additive), performance characteristics, or whether it blocks during execution.

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

Conciseness5/5

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

Single sentence with zero waste. Front-loaded with action verb, efficiently communicates mechanism and purpose without redundancy.

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

Completeness3/5

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

Appropriate for a 3-parameter tool with full schema coverage, but gaps remain regarding state management (no output schema or annotations provided). Missing guidance on index persistence and integration with the broader analysis workflow.

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?

Schema description coverage is 100% (all 3 parameters documented), establishing baseline 3. Description does not add parameter-specific semantics, but none are required given comprehensive schema documentation.

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?

Clear verb ('Build') and resource ('in-memory symbol index') with explicit use case ('for cross-file lookups'). Distinguishes from text search tools in sibling list, though does not explicitly name which sibling consumes this 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?

Provides no guidance on when to invoke this versus siblings like 'cross_file_links' or 'search', nor does it state prerequisites (e.g., whether this must be called before querying tools) or when NOT to use it.

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/rodhayl/mcpLocalHelper'

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