Skip to content

refactor(provider-core): MCP provider sessions live in a McpProviderSessions service - #17446

Open
juliusmarminge wants to merge 1 commit into
t3/provider-core-servicesfrom
t3/provider-mcp-sessions
Open

juliusmarminge wants to merge 1 commit into
t3/provider-core-servicesfrom
t3/provider-mcp-sessions

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

The per-thread T3 MCP credentials lived in a module-level Map in provider-core/server/mcpSession.ts, behind set/read/clearMcpProviderSession functions that any module could call. That's hidden global state, and it leaked between tests.

This PR adds @t3tools/provider-core/server/McpProviderSessions, a service with set, read and clear. The server provides it once, so ProviderSessionManager and every adapter share one instance.

  • Adapters yield it and read the session once per launch. The pure option builders (claudeMcpQueryOverrides, codexThreadRuntimeParams, cursorMcpServers, acpMcpContext) take the session they're given instead of looking it up.
  • makeClaudeAdapterV2 and makeCodexAdapterV2 are now Effect.fn, so they can yield the service.
  • Each adapter and driver env type lists McpProviderSessions. Tests get a fresh instance per layer, which replaces the old manual set/clear on the global.

Part of the provider-package audit (stack #17428).

Model: Claude Opus 5.5 via Claude Code in T3 Code.

🤖 Generated with Claude Code


Devin Review

…essions service

The per-thread MCP credentials were a module-level Map in mcpSession.ts. The
session manager now writes them through McpProviderSessions and adapters yield
it, reading the session once per launch and handing it to their pure option
builders. The server provides one instance; tests get a fresh one per layer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@juliusmarminge
juliusmarminge added this pull request to stack #17428 October 9, 2026 08:25
@juliusmarminge
juliusmarminge marked this pull request as ready for review October 9, 2026 08:25
@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Oct 9, 2026
@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Oct 9, 2026
@macroscopeapp

macroscopeapp Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR replaces global per-thread MCP credential state with an Effect service and threads it through the session manager and numerous provider launch and runtime paths. Because the shared-infrastructure refactor changes credential lifecycle and authentication-sensitive behavior across 48 files, human review is warranted.

You can add or adjust custom eligibility rules. Learn more.

@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown
Contributor

Thread transfer impact

✅ Thread transfer remains within every enforced ceiling.

ℹ️ No successful main baseline artifact is available yet. This run establishes the initial measurement.

Provider Metric Main baseline This PR Impact PR ceiling
Codex Total thread wire — 5.0 KiB — 6.8 KiB ✅
Codex Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Codex Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Codex Live turn WebSocket decoded — 20.9 KiB — 29.3 KiB ✅
Codex Live turn messages — 2 — 8 ✅
Claude Total thread wire — 5.0 KiB — 6.8 KiB ✅
Claude Thread snapshot wire — 3.8 KiB — 4.9 KiB ✅
Claude Live turn WebSocket wire — 1.2 KiB — 2.0 KiB ✅
Claude Live turn WebSocket decoded — 21.2 KiB — 29.3 KiB ✅
Claude Live turn messages — 2 — 8 ✅

Baseline: unavailable · PR result: 519937b · Source CI: success

Scenario 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.

  • Codex decoded thread snapshot: 108.5 KiB
  • Claude decoded thread snapshot: 108.8 KiB

Updated in place by a trusted workflow. PR artifacts are strictly validated and never executed.

@coderabbitai

coderabbitai Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

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: 45a87b1f-72de-4255-86f0-2f807a12bdf2

📥 Commits

Reviewing files that changed from the base of the PR and between 7da182d and 519937b.


📒 Files selected for processing (48)
  • apps/server/src/mcp/OrchestratorMcpToolkit.integration.test.ts
  • apps/server/src/orchestration-v2/AcpRegistryOrchestratorV2.live.test.ts
  • apps/server/src/orchestration-v2/Adapters/AcpAdapterV2.test.ts
  • apps/server/src/orchestration-v2/Adapters/AcpRegistryAdapterV2.test.ts
  • apps/server/src/orchestration-v2/Adapters/AntigravityAdapterV2.test.ts
  • apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.test.ts
  • apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts
  • apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.test.ts
  • apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts
  • apps/server/src/orchestration-v2/Adapters/CursorAdapterV2.testkit.ts
  • apps/server/src/orchestration-v2/Adapters/GrokAdapterV2.test.ts
  • apps/server/src/orchestration-v2/Adapters/OpenCode2AdapterV2.test.ts
  • apps/server/src/orchestration-v2/ClaudeAutomaticDelivery.integration.test.ts
  • apps/server/src/orchestration-v2/CursorOrchestratorV2.live.test.ts
  • apps/server/src/orchestration-v2/DelegatedCompletionDelivery.test.ts
  • apps/server/src/orchestration-v2/GrokOrchestratorV2.live.test.ts
  • apps/server/src/orchestration-v2/OpenCode2OrchestratorV2.live.test.ts
  • apps/server/src/orchestration-v2/ProjectSettingsUpgrade.integration.test.ts
  • apps/server/src/orchestration-v2/ProviderSessionManager.test.ts
  • apps/server/src/orchestration-v2/ProviderSessionManager.ts
  • apps/server/src/orchestration-v2/runtimeLayer.test.ts
  • apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts
  • apps/server/src/provider/Drivers/AntigravityDriver.test.ts
  • apps/server/src/provider/Drivers/AntigravityDriver.ts
  • apps/server/src/provider/Drivers/CodexDriver.test.ts
  • apps/server/src/provider/ProviderInstanceRegistry.test.ts
  • apps/server/src/provider/ProviderRegistry.test.ts
  • apps/server/src/server.ts
  • packages/provider-acp-registry/src/server/adapter.ts
  • packages/provider-acp/src/server/adapter.ts
  • packages/provider-core/package.json
  • packages/provider-core/src/server/McpProviderSessions.ts
  • packages/provider-core/src/server/mcpSession.ts
  • packages/provider-cursor/src/server/adapter.test.ts
  • packages/provider-cursor/src/server/adapter.ts
  • packages/provider-cursor/src/server/driver.test.ts
  • packages/provider-grok/src/server/adapter.ts
  • packages/provider-grok/src/server/driver.test.ts
  • packages/provider-muse/src/server/adapter.test.ts
  • packages/provider-muse/src/server/adapter.ts
  • packages/provider-muse/src/server/driver.ts
  • packages/provider-opencode/src/server/adapter.test.ts
  • packages/provider-opencode/src/server/adapter.ts
  • packages/provider-opencode/src/server/driver.test.ts
  • packages/provider-opencode/src/server/v2/adapter.ts
  • packages/provider-pi/src/server/adapter.test.ts
  • packages/provider-pi/src/server/adapter.ts
  • packages/provider-pi/src/server/driver.test.ts

💤 Files with no reviewable changes (1)
  • packages/provider-core/src/server/mcpSession.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.



📝 Walkthrough

Walkthrough

The pull request adds an Effect-based McpProviderSessions service, removes the legacy synchronous registry, and updates provider adapters, orchestration code, runtime layers, and tests to use the service.

Changes

MCP provider session migration

Layer / File(s) Summary
Session service and runtime wiring
packages/provider-core/src/server/McpProviderSessions.ts, packages/provider-core/src/server/mcpSession.ts, packages/provider-core/package.json, apps/server/src/server.ts
The new service stores, reads, and clears thread-scoped MCP configuration. The legacy registry is removed. Shared runtime and test layers provide the new service.
Provider adapter integration
packages/provider-acp/src/server/adapter.ts, packages/provider-cursor/src/server/adapter.ts, apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts, apps/server/src/orchestration-v2/Adapters/CodexAdapterV2.ts, packages/provider-*/src/server/adapter.ts
Adapters obtain MCP sessions from the Effect service. Several helper functions now receive resolved session configuration directly. Adapter construction gains service requirements where needed.
Provider session management
apps/server/src/orchestration-v2/ProviderSessionManager.ts, apps/server/src/orchestration-v2/testkit/ProviderReplayHarness.ts
Credential preparation and cleanup use effectful service operations. Credential-ID checks remain in cleanup logic. Replay harness layers include the service.
Test environment and fixtures
apps/server/src/orchestration-v2/**/*.test.ts, packages/provider-*/src/server/*.test.ts, apps/server/src/provider/**/*.test.ts
Tests provide McpProviderSessions.layer, seed sessions through set, read sessions through read, and remove direct global-registry cleanup. Adapter fixtures use effectful construction where required.

Priority: ➖ Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor


Merge Risk: ⚪ Minimal · up to 51993

The session migration has no identified issue requiring a fix before merge.

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check Warning The description clearly explains the problem and the implementation, but it omits the required Scope and approval section and focused Verification results. It references stack #17428 without providing… Add a ## Scope and approval section with the triaged issue or explicit maintainer approval, including a link and approval comment. Add a ## Verification section that lists the focused tests or manual checks run, their observed results, …
✅ Passed checks (3 passed)
Check name Status Explanation
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.
Title check Passed The title clearly and concisely identifies the main change: moving MCP provider sessions into an McpProviderSessions service.

Full details: Description check

Explanation

The description clearly explains the problem and the implementation, but it omits the required Scope and approval section and focused Verification results. It references stack #17428 without providing the required issue or approval link.

Resolution

Add a ## Scope and approval section with the triaged issue or explicit maintainer approval, including a link and approval comment. Add a ## Verification section that lists the focused tests or manual checks run, their observed results, and any checks not completed.



  • Fix all pre-merge checks with AI
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR

🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR


  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

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

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:L 100-499 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant