Core Functionalities of Codebase Memory MCP: Static Analysis and Knowledge Graph Architecture

Codebase Memory MCP is a static-analysis engine that converts entire source repositories into persistent, queryable knowledge graphs, enabling AI coding agents to perform structural searches, dependency tracing, and impact analysis in milliseconds without external API dependencies.

The codebase-memory-mcp project from DeusData implements a Model Context Protocol (MCP) server that transforms raw source trees into compressed graph databases. By combining 158 vendored Tree-Sitter grammars with a Hybrid LSP implementation, it creates persistent code intelligence that spans across agent sessions while remaining completely local and offline.

Repository Indexing Pipeline

The indexing layer processes entire codebases using a RAM-first design that keeps all operations in memory until final persistence. This pipeline utilizes 158 vendored Tree-Sitter grammars—defined in opencode.json—to parse source files across more than 12 languages including Python, TypeScript/JS/TSX, PHP, C#, Go, C/C++, Java, Kotlin, Rust, and Perl.

Cross-reference resolution operates through a lightweight Hybrid LSP implementation that extracts import relationships, type information, and cross-service links without requiring external language servers. The extracted graph data flows into an in-memory SQLite database, undergoes LZ4 compression, and finally writes to disk as a zstd-compressed snapshot at .codebase-memory/graph.db.zst. Compression logic resides in internal/cbm/zstd_store.c, ensuring efficient storage while maintaining fast decompression speeds.

Two primary entry points drive the indexing process: the index_repository CLI command for one-shot scans, and a background file watcher implemented in src/watcher/watcher.c that automatically re-indexes repositories when auto_watch is enabled.

Persistent Knowledge Graph Architecture

Once indexed, the repository transforms into a rich semantic graph storing entities as nodes and relationships as typed edges. Nodes represent structural elements: Project, Package, Folder, File, Module, Class, Function, Method, Interface, Enum, Type, Route, and Resource.

Edges capture complex code relationships including CALLS, IMPORTS, DEFINES, IMPLEMENTS, HTTP_CALLS, ASYNC_CALLS, EMITS, LISTENS_ON, DATA_FLOWS, SIMILAR_TO, and SEMANTICALLY_RELATED. This graph persists on disk using the zstd-compressed SQLite format and automatically syncs across all agent sessions via a coordination daemon. Security-sensitive operations and logging configurations are documented in docs/SECURITY.md, with runtime logs written to ${CBM_CACHE_DIR}/logs/.

Query Engine and Analysis Tools

The MCP exposes a comprehensive toolset for code intelligence that operates directly against the persisted graph.

search_graph and search_code provide structural search capabilities supporting label filters, regex name patterns, degree limits, and pagination. trace_path executes BFS traversals to map call chains up or downstream, enabling dead-code detection and Louvain community detection for architectural clustering.

detect_changes performs impact analysis by mapping git diffs to affected symbols and classifying blast-radius risk. For high-level overviews, get_architecture returns language distributions, package structures, entry points, HTTP routes, hotspots, and Architecture Decision Records (ADRs) in a single call.

manage_adr provides full CRUD operations for ADRs, while query_graph supports a read-only subset of openCypher for complex graph traversals. Semantic search leverages a bundled nomic-embed-code model for vector similarity queries without external API calls. Cross-service linking identifies HTTP, gRPC, GraphQL, and tRPC routes with confidence scores.

CLI Usage Examples

Index a repository to create an initial graph snapshot:

codebase-memory-mcp cli index_repository --repo-path /absolute/path/to/my/project

Find functions matching a specific pattern using structural search:

codebase-memory-mcp cli search_graph \
  --project my-project \
  --label Function \
  --name-pattern '.*Handler.*' \
  --limit 20

Trace the complete call chain for a function in both directions:

codebase-memory-mcp cli trace_path \
  --project my-project \
  --function-name Search \
  --direction both \
  --depth 5

Execute a Cypher-like query to identify the most-called functions:

codebase-memory-mcp cli query_graph \
  --project my-project \
  --query "MATCH (f:Function) RETURN f.name, size((f)<-[:CALLS]-()) AS callers ORDER BY callers DESC LIMIT 5"

Analyze the impact of uncommitted changes:

git diff HEAD | codebase-memory-mcp cli detect_changes --project my-project

Launch the optional 3D graph visualizer:

codebase-memory-mcp --ui=true --port=9749

Configuration options for indexing behavior and ignore patterns are documented in docs/CONFIGURATION.md and docs/cbmignore.md respectively.

Summary

  • Static Analysis Engine: Parses 12+ languages using 158 Tree-Sitter grammars and Hybrid LSP resolution, storing results in opencode.json and the indexing pipeline.
  • Compressed Graph Storage: Maintains persistent knowledge graphs using zstd-compressed SQLite snapshots via internal/cbm/zstd_store.c, shared across sessions through a coordination daemon.
  • Rich Query Interface: Exposes tools like trace_path, detect_changes, and query_graph for dependency tracing, impact analysis, and openCypher queries.
  • Local-First Architecture: Operates entirely offline with no external API dependencies, reducing token usage by approximately 99% compared to file-by-file analysis.

Frequently Asked Questions

Codebase memory MCP is a static-analysis engine that builds a persistent knowledge graph of your entire repository, enabling structural queries like "find all callers of this function" or "trace data flow between services." Unlike text search, it understands semantic relationships, imports, and type information across 12+ languages, delivering results in under 10 milliseconds without reading individual files.

Which programming languages does the indexing pipeline support?

The pipeline supports Python, TypeScript, JavaScript, TSX, PHP, C#, Go, C, C++, Java, Kotlin, Rust, and Perl. This coverage is implemented through 158 vendored Tree-Sitter grammars compiled into the binary, combined with a Hybrid LSP system that resolves imports and type information specific to each language's ecosystem.

Is codebase memory MCP completely local or does it require cloud APIs?

The system is fully local and offline. All indexing, embedding generation using the bundled nomic-embed-code model, and graph queries execute on your machine. No Docker containers, external API keys, or network connections are required, making it suitable for air-gapped environments and sensitive codebases.

How does the background watcher handle large repository changes?

The background watcher, implemented in src/watcher/watcher.c, monitors file system events and triggers incremental re-indexing when auto_watch is enabled. The RAM-first design ensures that even large diffs are processed in memory before writing compressed snapshots to disk, with old graph versions automatically managed in ${CBM_CACHE_DIR}.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →