Skip to content

fix(code): share MCP approvals across Git worktrees - #4939

Merged
Mason Daugherty (mdrxy) merged 4 commits into
mainfrom
mdrxy/code/share-mcp-approvals-across-worktrees
Jul 22, 2026
Merged

fix(code): share MCP approvals across Git worktrees#4939
Mason Daugherty (mdrxy) merged 4 commits into
mainfrom
mdrxy/code/share-mcp-approvals-across-worktrees

Conversation

@mdrxy

@mdrxy Mason Daugherty (mdrxy) commented Jul 22, 2026

Copy link
Copy Markdown
Member

Users previously had to approve the same unchanged project MCP server once per Git worktree, producing repeated approval entries when tools created temporary worktrees.

Approvals are now transport-aware when Git's shared metadata can be validated:

  • Remote servers with fixed URLs (http/sse/streamable_http, no ${} interpolation, no command field) are shared across linked worktrees via the validated Git common directory. These resolve identically from any checkout, so sharing is safe.
  • Local stdio servers (any definition containing command) use the exact worktree root, because the same command can execute different files in another checkout.
  • Remote servers with interpolated URLs (containing ${) use the exact worktree root, because project .env files can resolve the same template to different endpoints.

The git_common_dir marker now participates in approval equality, so a transport change under the same name (e.g. stdio → http) requires re-approval. Independent clones still require their own approval, non-Git projects remain scoped to their exact resolved root, and any changed command, URL, headers, or other server configuration still requires re-approval.

Legacy persisted approvals without a git_common_dir marker remain exact-worktree scoped and are never broadened to a Git identity, so existing entries do not silently widen.


Linked worktrees are recognized only when their Git administration directory belongs to the repository's common metadata, points back to that exact worktree, and carries its own valid HEAD and self-referential gitdir backlink. Malformed, missing, forged, or linked metadata falls back to exact-root scoping instead of widening trust. This closes a self-consistent forgery where an attacker's admin directory passes every acceptance check except its location under worktrees/.

Disabled-server precedence and DEEPAGENTS_CODE_DANGEROUSLY_ENABLE_PROJECT_MCP_SERVERS retain their existing behavior.

Test plan
  • Focused Git, model configuration, MCP loading, disabled-server, config-manifest, and startup trust-prompt tests: 1005 passed.
  • Ruff formatting and lint checks passed for all changed Python files.
  • ty passed for deepagents-code.
  • git diff --check passed.

@github-actions github-actions Bot added dcode Related to `deepagents-code` fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: XL 1000+ LOC labels Jul 22, 2026

@open-swe open-swe Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Open SWE Review: No issues found

Open SWE reviewed this PR and found no potential bugs to report.

Open in WebView Open SWE trace

Comment thread libs/code/deepagents_code/_git.py Dismissed
Comment thread libs/code/deepagents_code/_git.py Dismissed
Comment thread libs/code/deepagents_code/_git.py Dismissed

@corridor-security corridor-security Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR intentionally shares MCP server approvals across Git worktrees of the same repository by normalizing the trust scope to the Git common directory. The design introduces a real trust boundary gap: the approval fingerprint covers only the server definition in .mcp.json, not the content of local scripts or binaries it executes, so a sibling worktree (e.g. a PR checkout) can reuse an existing approval to silently launch attacker-controlled code.

Comment thread libs/code/deepagents_code/model_config.py Outdated
Mason Daugherty (mdrxy) and others added 3 commits July 21, 2026 23:35
Remote servers with fixed URLs are safe to share across linked Git
worktrees because they resolve identically from any checkout. Local
stdio commands and interpolated remote URLs are not — the same command
can run different files in another checkout, and the same URL template
can resolve to different endpoints from each worktree's .env.

Approvals are now transport-aware: fixed-URL remote servers use the
validated Git common directory (shared across worktrees), while local
commands and interpolated URLs use the exact worktree root. The
git_common_dir marker participates in equality, so a transport change
under the same name requires re-approval. Legacy unmarked approvals
stay exact-worktree scoped and are never broadened.

find_git_common_dir also now requires the worktree's own admin
directory to carry a valid HEAD and self-referential gitdir backlink,
closing a self-consistent forgery that passed every check except
location.
@mdrxy
Mason Daugherty (mdrxy) merged commit 467f9dd into main Jul 22, 2026
54 checks passed
@mdrxy
Mason Daugherty (mdrxy) deleted the mdrxy/code/share-mcp-approvals-across-worktrees branch July 22, 2026 04:55
Mason Daugherty (mdrxy) pushed a commit that referenced this pull request Jul 22, 2026
> [!CAUTION]
> Merging this PR will automatically publish to **PyPI** and create a
**GitHub release**.

For the full release process, see
[`.github/RELEASING.md`](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md).

---

_Release notes preview: keep this section in sync with the package
`CHANGELOG.md`. The published GitHub release body is extracted from the
merged `CHANGELOG.md` by `release.yml`, not from this PR description._

---


##
[0.1.45](deepagents-code==0.1.44...deepagents-code==0.1.45)
(2026-07-22)

### Features

- Added the Hooks v2 execution engine and typed hooks data models
([#4880](#4880),
[#4870](#4870))
- Added a filesystem tool allowlist for `dcode` with `--allow-fs-tools`
([#4635](#4635))
- Added a GLM-5.2 harness profile
([#4710](#4710))
- Added a built-in thread inspector skill
([#4769](#4769))
- Replaced Gemini 3.5 Flash with Gemini 3.6 Flash in the model switcher
([#4890](#4890))
- Show experimental mode in the splash screen and debug console
([#4863](#4863))
- Gate debug console click-to-copy behind a checkbox
([#4810](#4810))

### Bug Fixes

- Improved scratch-file handling by allowing cleanup of agent-created
scratch files and safe OS-temp scratch artifacts
([#4860](#4860),
[#4869](#4869))
- Skip grading during `/goal` proposals
([#4941](#4941))
- Improved MCP approval handling: Esc now aborts project MCP approval,
disabled MCP servers are honored for plugins, remembered approvals are
preserved with the env allowlist, and approvals are shared across Git
worktrees
([#4888](#4888),
[#4848](#4848),
[#4889](#4889),
[#4939](#4939))
- Hardened installer downloads and paths
([#4871](#4871))
- Fixed forced `dcode update` checks to bust the CDN cache
([#4862](#4862))
- Prevented failed exit setup from stranding the app
([#4913](#4913))
- Fixed routing so `ctrl+x` goes to the focused `ask_user` input
([#4926](#4926))
- Show `-m` prompts as queued immediately on startup
([#4861](#4861))
- Kept harness-profile diagnostics out of terminal output
([#4943](#4943))
- Avoid tracking inline restart callers
([#4894](#4894))
- Fixed debug console thread ID copying on click
([#4945](#4945))

### Performance Improvements

- Reduced exit latency by coordinating async shutdown teardown
([#4831](#4831))
- Sped up local context detection
([#4922](#4922))

_End release notes preview._

---

> [!NOTE]
> A **New Contributors** section is appended to the GitHub release notes
automatically at publish time (see [Release
Pipeline](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md#release-pipeline),
step 2).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: langchain-oss-automated-triage[bot] <248757908+langchain-oss-automated-triage[bot]@users.noreply.github.com>
Marcelo5444 pushed a commit to Marcelo5444/deepagents that referenced this pull request Jul 30, 2026
Users previously had to approve the same unchanged project MCP server
once per Git worktree, producing repeated approval entries when tools
created temporary worktrees.

Approvals are now **transport-aware** when Git's shared metadata can be
validated:

- **Remote servers with fixed URLs** (`http`/`sse`/`streamable_http`, no
`${}` interpolation, no `command` field) are shared across linked
worktrees via the validated Git common directory. These resolve
identically from any checkout, so sharing is safe.
- **Local stdio servers** (any definition containing `command`) use the
exact worktree root, because the same command can execute different
files in another checkout.
- **Remote servers with interpolated URLs** (containing `${`) use the
exact worktree root, because project `.env` files can resolve the same
template to different endpoints.

The `git_common_dir` marker now participates in approval equality, so a
transport change under the same name (e.g. stdio → http) requires
re-approval. Independent clones still require their own approval,
non-Git projects remain scoped to their exact resolved root, and any
changed command, URL, headers, or other server configuration still
requires re-approval.

Legacy persisted approvals without a `git_common_dir` marker remain
exact-worktree scoped and are never broadened to a Git identity, so
existing entries do not silently widen.

---

Linked worktrees are recognized only when their Git administration
directory belongs to the repository's common metadata, points back to
that exact worktree, and carries its own valid `HEAD` and
self-referential `gitdir` backlink. Malformed, missing, forged, or
linked metadata falls back to exact-root scoping instead of widening
trust. This closes a self-consistent forgery where an attacker's admin
directory passes every acceptance check except its location under
`worktrees/`.

Disabled-server precedence and
`DEEPAGENTS_CODE_DANGEROUSLY_ENABLE_PROJECT_MCP_SERVERS` retain their
existing behavior.

<details>
<summary>Test plan</summary>

- Focused Git, model configuration, MCP loading, disabled-server,
config-manifest, and startup trust-prompt tests: 1005 passed.
- Ruff formatting and lint checks passed for all changed Python files.
- `ty` passed for `deepagents-code`.
- `git diff --check` passed.

</details>
Marcelo5444 pushed a commit to Marcelo5444/deepagents that referenced this pull request Jul 30, 2026
> [!CAUTION]
> Merging this PR will automatically publish to **PyPI** and create a
**GitHub release**.

For the full release process, see
[`.github/RELEASING.md`](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md).

---

_Release notes preview: keep this section in sync with the package
`CHANGELOG.md`. The published GitHub release body is extracted from the
merged `CHANGELOG.md` by `release.yml`, not from this PR description._

---


##
[0.1.45](langchain-ai/deepagents@deepagents-code==0.1.44...deepagents-code==0.1.45)
(2026-07-22)

### Features

- Added the Hooks v2 execution engine and typed hooks data models
([langchain-ai#4880](langchain-ai#4880),
[langchain-ai#4870](langchain-ai#4870))
- Added a filesystem tool allowlist for `dcode` with `--allow-fs-tools`
([langchain-ai#4635](langchain-ai#4635))
- Added a GLM-5.2 harness profile
([langchain-ai#4710](langchain-ai#4710))
- Added a built-in thread inspector skill
([langchain-ai#4769](langchain-ai#4769))
- Replaced Gemini 3.5 Flash with Gemini 3.6 Flash in the model switcher
([langchain-ai#4890](langchain-ai#4890))
- Show experimental mode in the splash screen and debug console
([langchain-ai#4863](langchain-ai#4863))
- Gate debug console click-to-copy behind a checkbox
([langchain-ai#4810](langchain-ai#4810))

### Bug Fixes

- Improved scratch-file handling by allowing cleanup of agent-created
scratch files and safe OS-temp scratch artifacts
([langchain-ai#4860](langchain-ai#4860),
[langchain-ai#4869](langchain-ai#4869))
- Skip grading during `/goal` proposals
([langchain-ai#4941](langchain-ai#4941))
- Improved MCP approval handling: Esc now aborts project MCP approval,
disabled MCP servers are honored for plugins, remembered approvals are
preserved with the env allowlist, and approvals are shared across Git
worktrees
([langchain-ai#4888](langchain-ai#4888),
[langchain-ai#4848](langchain-ai#4848),
[langchain-ai#4889](langchain-ai#4889),
[langchain-ai#4939](langchain-ai#4939))
- Hardened installer downloads and paths
([langchain-ai#4871](langchain-ai#4871))
- Fixed forced `dcode update` checks to bust the CDN cache
([langchain-ai#4862](langchain-ai#4862))
- Prevented failed exit setup from stranding the app
([langchain-ai#4913](langchain-ai#4913))
- Fixed routing so `ctrl+x` goes to the focused `ask_user` input
([langchain-ai#4926](langchain-ai#4926))
- Show `-m` prompts as queued immediately on startup
([langchain-ai#4861](langchain-ai#4861))
- Kept harness-profile diagnostics out of terminal output
([langchain-ai#4943](langchain-ai#4943))
- Avoid tracking inline restart callers
([langchain-ai#4894](langchain-ai#4894))
- Fixed debug console thread ID copying on click
([langchain-ai#4945](langchain-ai#4945))

### Performance Improvements

- Reduced exit latency by coordinating async shutdown teardown
([langchain-ai#4831](langchain-ai#4831))
- Sped up local context detection
([langchain-ai#4922](langchain-ai#4922))

_End release notes preview._

---

> [!NOTE]
> A **New Contributors** section is appended to the GitHub release notes
automatically at publish time (see [Release
Pipeline](https://github.com/langchain-ai/deepagents/blob/main/.github/RELEASING.md#release-pipeline),
step 2).

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: langchain-oss-automated-triage[bot] <248757908+langchain-oss-automated-triage[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dcode Related to `deepagents-code` fix A bug fix (PATCH) internal User is a member of the `langchain-ai` GitHub organization size: XL 1000+ LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants