Skip to main content
Glama

index_codebase

Create a searchable index from code and documentation to enable semantic search and cross-references across your codebase.

Instructions

YOU MUST CALL THIS TOOL FIRST before using search_code or search_docs. Use this tool to build the searchable index that powers all other code intelligence features.

TRIGGER: Call this tool immediately when:

  • Starting a new session with this codebase

  • search_code or search_docs returns empty or unexpected results

  • You haven't indexed recently or files have been modified

  • User asks about code structure, definitions, or documentation

This tool performs TWO critical operations:

  1. CODE INDEXING: Uses tree-sitter for language-agnostic AST extraction (Python, JavaScript/TypeScript, Java, Kotlin, Go, Rust, C/C++, Ruby, and more). Extracts functions, classes, methods, variables, and cross-references.

  2. DOCUMENTATION INDEXING: Parses markdown files, READMEs, and extracts docstrings from indexed code. Generates embeddings for semantic search.

IMPORTANT ADVANTAGES over built-in file search:

  • Creates persistent structural knowledge (AST-based, not just text)

  • Enables semantic search via vector embeddings

  • Builds cross-reference graphs for "find all usages" queries

  • Incremental indexing: unchanged files are automatically skipped

  • PARALLEL PROCESSING: Uses thread pool for faster indexing

Do NOT use this tool for:

  • Non-code files (images, binaries, data files)

  • Single-file lookups (use search_code after indexing)

  • Git history queries (use search_history instead)

Args: directory: The root directory to index. Must be a valid path. cpu: If True, force CPU-only mode for embedding generation. Use this when GPU memory is unavailable or constrained (CUDA OOM). Default is False (auto-detect best device: CUDA > MPS > CPU). Set CODE_MEMORY_DEVICE env var to override ('cuda', 'mps', 'cpu', or 'auto').

Returns: Summary with files_indexed, total_symbols, total_chunks, and details.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cpuNo
directoryYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes
Behavior4/5

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

With no annotations, the description carries full burden. It details two operations (code indexing with AST, documentation indexing with embeddings), incremental indexing, parallel processing, and advantages over file search. It could mention potential time or resource consumption for large repos, but overall provides rich behavioral context.

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

Conciseness4/5

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

The description is relatively long but well-structured with front-loaded key instruction, bullet points, and a clear 'do not use' section. Every part adds value, though minor trimming is possible.

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

Completeness5/5

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

Given the tool's complexity and the presence of an output schema, the description covers indexing behavior, advantages, parameters, and return summary (files_indexed, total_symbols, etc.). It also mentions environment variable. No gaps found.

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

Parameters5/5

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

Schema description coverage is 0%, so the description must compensate. It explains 'directory' as a valid path and 'cpu' with detailed behavior including default logic and env var override. This adds full meaning beyond the raw schema.

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

Purpose5/5

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

The description clearly states this tool builds the searchable index for code intelligence features. It distinguishes itself from siblings like search_code and search_docs by noting they depend on 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 Guidelines5/5

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

Explicitly says 'YOU MUST CALL THIS TOOL FIRST' and lists triggers for when to call it (new session, empty results, etc.). It also states what not to use it for (non-code files, single-file lookups, git history) and points to alternatives.

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/kapillamba4/code-memory'

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