Skip to content

romiluz13/MongoBranch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

MongoBranch hero image showing robotic arms managing branch, commit, merge, and deploy operations on a tree built for AI agents

🌿 MongoBranch

Git-level version control for MongoDB β€” built for AI agents

Tests MongoDB MCP Tools CLI Commands Engines TypeScript License: MIT

branch β†’ commit β†’ diff β†’ merge β†’ checkpoint β†’ audit β†’ deploy

340 tests. 87 MCP tools. 26 engines. Zero mocks. Real MongoDB only.

Quick Start Β· Why Β· Features Β· MCP Server Β· CLI Β· Architecture


🧠 The Problem

AI agents write to databases. They hallucinate. They retry. They run in parallel. And when they break your data, you have no undo button.

❌ Without MongoBranch                    βœ… With MongoBranch
─────────────────────────                 ─────────────────────────
Hope the agent doesn't break anything     Agent works on isolated branch copy
Manually snapshot before every op         Commits are automatic + content-addressed
Lock the entire database                  Parallel agents, zero interference
"Who changed that?" β€” nobody knows        blame β†’ agent-b, commit abc123, 14:32
"Roll it back" β€” to when, exactly?        time-travel β†’ any commit or timestamp
"Did the merge break anything?"           three-way merge + conflict detection
"Ship it to prod" β†’ YOLO                  deploy request β†’ review β†’ approve β†’ merge

MongoBranch gives MongoDB the full git experience: branches, commits, diffs, three-way merges, cherry-picks, reverts, tags, blame, stash, reflog, and time travel. Every operation tracked. Every change reversible. Every agent sandboxed.


πŸ“Š Feature Matrix

Neon raised $100M+ and their branches can never merge back. MongoBranch does three-way merge with per-field conflict resolution. On MongoDB.

Feature MongoBranch Neon (Postgres) Dolt (MySQL)
Branch isolation βœ… DB-per-branch βœ… CoW fork βœ… Working copy
Merge back to parent βœ… Three-way ❌ Impossible βœ… Three-way
Content-addressed commits βœ… SHA-256 ❌ WAL-based βœ… Prolly tree
Cherry-pick & revert βœ… ❌ βœ…
Field-level blame βœ… ❌ βœ… Row-level
Time travel queries βœ… Commit + timestamp βœ… LSN-based βœ… AS OF
Tags & refs βœ… ❌ βœ…
Deploy requests (data PRs) βœ… ❌ ❌
Branch protection + globs βœ… βœ… ❌
Pre/post hooks (14 events) βœ… ❌ ❌
Stash / pop βœ… ❌ ❌
Reflog (survives deletion) βœ… ❌ ❌
Operation log + undo βœ… ❌ ❌
N-way branch comparison βœ… ❌ ❌
PII anonymization βœ… hash/mask/null/redact ❌ ❌
Agent scopes + quotas βœ… Collection-level ACLs ❌ ❌
Multi-agent isolation βœ… Per-agent sandboxes ❌ ❌
Merge queue (FIFO atomic) βœ… ❌ Can't merge ❌
MCP Server for AI agents βœ… 87 tools βœ… ~10 tools ❌
CLI βœ… 62 commands βœ… βœ…
Atlas Search index branching βœ… N/A N/A
Branch TTL (auto-expire) βœ… βœ… ❌
Tamper-evident audit chain βœ… SHA-256 hash-chain ❌ ❌
Checkpoints (instant save/restore) βœ… Zero-ceremony βœ… Snapshots API ❌
Idempotent execution guard βœ… requestId dedup ❌ ❌
Branch-from-branch (nested) βœ… Depth-tracked βœ… βœ…
Webhooks (HMAC-signed) βœ… Pre/post + HMAC-SHA256 ❌ ❌
Real-time change streams βœ… Branch watchers ❌ ❌

MongoBranch: 28/28. Neon: 8/28. Dolt: 11/28.

The only tool that gives MongoDB full git semantics and is purpose-built for AI agents.


πŸš€ Quick Start

# 0. Prerequisite: Bun 1.0+ must be installed on your machine
#    MongoBranch ships Bun-based CLI and MCP entrypoints.

# 1. Install globally
npm install -g mongobranch

# 2. Bootstrap a fresh app workspace with auth-enabled Atlas Local preview
mkdir my-agent-app && cd my-agent-app
mb init --db myapp --start-local

# 3. Prove the environment before touching data
mb doctor
mb access status

# 4. Branch β†’ Work β†’ Commit β†’ Merge
mb branch create experiment --description "testing new schema"
# ... make your changes ...
mb commit experiment -m "restructured user fields"
mb diff experiment
mb merge experiment          # apply to main

# Or tag a known-good state and time-travel later
mb tag create v1.0 experiment
mb branch delete experiment  # done β€” branch is disposable

Scoped approval rule:

  • Use mb init --start-local for new external workspaces.
  • Treat mb doctor + mb access status as the install-to-ready gate.
  • The current strongest proof is an auth-enabled Atlas Local preview consumer app that passed 22/22 install-to-restore dogfood checks.
  • For an agent-friendly zero-guess setup path, see For AI.

Use With Your Existing App

MongoBranch connects to the same MongoDB deployment your app uses.

  • It does not patch your app automatically.
  • It controls a sourceDatabase plus one or more branch databases.
  • The safest workflow is: let the app keep using main, and let the agent use MongoBranch tools to branch, diff, merge, and review data.
  • If you want the app itself to run against a branch, point the app's DB name to the branch database after you create the branch.

Example for an existing app workspace:

cd /path/to/your-app
mb init --db your_real_db_name --uri "mongodb://localhost:27017/?directConnection=true"
mb doctor
mb access status
mb branch create feature-x

Then either:

  • use MongoBranch tools directly against feature-x, or
  • repoint the app's DB name to the generated branch DB for isolated end-to-end testing

πŸ€– MCP Server β€” 87 Tools for AI Agents

MongoBranch ships a Model Context Protocol server with 87 tools. Drop into Claude Desktop, Cursor, Windsurf, or any MCP client:

Bun must be available on the host machine because mongobranch-mcp is shipped as a Bun entrypoint.

{
  "mcpServers": {
    "mongobranch": {
      "command": "npx",
      "args": ["mongobranch-mcp"],
      "env": {
        "MONGOBRANCH_URI": "mongodb://localhost:27017",
        "MONGOBRANCH_DB": "myapp"
      }
    }
  }
}

Two Calls. That's It.

1. start_task(agentId: "claude", task: "fix-user-emails")
   β†’ Creates isolated branch with full DB copy. Agent works freely.

2. complete_task(agentId: "claude", task: "fix-user-emails", autoMerge: true)
   β†’ Diffs every collection β†’ three-way merges β†’ main updated atomically.

Main is never touched until merge. If the agent fails, delete the branch. Zero damage.

All 87 MCP Tools

Category Tools What They Do
Workflow start_task, complete_task One-call branch + one-call merge
Branch create_branch, list_branches, delete_branch, rollback_branch, gc, system_status Full lifecycle + garbage collection
Diff & Merge diff_branch, merge_branch, merge_three_way Field-level diff, conflict strategies
Commits commit, get_commit, commit_log SHA-256, parent chains, merge commits
Tags create_tag, list_tags, delete_tag Immutable named refs
Cherry-Pick cherry_pick, revert_commit Surgical apply/undo
Time Travel time_travel_query, blame Any commit or timestamp
Deploy open/approve/reject/execute/list_deploy_request PR-like workflow for data
Access Control access_control_status, provision_branch_access, provision_deployer_access, revoke_access_identity, list_access_profiles Least-privilege MongoDB users + live enforcement probe
Protection protect_branch, list_protections, remove_protection Glob patterns, merge-only
Hooks list_hooks, remove_hook, register_webhook 14 events + HTTP webhooks
TTL set_branch_ttl, reset_from_parent Auto-expire + re-copy from source
Stash stash, stash_pop, stash_list Save/resume work
Reflog reflog Branch pointer history
Scope set_agent_scope, check_agent_permission, get_agent_violations Per-agent collection ACLs
Compare compare_branches N-way branch comparison matrix
Anonymize create_anonymized_branch hash/mask/null/redact PII
Search Index list/copy/diff/merge_search_indexes Atlas Search on branches
CRUD Proxy branch_insert/update/delete/find, branch_aggregate, branch_count, branch_update_many, branch_list_collections, branch_schema Full database ops on any branch
Agent register_agent, create_agent_branch, agent_status Per-agent sandboxes
History branch_log, record_snapshot, export_audit_log Full audit trail (JSON/CSV)
Queue enqueue_merge, process_merge_queue, merge_queue_status FIFO atomic merges
Ops branch_oplog, branch_undo, materialization_status Oplog, undo, CoW status
Audit Chain verify_audit_chain, export_audit_chain_certified, get_audit_chain Tamper-evident hash chain (EU AI Act)
Checkpoints create_checkpoint, restore_checkpoint, list_checkpoints Lightweight save/restore points
Execution Guard guarded_execute Idempotent ops β€” dedup via requestId
Watcher watch_branch, stop_watch, get_watch_events Real-time change stream events

πŸ“Ÿ CLI β€” 62 Commands

# System
mb status                         # Active branches, storage, recent activity
mb doctor                         # Live environment probe for Atlas Local capabilities
mb access status                  # Verify whether MongoDB access control is actually enforced

# Branch lifecycle
mb branch create <name>           # Isolated DB copy β€” indexes, data, validators
mb branch list                    # All branches with metadata + TTL
mb branch switch <name>           # Switch active branch context
mb branch delete <name>           # Drop branch database

# Version control
mb commit <branch> -m "message"   # SHA-256 content-addressed commit
mb commits <branch>               # Walk the commit graph
mb tag create <name> <branch>     # Immutable ref: "v1.0", "pre-migration"
mb tag list                       # All tags with commit hashes
mb tag delete <name>              # Remove tag (commit preserved)
mb cherry-pick <target> <hash>    # Apply one commit to another branch
mb revert <branch> <hash>         # Undo a commit, history preserved

# Diff & merge
mb diff <source> [target]         # Colored field-level diff
mb merge <source> --into main     # Three-way merge with conflict detection
mb merge <source> --dry-run       # Preview without applying

# Time travel & forensics
mb query <branch> <collection>            # Query data at any commit/timestamp
mb blame <branch> <collection> <docId>    # Who changed what field, when

# Deploy & safety
mb deploy create                  # Create deploy request (data PR)
mb deploy list                    # List all deploy requests
mb deploy approve <id>            # Approve for production
mb deploy reject <id>             # Reject with reason
mb deploy execute <id>            # Ship it
mb stash save <branch>            # Save work-in-progress
mb stash pop <branch>             # Restore it
mb stash list <branch>            # View stash stack
mb drift capture <branch>         # Review fence using MongoDB operationTime
mb drift check --branch <name>    # Detect post-review raw writes
mb access provision-branch <name> # Least-privilege branch-scoped MongoDB user
mb access provision-deployer      # Protected-target deploy identity
mb access revoke <username>       # Drop provisioned user/role

# Agent coordination
mb anonymize <branch> --strategy mask         # PII redaction
mb compare <branch1> <branch2> <branch3>      # N-way comparison matrix
mb reflog <branch>                # Branch pointer history

# Atlas Search indexes on branches
mb search-index list <branch>     # List indexes on branch
mb search-index copy <src> <tgt>  # Copy indexes between branches
mb search-index diff <src> <tgt>  # Compare index definitions
mb search-index merge <src> <tgt> # Merge index definitions

# Operations
mb gc                             # Clean stale branches
mb log [branch]                   # History log with filtering

# Agent Safety (Wave 9)
mb checkpoint create <branch> --label "before-migration"
mb checkpoint restore <branch> <id>
mb checkpoint list <branch>
mb audit verify                   # Verify tamper-evident hash chain
mb audit export --format json     # Export for compliance auditors
mb audit log --branch <name>      # View audit trail

βš™οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                       Your App / AI Agent                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚           CLI (62 cmds) Β· MCP Server (87 tools) Β· SDK            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  BranchManager   CommitEngine     DiffEngine      MergeEngine    β”‚
β”‚  TimeTravelEngine DeployManager   BranchProxy     ScopeManager   β”‚
β”‚  ProtectionManager HookManager   AgentManager     MergeQueue     β”‚
β”‚  OperationLog    HistoryManager   StashManager    ReflogManager  β”‚
β”‚  BranchComparator AnonymizeEngine SearchIndexManager              β”‚
β”‚  AuditChainMgr   CheckpointMgr   ExecutionGuard  BranchWatcher   β”‚
β”‚  AccessControlManager                                           β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                        MongoDB Driver                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  main (myapp)  β”‚  __mb_feature-x  β”‚  __mb_claude--fix-users      β”‚
β”‚  ────────────  β”‚  ──────────────  β”‚  ──────────────────────────  β”‚
β”‚  users         β”‚  users (copy)    β”‚  users (modified)             β”‚
β”‚  products      β”‚  products        β”‚  products                     β”‚
β”‚  orders        β”‚  orders          β”‚  orders (new docs)            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  __mongobranch (metadata)                                        β”‚
β”‚  β”œβ”€β”€ branches    commits     tags           commit_data          β”‚
β”‚  β”œβ”€β”€ protections hooks       deploy_requests agents              β”‚
β”‚  β”œβ”€β”€ oplog       history     reflog         scopes               β”‚
β”‚  β”œβ”€β”€ stashes     violations  merge_queue    search_indexes       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Each branch = a separate MongoDB database. Full isolation. Real indexes. Real data. Zero mocks.

Design Decisions

Decision Why
DB-per-branch Complete isolation β€” branches can't leak into each other
Content-addressed commits SHA-256 hashes ensure integrity, parent chains enable graph traversal
Three-way merge BFS common ancestor, per-field conflict detection β€” no silent data loss
Lazy copy-on-write lazy: true β†’ instant branch, data copied only on first write
Deploy requests PR-like review: open β†’ approve β†’ execute (not YOLO merge)
Pre/post hooks Pre-hooks reject synchronously, post-hooks fire-and-forget
Merge queue FIFO ordering for concurrent agent merges β€” no race conditions
Batched cursor iteration Large collections copied in 1000-doc batches β€” no memory blowup
Agent scopes Collection-level ACLs + quotas β€” agents can't touch what they shouldn't
Access control probe Restricted-user live check proves whether MongoDB is enforcing least privilege

What Gets Diffed

  • Documents β€” added, removed, modified (field-level via jsondiffpatch)
  • Indexes β€” structural changes between branches
  • Validation rules β€” JSON Schema differences
  • Atlas Search indexes β€” search index definitions branched and diffed
  • Vector embeddings β€” 512-dim Voyage AI embeddings survive branchβ†’diffβ†’merge intact

πŸ›‘οΈ Agent Safety (Wave 9)

Production-hardened features for AI agents operating on real data.

Checkpoints β€” Instant Save/Restore

// Agent creates a save point before risky work
const cp = await checkpointManager.create("feature-branch", { label: "before-migration" });

// Agent does aggressive operations...
await proxy.insertOne("feature-branch", "products", bulkData);
await proxy.updateMany("feature-branch", "users", {}, { $set: { role: "pending" } });

// Something went wrong? Instantly restore to the save point
await checkpointManager.restore("feature-branch", cp.id);
// Data is exactly as it was before β€” every collection, every document

Audit Chain β€” Tamper-Evident Compliance

// Every operation is hash-chained (SHA-256). Tampering breaks the chain.
const verification = await auditChain.verify();
// { valid: true, totalEntries: 847, firstEntry: genesis, lastEntry: ... }

// Export for compliance auditors (EU AI Act Article 12)
const report = await auditChain.exportChain("json");
// Includes cryptographic verification header + full hash chain

Execution Guard β€” Exactly-Once Operations

// LLM retries the same tool call? No duplicate side effects.
const result = await guard.execute(
  "req-abc-123",  // Deterministic request ID
  "branch_insert", "my-branch", args,
  async () => proxy.insertOne("my-branch", "orders", newOrder),
);
// result.cached === true on retry β€” same result, zero duplicate writes

Nested Branches β€” Hierarchical Agent Teams

mb branch create feature                     # depth 0 (from main)
mb branch create experiment --from feature    # depth 1
mb branch create sub-test --from experiment   # depth 2
# Max depth enforced (default 5) β€” prevents runaway nesting

Webhooks β€” HMAC-Signed HTTP Notifications

// Pre-merge webhook β€” blocks merge if policy violated
await hookManager.registerWebhook("policy-check", "pre-merge",
  "https://api.example.com/hooks/review",
  { secret: "my-signing-key", timeout: 3000 }
);
// POST with X-MongoBranch-Signature: <HMAC-SHA256> header

⏰ Time Travel & Blame

Query your data at any point in history. Like Dolt's AS OF or Neon's Time Travel β€” but for MongoDB.

// "What did the users collection look like at commit abc123?"
const users = await timeTravelEngine.findAt({
  branchName: "main",
  collection: "users",
  commitHash: "abc123",
});

// "What did it look like yesterday at 3pm?"
const snapshot = await timeTravelEngine.findAt({
  branchName: "main",
  collection: "users",
  timestamp: new Date("2026-03-30T15:00:00Z"),
});

// "Who changed the email field on user 42?"
const blame = await timeTravelEngine.blame("main", "users", "user-42");
// β†’ { fields: { email: { commitHash: "abc123", author: "agent-b", message: "fix emails" } } }

Every commit snapshots the full document state. No WAL parsing. No reconstruction. Instant lookup.


🚦 Deploy Requests β€” PRs for Your Data

Don't YOLO merge to production. Open a deploy request, review the diff, approve, then execute.

Inspired by PlanetScale's deploy requests β€” but for document data, not just schema.

1. open_deploy_request(source: "feature-x", target: "main", description: "Add premium users")
   β†’ DR #a1b2c3d4 opened. Diff computed automatically.

2. approve_deploy_request(id: "a1b2c3d4", reviewedBy: "alice")
   β†’ Approved. Ready to execute.

3. execute_deploy_request(id: "a1b2c3d4")
   β†’ Merged! feature-x β†’ main. 3 added, 0 removed, 1 modified.

Duplicate protection, rejection with reasons, status filtering. The full PR workflow.


πŸ” Access Control β€” Managed vs Enforced

MongoBranch now provisions least-privilege MongoDB users for branch and deploy workflows, but it does not blindly assume that createUser means the server is enforcing RBAC.

mb access status
# Shows authenticated user context and runs a restricted-user probe

If MongoDB accepts a forbidden write from that restricted probe user, MongoBranch reports the environment as not enforced.

mb access provision-branch feature-x \
  --username agent_feature_x \
  --password secret123 \
  --collections users,orders \
  --by codex

This produces:

  • a MongoDB role scoped to the branch database
  • a MongoDB user assigned to that role
  • a connection string agents can use for that branch
  • metadata in MongoBranch so the identity can be listed and revoked later

πŸ›‘οΈ Branch Protection & Hooks

// Nobody writes to main directly. Period.
await protectionManager.protectBranch("main", { requireMergeOnly: true, preventDelete: true });
await protectionManager.protectBranch("prod-*", { requireMergeOnly: true });  // glob patterns

// Hooks fire on 14 different events
await hookManager.addHook({
  name: "validate-before-merge",
  event: "pre-merge",
  callback: async (ctx) => {
    if (ctx.targetBranch === "main" && !ctx.approved) {
      throw new Error("Merge to main requires deploy request approval");
    }
  },
});
// Pre-hooks reject synchronously. Post-hooks fire-and-forget. (lakeFS pattern)

Hook Events

pre-create, post-create, pre-delete, post-delete, pre-merge, post-merge, pre-commit, post-commit, pre-reset, post-reset, pre-cherry-pick, post-cherry-pick, pre-revert, post-revert


πŸ”’ Multi-Agent Isolation

Agent A: start_task(agentId: "agent-a", task: "update-users")
Agent B: start_task(agentId: "agent-b", task: "update-products")

# Completely isolated databases:
#   __mb_agent-a--update-users    (Agent A's sandbox)
#   __mb_agent-b--update-products (Agent B's sandbox)

# Both work in parallel β€” zero interference

Agent A: complete_task(agentId: "agent-a", task: "update-users", autoMerge: true)
Agent B: complete_task(agentId: "agent-b", task: "update-products", autoMerge: true)

# Three-way merge handles conflicts automatically
# Merge queue ensures sequential ordering β€” no race conditions

πŸ“‘ Real-Time Branch Watcher

React to branch changes in real time via MongoDB Change Streams β€” with resume token support for crash recovery.

const watcher = new BranchWatcher(client, config);

// Watch a branch for live changes
await watcher.watch("feature-x", async (event) => {
  console.log(`${event.operationType} on ${event.collection}: ${event.documentId}`);
  // β†’ "insert on products: 507f1f77bcf86cd799439011"
}, {
  fullDocument: true,          // Include the full document in events
  fullDocumentBeforeChange: true,  // Include pre-image (what it looked like before)
});

// Resume after disconnect β€” no missed events
const token = watcher.getResumeToken("feature-x");
await watcher.watch("feature-x", handler, { resumeAfter: token });

await watcher.stop("feature-x");

Use cases: CI triggers on branch data changes, agent coordination signals, audit stream forwarding.


πŸ§ͺ Testing β€” 340 Tests, Zero Mocks

Every test runs against real MongoDB (Atlas Local Docker). No mocking. No faking. If it passes here, it works in production.

bun run test                                 # Full suite β€” 340 tests, 32 files
bun test tests/core/commit.test.ts           # Commits, tags, cherry-pick, revert
bun test tests/core/three-way-merge.test.ts  # Three-way merge + conflict resolution
bun test tests/core/timetravel.test.ts       # Time travel queries + blame
bun test tests/core/deploy.test.ts           # Deploy request workflow
bun test tests/core/scope.test.ts            # Agent permissions + ACLs
bun test tests/core/access-control.test.ts   # MongoDB users, roles, RBAC enforcement probe
bun test tests/core/stress-ai.test.ts        # Real Voyage AI 512-dim embeddings

Current verification highlights:

  • branch + nested-branch lifecycle against real MongoDB
  • three-way merge, deploy drift gates, and time travel semantics
  • access control provisioning plus live restricted-user enforcement probe
  • Atlas Search / Vector Search capability checks on Atlas Local preview
  • MCP tool handlers and end-to-end consumer-app dogfooding
  • fresh external auth-enabled Atlas Local consumer app passed 22/22 install, branch, deploy, drift, backup/restore, and CLI/MCP/library checks

πŸ”§ Configuration

MONGOBRANCH_URI=mongodb://localhost:27017   # MongoDB connection string
MONGOBRANCH_DB=myapp                        # Source database name
# .mongobranch.yaml
uri: mongodb://localhost:27017/?directConnection=true
sourceDatabase: myapp
metaDatabase: __mongobranch
branchPrefix: __mb_

πŸ› οΈ Development

bun install                       # Install dependencies
docker compose up -d              # Atlas Local on port 27017 (repo contributors)
bun run test                      # 340 tests, ~220 seconds
bun src/mcp/server.ts             # Start MCP server
bun src/cli.ts branch create my-feature   # CLI

27 Core Modules

src/core/
β”œβ”€β”€ access-control.ts  AccessControlManager β€” branch/deployer users, roles, RBAC enforcement probe
β”œβ”€β”€ branch.ts          BranchManager β€” create, list, switch, delete, TTL, nested branches, CoW, gc
β”œβ”€β”€ commit.ts          CommitEngine β€” SHA-256 commits, parent chains, tags, cherry-pick, revert
β”œβ”€β”€ diff.ts            DiffEngine β€” documents + indexes + validation rules + three-way
β”œβ”€β”€ merge.ts           MergeEngine β€” two-way, three-way, branch-to-branch, dry-run, strategies
β”œβ”€β”€ doctor.ts          EnvironmentDoctor β€” live Atlas Local capability probes
β”œβ”€β”€ drift.ts           DriftManager β€” operationTime review fences + stale-state detection
β”œβ”€β”€ timetravel.ts      TimeTravelEngine β€” findAt (commit/timestamp), listCollectionsAt, blame
β”œβ”€β”€ deploy.ts          DeployRequestManager β€” open, approve, reject, execute, list, get
β”œβ”€β”€ protection.ts      ProtectionManager β€” branch protection rules, glob patterns
β”œβ”€β”€ hooks.ts           HookManager β€” 14 event types, pre/post hooks, HTTP webhooks (HMAC-SHA256)
β”œβ”€β”€ scope.ts           ScopeManager β€” agent permissions, collection ACLs, quota enforcement
β”œβ”€β”€ compare.ts         BranchComparator β€” N-way branch comparison, presence matrix
β”œβ”€β”€ stash.ts           StashManager β€” stash/pop/list/drop, ordered stash stack
β”œβ”€β”€ anonymize.ts       AnonymizeEngine β€” hash/mask/null/redact PII strategies
β”œβ”€β”€ reflog.ts          ReflogManager β€” branch pointer tracking, survives deletion
β”œβ”€β”€ search-index.ts    SearchIndexManager β€” Atlas Search index branching
β”œβ”€β”€ audit-chain.ts     AuditChainManager β€” SHA-256 hash-chained tamper-evident log (EU AI Act)
β”œβ”€β”€ checkpoint.ts      CheckpointManager β€” lightweight save points, instant restore, TTL prune
β”œβ”€β”€ execution-guard.ts ExecutionGuard β€” idempotent agent ops, requestId dedup, exactly-once
β”œβ”€β”€ watcher.ts         BranchWatcher β€” real-time change stream monitoring per branch
β”œβ”€β”€ proxy.ts           BranchProxy β€” CRUD, aggregate, count, schema with lazy auto-materialization
β”œβ”€β”€ oplog.ts           OperationLog β€” every write tracked, undo support
β”œβ”€β”€ queue.ts           MergeQueue β€” FIFO concurrent merge ordering
β”œβ”€β”€ agent.ts           AgentManager β€” per-agent namespaced branches
β”œβ”€β”€ history.ts         HistoryManager β€” snapshots, branch log, audit export (JSON/CSV)
└── types.ts           TypeScript interfaces, config, constants

Architecture Decisions


πŸ—ΊοΈ Roadmap

Wave What Status
1-3 Branch, diff, merge, agent, proxy, oplog, CoW, queue βœ… Shipped
4 Commits (SHA-256), tags, three-way merge, cherry-pick, revert βœ… Shipped
5 Branch TTL, reset from parent, protection rules, hooks (14 events) βœ… Shipped
6 Time travel, blame, deploy requests βœ… Shipped
7 Agent scopes, branch compare, stash, anonymize, reflog βœ… Shipped
8 Atlas Search index branching, MCP server, CLI, CI βœ… Shipped
9 Audit chain (EU AI Act), checkpoints, execution guard, nested branches, webhooks, watchers βœ… Shipped
10 Ship It β€” npm publish, release workflow, .npmignore, v1.0.0 βœ… Shipped

All 10 waves shipped. πŸš€ 87 MCP tools Β· 62 CLI commands Β· 26 engines Β· 340 tests


License

MIT


Built for the age of AI agents writing to databases.

Stop hoping. Start branching.

340 tests Β· 87 MCP tools Β· 62 CLI commands Β· 26 engines Β· 0 mocks Β· real MongoDB only

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors