feat(server): /mcp narrows a client's modes from T3-Mode-Limit #16653
main fromrefs/pull/16653/head·merged by juliusmarminge View on GitHubPart of cross-environment orchestration: an environment linked to another signs in to its /mcp as an outside agent. Every linked call has to carry the calling agent's own limits, so a plan-mode agent on the laptop can't start full-access work on the box just because the link was approved at auto.
What changes
/mcpreads an optionalT3-Mode-Limit: <runtime>/<interaction>header, from OAuth (mcp-client) callers only.- The header can only narrow the client's ceiling. A broader value changes nothing, and a malformed one gets a 400 (
invalid_mode_limit). clientModeCeilingreplacesclientRuntimeModeCeiling, adding an interaction ceiling.loadCallerand the orchestrator MCP service use it, so the access declarations and the in-lockDispatchModeLimitcheck enforce the narrowed modes.- Provider sessions ignore the header; their limits come from their thread.
Verification
- New test in
McpHttpServer.test.ts. A real/mcp, with anautoOAuth client, serves a probe tool that starts a thread throughMcpToolAccess.startsThreads. Results:- no header →
auto/default; approval-required/plan→ narrowed, and escalation requests above it are refused;- a broader header → unchanged;
- malformed → 400.
- no header →
- Mutation-checked both ways: dropping the narrowing fails the test, and so does letting a broader header widen the ceiling.
- MCP and auth suites: 37 files, 364 tests, all passing.
Opus 5.5 via Claude Code.
🤖 Generated with Claude Code
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
juliusmarminge changed the title
juliusmarminge added labelsmacroscope-review
End-to-end run, two real servers#
Two
t3 serveprocesses from the top of this stack, each with its own data directory, on one machine. A laptop (port 3971) and a box (port 3972). Their projects are clones of one bare origin, so they share a repository. An outside agent (OAuth with a pairing code) drives the laptop's/mcp, and real Claude Sonnet 5.5 turns run on both sides. The last part repeats the run over Tailscale HTTPS (a*.ts.netHTTPS address).Through the link, the box refused launches above the caller's modes. A plain call at
full-accessgot "Child runtime mode full-access is broader than parent mode auto." (the link's access wasauto). The same launch atautowithT3-Mode-Limit: approval-required/plangot "Child runtime mode auto is broader than parent mode approval-required.", so the header narrowed the ceiling below the link's.CI also showed an unused
MODE_LIMIT_HEADERexport (Knip). The constant now lives inMcpInvocationContext, where #16684 already uses it.Opus 5.5 via Claude Code.
Note
Reviews paused#
It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the
reviews.auto_review.auto_pause_after_reviewed_commitssetting.- Last reviewed commit: 0b078468c5f2610a2366bac9eac2acfb4f3a31ce
- Latest commit, not reviewed: 898a8133696e76e333ff0929472a28c710a1afa3
Use the following commands to manage reviews:
@coderabbitai resumeto resume automatic reviews.@coderabbitai reviewto trigger a single review.
Use the checkboxes below for quick actions:
- ▶️ Resume reviews
- 🔍 Trigger review
No actionable comments were generated in the recent review.
ℹ️ Recent review info
-
⚙️ Run configuration
-
- Configuration used: Path: .coderabbit.config.ts
- Review profile: CHILL
- Plan: Team
- Run ID:
d94a2616-bd0d-4db2-a460-cf472ccc8b20
📥 Commits
-
Reviewing files that changed from the base of the PR and between 8eadb66c31d5b146ef2f524f34c7470a6e178985 and 0b078468c5f2610a2366bac9eac2acfb4f3a31ce.
📒 Files selected for processing (1)
-
apps/server/src/mcp/OrchestratorMcpService.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
-
Walkthrough
-
The MCP HTTP server accepts a
T3-Mode-Limitheader for authenticated clients. It validates the requested modes and applies them as limits to the client’s runtime and interaction modes. MCP callers without a thread use the resulting ceilings.Changes: OAuth Client Mode Limits
Priority:Layer / File(s) Summary Request mode-limit contract and validation
apps/server/src/mcp/McpInvocationContext.ts,apps/server/src/mcp/McpHttpServer.tsThe invocation context defines the mode-limit header and optional narrowed modes. The HTTP server validates the header and returns HTTP 400 for malformed or unsupported values. Effective mode ceilings and callers
apps/server/src/mcp/McpInvocationContext.ts,apps/server/src/mcp/OrchestratorMcpService.ts,apps/server/src/mcp/threadAccess.ts,apps/server/src/mcp/McpHttpServer.test.tsclientModeCeilingindependently applies runtime and interaction limits. Callers without a thread use those ceilings. The integration test checks narrowing, non-widening, escalation-denied responses, and invalid headers. NormalEstimated code review effort: 3 (Moderate) | ~20 minutes
Change: Feature
Sequence Diagram(s)#
sequenceDiagram participant OAuthClient participant McpHttpServer participant OrchestratorMcpService OAuthClient->>McpHttpServer: Send request with T3-Mode-Limit McpHttpServer->>OrchestratorMcpService: Pass invocation context to handler OrchestratorMcpService->>OrchestratorMcpService: Calculate runtime and interaction ceilingsSuggested reviewers:
maria-rcks
Merge Risk:
Minimal · previous review0b078-
The change narrows OAuth MCP callers’ mode limits, and both limits reach dispatch enforcement. No concrete merge-blocking risk is apparent.
🚥 Pre-merge checks | ✅ 3 | ❌ 1
-
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Description check ⚠️ Warning The description explains the problem, implementation, affected callers, and verification results. It does not include the required Scope and approvalsection or an issue, approval reference, or vali…Add a ## Scope and approvalsection. Link the triaged issue or maintainer approval with the approval comment, or explain why this focused change qualifies for an exemption.✅ Passed checks (3 passed)
-
Check name Status Explanation Title check ✅ Passed The title clearly describes the main change: /mcpnarrows client modes usingT3-Mode-Limit.Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check
-
Explanation
The description explains the problem, implementation, affected callers, and verification results. It does not include the required
Scope and approvalsection or an issue, approval reference, or valid exemption rationale.
-
✨ Finishing Touches
-
📝 Generate docstrings
-
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Approvability#
Verdict: Needs Human Approval
Macroscope's review found this PR requires human approval — The PR adds an optional T3-Mode-Limit header that changes MCP authorization ceilings and constrains downstream thread modes. It also introduces a new static-analysis suppression in the test, making this more than a routine additive or mechanical change.
No code changes detected at
You can add or adjust custom eligibility rules. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).898a813. Prior analysis still applies.Taking over this one as maintainer for batch usage-billing-05. I will preserve this branch's commits, bring it onto current main, verify request-local narrowing through the MCP access and dispatch paths, and review its linked-environment compatibility. Tests and implementation will get separate passes followed by independent reviews. This batch will not merge the PR.
juliusmarminge assignedjuliusmarminge
Closing as superseded by the already-published maintainer replacement #21670, the foundation of the replacement linked-environment stack documented on #16684.
I compared all five changed paths in this PR against that replacement: OAuth-only header parsing, malformed-header rejection, both independent mode ceilings, access/dispatch wiring, and the HTTP regression case are retained there. The replacement also has the integrated two-server proof required by the linked-environment work. Thanks @juliusmarminge for the original design and implementation; the replacement credits that work.
Batch usage-billing-05 made no push here and stopped its redundant test pass once the overlap was confirmed. The surviving stack remains owned by batch ssh-relay-remote-15; its human permission-policy approval and platform/real two-host verification limits remain as reported there. This closure does not merge or approve that stack.
juliusmarminge closed this
juliusmarminge reopened this
Documentation/reuse cross-link for caller mode ceilings: Forwarding must retain the caller's limits even when a linked credential has broader access.
The native messaging Ideas discussion and complete fork brief now bring together why/when/how, original/support PR dependencies, closed replacement history, later-layer scope, exact-head evidence and limitations. The corresponding core layer and selected fixes are represented in the version-pinned stable integration; it is not a copy of every current PR head.
The stable source/download preview has its own manifest and evidence; its results do not establish this PR head's acceptance. This temporary fork is maintained until T3 supplies the capability or a better replacement. Original upstream authorship is retained. This is a documentation cross-link, not a new feature PR or merge request.
Prepared with GPT-6.1 Sol through Codex in T3 Code. Implementation and historical model credits are stated in the linked brief.
Factory catalog cross-reference — 2026-10-26. Included capability lineage: forwarded mode ceilings keep a factory worker within its caller’s authority when a linked credential is broader.
Factory Ideas · Pinned fork source/guide · Source release. Version-pinned community experimental source preview; full lifecycle acceptance remains open. No upstream endorsement or current-PR-head test acceptance is claimed. Julius Marminge/T3 authorship is retained; later upstream heads are not acceptance evidence or a required cherry-pick sequence.
Prepared with GPT-6.1 Sol through Codex in T3 Code.
juliusmarminge merged this1b1ad04
juliusmarminge closed this
Sign in to join this conversation.
Thread transfer impact#
✅ Thread transfer remains within every enforced ceiling.
Baseline:
5808469· PR result:898a813· Source CI: successScenario and decoded snapshot size
10 historical turns, 5 command tools per turn, 878.9 KiB retained MCP result per historical turn, and a 1.05 MiB retained result in the measured turn.
Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.