# TreeDB & TreeDB for Agents (treedb.dev) > Compressed copy-on-write B+Tree engine (Memtable + Command WAL + Dictionary-ZSTD outer leaves + compressed secondary, lexical text, and HNSW vector indexes + multi-node Raft + Mongo gateway) and commit-exact Model Context Protocol (MCP) server for multi-repository code search, AST symbols, GitHub history, and code-linked agent memory. ## Install TreeDB for Agents (`treedb-repo-mcp`) Static `CGO_ENABLED=0` binary (Linux/macOS, amd64/arm64, SHA-256 verified): ```sh curl -fsSL https://treedb.dev/install.sh | sh ``` Environment overrides: `TREEDB_MCP_VERSION` (default `latest`), `TREEDB_MCP_INSTALL_DIR` (default `~/.local/bin`). Pi coding-agent extension (auto-`HEAD` commit pinning, prompt-cache-safe memory recall, OpenTelemetry spans): ```sh pi install npm:@snissn/pi-treedb ``` From source (Go 1.26+): ```sh git clone https://github.com/snissn/treedb-repo-mcp.git cd treedb-repo-mcp go build -o ~/.local/bin/treedb-repo-mcp ./cmd/treedb-repo-mcp ``` ## Multi-Repo Setup (`repos.toml`) Default registry path: `~/.config/treedb-mcp/repos.toml`. ```sh # 1-command client setup (auto-wires Antigravity, Codex TOML, Claude Code, Cursor + agent directive) treedb-repo-mcp setup # Register repositories (auto-detects owner/repo from git remote origin) # On Apple Silicon (darwin/arm64), creating a new repos.toml automatically enables # managed local Metal GPU embeddings (embeddinggemma-2, 168 MB, 5m idle auto-sleep; # pass --lexical-only to disable, or run `treedb-repo-mcp embed-warmup` to pre-fetch). treedb-repo-mcp repo add /path/to/repo-a treedb-repo-mcp repo add /path/to/repo-b --no-github # Inspect freshness, commit lag, watcher health, and disk usage treedb-repo-mcp repos status treedb-repo-mcp repos status --json # Initial sync across all registered repos (--config defaults to ~/.config/treedb-mcp/repos.toml) treedb-repo-mcp sync --config ~/.config/treedb-mcp/repos.toml # Optional: run a shared Streamable HTTP daemon + /dashboard UI. # (Stdio MCP mode auto-starts a local Unix-socket daemon automatically, so you # only need to run `daemon` manually if you want HTTP / shared team access / /dashboard.) treedb-repo-mcp daemon --config ~/.config/treedb-mcp/repos.toml --http 127.0.0.1:7337 ``` ## MCP Client Configuration ### Antigravity (`~/.gemini/config/mcp_config.json`) / Cursor (`~/.cursor/mcp.json`) / Claude Desktop (Stdio, Multi-Repo Auto-Start) ```json { "mcpServers": { "treedb": { "command": "treedb-repo-mcp", "args": ["mcp", "--config", "~/.config/treedb-mcp/repos.toml"] } } } ``` ### Codex CLI (`~/.codex/config.toml` — TOML, not JSON) ```toml [mcp_servers.treedb] command = "treedb-repo-mcp" args = ["mcp", "--config", "~/.config/treedb-mcp/repos.toml"] ``` Or for a shared Streamable HTTP daemon: ```toml [mcp_servers.treedb] url = "http://127.0.0.1:7337/mcp" ``` ### Claude Code ```sh claude mcp add treedb -- treedb-repo-mcp mcp --config ~/.config/treedb-mcp/repos.toml ``` ### Single-Repo Stdio ```json { "mcpServers": { "treedb": { "command": "treedb-repo-mcp", "args": ["mcp", "--repo", "/path/to/repo"] } } } ``` ### Streamable HTTP (Shared Daemon — Antigravity / Cursor / Claude) ```json { "mcpServers": { "treedb": { "url": "http://127.0.0.1:7337/mcp" } } } ``` HTTP endpoints: `POST /mcp`, `GET /health`, `GET /status`, `GET /status?repo=`, `GET /dashboard`. ### Standalone Zero-Repo Agentic Memory (`memory-serve`) ```sh # Stdio MCP server exposing only the 8 Agentic Memory tools (no git repo required) treedb-repo-mcp memory-serve --data-dir ~/.local/share/treedb-memory # Or Streamable HTTP treedb-repo-mcp memory-serve --data-dir ~/.local/share/treedb-memory --http 127.0.0.1:7338 ``` ## Recommended Agent Directive (`AGENTS.md` / `CLAUDE.md` / `GEMINI.md`) `treedb-repo-mcp` automatically sends MCP protocol `instructions` during `initialize`. To make sure agents proactively choose TreeDB over slow recursive `grep`/`rg` scans or GitHub API pagination from turn 1, add this short block to your global or repo `AGENTS.md`, `CLAUDE.md`, or `GEMINI.md`: ```md ## TreeDB MCP Search & Memory Directive - Prefer the `treedb` MCP tools FIRST before local recursive grep/rg or GitHub API pagination. - Call `list_repos` first (and `register_repo(github_repo="owner/repo", pinned=false, wait_lexical_sec=15)` if a needed repo is not mounted). - Prefer `find_symbol(defs_only=true, include_body=true)` for definitions, `search_code(response_mode="passage")` for code/docs, `phrase_search` for exact strings, and `search_github(exclude_bots=true)` + `get_github_thread` for issues/PRs. Pass `ref="HEAD"` for commit-exact verification. - **When NOT to use remote MCP:** Do not rely on a remote/shared MCP server for uncommitted local edits, untracked files, or unpushed commits (remote mirrors only index pushed commits) or for exact lines of a single local file you already have open for editing — read the local file directly (or run a local stdio daemon with `fsnotify`). - For cross-session memory, call `memory_pack` at task start, `memory_retain` (with `linked_paths`/`linked_symbols`) for durable decisions/gotchas, `memory_handoff` at session end, and `register_turn` at milestones. ``` ## Commit-Pinned Fail-Closed Queries (`ref`) Pass `ref` (any git commit SHA, branch, or tag, e.g. `HEAD` or a feature-branch commit `DEADBEEF2`) to `search`, `search_code`, `phrase_search`, `find_symbol`, `get_file_context`, or CLI `query --ref`: - If the indexed base commit matches the resolved `ref` and the base snapshot came from a clean working tree, queries hit the TreeDB index directly at zero overlay cost. - Otherwise, `treedb-repo-mcp` computes the exact `git diff-tree` delta from the indexed base to `ref`, masks modified/deleted base paths, and overlays commit-only `git cat-file` blobs in memory. - Every response attaches a `snapshot` object (or `snapshots` array on multi-repo fan-out) with `verified_commit`, `base_commit`, `overlay_files` (omitted when `0`), and `drift` (`false` when verified). - Fail-closed: invalid refs, dirty/unknown indexed bases, oversized diffs (`>500` changed files or `>32 MiB`), or any targeted repo failing to verify `ref` during multi-repo fan-out return an explicit error instead of silently serving stale results. ## Code-Linked Agent Memory (`agent_memories`) Persistent, namespace-scoped memory stored in TreeDB with automatic git drift detection and a fail-closed secret-scanning gate: - `memory_retain`: Store a memory (`fact`, `decision`, `gotcha`, `preference`, `procedure`) linked to `linked_paths`, `linked_symbols`, and `linked_commit_sha` (defaults to repo `HEAD` when code links are provided). Supports `supersedes_id` immutable versioning and `ttl_seconds`. Rejects API keys, tokens, PEM private keys, and high-entropy credentials before persistence. - `memory_recall`: Search active memories via BM25F (`query`), `namespace`, `kind`, `tag`, `linked_path`, `include_inactive`, `include_expired`, and optional `ref` (defaults to `HEAD`, failing closed if invalid). Automatically checks git drift against `ref` and flags `stale_code_warning: true` with `changed_paths` when linked files changed since `linked_commit_sha`. - `memory_invalidate`: Soft-delete a memory with an optional `reason` and `superseded_by` ID. ## MCP Tools (21 Total) | Tool | Purpose | Key Arguments | | --- | --- | --- | | `list_repos` | List registered repositories and live freshness/lag status | *(none)* | | `register_repo` | Dynamically mount any accessible GitHub repo (14d idle auto-evict) | `github_repo`, `pinned`, `added_by`, `wait_lexical_sec` | | `remove_repo` | Unmount an unpinned repository and optionally delete its local index | `repo`, `delete_data` | | `register_turn` | Report agent turn progress and files touched to `/dashboard` | `agent_id`, `session_id`, `repo`, `task_ref`, `status`, `summary`, `files_touched`, `next_action` | | `search` | Unified search across repo code/docs, issues, PRs, and comments | `query`, `repo`/`repos`, `ref`, `sources`, `mode`, `operator`, `fuzzy`, `response_mode`, `max_passage_runes`, `exclude_bots`, `top_k`, `explain` | | `search_code` | Search chunked repository files with per-file collapse | `query`, `repo`/`repos`, `ref`, `top_dir`, `sub_dir`, `ext`, `lang`, `path`, `path_prefix`, `mode`, `response_mode`, `max_chunks_per_file`, `top_k` | | `search_github` | Search GitHub issues, PRs, reviews, and comments | `query`, `repo`/`repos`, `scope`, `state`, `author`, `exclude_bots`, `label`, `comment_kind`, `number_min`/`max`, `updated_after`/`before`, `top_k` | | `phrase_search` | Native Block-Max WAND exact phrase and proximity (`slop`) search | `phrase`, `repo`/`repos`, `ref`, `slop`, `collection`, `top_dir`, `ext`, `exclude_bots`, `state`, `top_k` | | `find_symbol` | Pure-Go AST symbol-definition lookup (`go/parser` + `gotreesitter`) | `name`, `repo`/`repos`, `ref`, `kind`, `lang`, `top_dir`, `defs_only`, `top_k` | | `get_file_context` | Fetch indexed chunks or exact `ref` lines for a file path | `path`, `repo`, `ref`, `chunk_ordinal`, `start_line`, `end_line` | | `get_github_thread` | Reconstruct an issue/PR body and chronological comments/reviews | `number`, `repo`, `exclude_bots`, `offset`, `limit` | | `memory_pack` | Cold-start token-budgeted active handoff + hybrid memories + 1-hop graph | `query`, `repo`, `branch`, `max_tokens`, `ref` | | `memory_handoff` | Save/update canonical active per-branch session handoff | `repo`, `branch`, `summary`, `completed`, `next_steps`, `linked_paths` | | `memory_retain` | Persist a bi-temporal code-linked agent memory with secret-scanning gate | `body`, `repo`, `namespace`, `kind`, `title`, `tags`, `linked_paths`, `linked_symbols`, `entities`, `relations`, `linked_commit_sha`, `ttl_seconds`, `supersedes_id` | | `memory_recall` | Hybrid BM25F+vector + 1-2 hop graph memory recall with git drift check | `query`, `repo`/`repos`, `ref`, `as_of`, `graph_hops`, `namespace`, `kind`, `tag`, `linked_path`, `top_k`, `include_inactive`, `include_expired` | | `memory_link` | Create typed edges between memories, entities, paths, or symbols | `repo`, `src`, `relation`, `dst`, `memory_id` | | `memory_graph` | Traverse 1-2 hop embedded `memory_edges` graph (<1ms) | `repo`, `seed`, `hops`, `relation`, `direction`, `limit` | | `memory_consolidate` | Deterministic duplicate cleanup, stale decay, and turn promotion preview | `repo`, `dry_run`, `promote_turns` | | `memory_invalidate` | Soft-invalidate an outdated or superseded agent memory | `id`, `repo`, `reason`, `superseded_by` | | `sync_now` | Trigger immediate incremental repo sync, GitHub sync, or maintenance | `target_repo`, `repo`, `github`, `maintain` | | `status` | Report HEAD vs indexed HEAD, lag, watcher telemetry, and TreeDB stats | `repo` | ## Links - Website: https://treedb.dev - TreeDB for Agents: https://treedb.dev/agents - Benchmarks Hub: https://treedb.dev/benchmarks - Documentation: https://treedb.dev/docs - Agent MCP Repository: https://github.com/snissn/treedb-repo-mcp - Core Storage Engine Repository: https://github.com/snissn/gomap (standalone `snissn/treedb` tracked in `snissn/gomap#5972`)