Skip to content

Enable parallel MCP graph access across Git worktrees - #1063

Open
falgon wants to merge 1 commit into
tirth8205:stagingfrom
falgon:staging
Open

falgon wants to merge 1 commit into
tirth8205:stagingfrom
falgon:staging

Conversation

@falgon

@falgon falgon commented Sep 21, 2026

Copy link
Copy Markdown

Summary

This change adds an opt-in stdio MCP mode that allows one MCP session to serve multiple linked Git worktrees concurrently.

The router:

  • Starts one child MCP server lazily for each authorized repository root.
  • Routes each tool call to the child selected by its explicit repo_root.
  • Keeps each worktree on its normal per-repository graph database or Registry-configured data_dir.
  • Rejects unrelated repositories, inactive worktrees, and worktrees that resolve to the same database.
  • Forwards initialization, notifications, cancellations, responses, and server requests across the parent and child MCP processes.
  • Preserves the existing single-root behavior unless --multi-worktree is explicitly enabled.

Motivation

Parallel pull request reviews commonly use separate linked worktrees so that each review can inspect the exact pull request revision. The existing single-root MCP process could not accept another linked worktree after startup, which forced reviews to run serially and required repeatedly rebuilding or switching the checkout.

This mode lets one MCP session route concurrent requests to isolated child servers without mixing graph data from different worktrees or commits.

Usage

Start the server from the primary checkout:

code-review-graph serve --multi-worktree --repo /path/to/primary-repository

Tool calls for linked worktrees must include that worktree's absolute path in repo_root. Only the primary checkout and active worktrees reported by git worktree list for the same Git common directory are accepted.

The mode is stdio-only and cannot be combined with a process-wide CRG_DATA_DIR. External graph storage should instead use separate, non-overlapping Registry data_dir entries for each worktree.

Security

The implementation keeps the existing repository boundary checks and adds explicit same-repository worktree authorization. Each child process is started with a restricted environment allowlist, and the router refuses database aliasing between worktrees. Unrelated repositories and inactive worktree paths cannot be routed through the session.

Validation

  • uv run ruff check code_review_graph/cli.py code_review_graph/multi_worktree.py tests/test_cli.py tests/test_e2e_mcp_client.py tests/test_multi_worktree.py
  • uv run pytest -q tests/test_multi_worktree.py tests/test_cli.py tests/test_e2e_mcp_client.py — 32 passed
  • git diff --check
  • prek was not run because this repository does not contain a prek or pre-commit configuration.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant