Skip to content

fix(mcp): lazy on-demand provider activation with checkpoint persistence#444

Closed
sentry-junior[bot] wants to merge 4 commits into
mainfrom
fix/mcp-provider-skill-gate
Closed

fix(mcp): lazy on-demand provider activation with checkpoint persistence#444
sentry-junior[bot] wants to merge 4 commits into
mainfrom
fix/mcp-provider-skill-gate

Conversation

@sentry-junior
Copy link
Copy Markdown
Contributor

@sentry-junior sentry-junior Bot commented May 29, 2026

MCP providers were either skill-gated (original) or eagerly connected for all configured providers at turn start (first iteration). This PR takes the correct lazy approach: providers connect only when the model explicitly asks for one, and activated providers persist across turns.

Root cause (JUNIOR-30)

Two gates blocked MCP without loadSkill: a skill-scope filter in resolveProviderTools, and activation only happening for checkpoint-preloaded skills. Both are removed.

The lazy model

searchMcpTools({ provider: "notion" }) and callMcpTool("mcp__notion__*") both auto-activate the provider on demand before executing. Auth prompts fire normally if credentials are missing. No connections happen at turn start for providers the model didn't ask for.

Checkpoint persistence

activeMcpProviderNames added to AgentTurnSessionCheckpoint. After a provider is activated (lazily or via skill), syncResumeState() captures it. Future turns restore only checkpointed providers — no cold-start listTools() for unused plugins.

Prompt advertising

<available-mcp-providers> block added to the turn context prompt listing configured-but-inactive providers by name and description, with zero network cost. The model knows what's available and can activate on demand.

What stays unchanged

loadSkill still works and still activates its plugin provider. Backward compatible with all existing skill/MCP flows.


View Session in Sentry

@vercel
Copy link
Copy Markdown

vercel Bot commented May 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview, Comment May 31, 2026 12:28am

Request Review

Replaces the eager activateAllProviders() approach with a model-driven
lazy activation model:

- Providers connect only when the model first accesses them, not at
  turn start. No wasted listTools() calls for unused providers.
- searchMcpTools({ provider }) and callMcpTool('mcp__provider__*')
  both auto-activate the named provider on demand. Auth prompts fire
  normally if credentials are missing or expired.
- Activated providers are persisted in the turn checkpoint under
  activeMcpProviderNames and restored at the start of future turns,
  so providers stay live across multi-turn conversations without
  re-activating on every request.
- The <available-mcp-providers> prompt block advertises configured
  but inactive providers (name + description) with zero network cost,
  so the model knows what is available before deciding to activate.
- syncResumeState() now also captures activeMcpProviderNamesForResume
  so checkpoint sync happens correctly after lazy activation inside tools.
- loadSkill continues to work and still activates its plugin provider.

Co-Authored-By: claude-opus-4-5 <claude-opus-4-5@anthropic.com>
@sentry-junior sentry-junior Bot force-pushed the fix/mcp-provider-skill-gate branch from ea7e62f to 665fcea Compare May 29, 2026 18:31
@sentry-junior sentry-junior Bot changed the title fix(mcp): activate all providers at turn start without skill gate fix(mcp): lazy on-demand provider activation with checkpoint persistence May 29, 2026
parseMcpProviderFromToolName: replace regex with indexOf('__') split.
The regex failed for provider names containing a single underscore; the
string approach is also more readable and explicit about the delimiter.

getActiveProviderNames: remove the thin wrapper around getActiveProviders().
Both methods returned the same value; inlining the call site removes
unnecessary public API surface.

Co-authored-by: David Cramer <david@sentry.io>
Replace checkpoint-specific Pi message stores with a conversation-keyed session log that restores Pi messages, MCP provider state, and authorization observations from one durable append-only source.

Add compaction reset handling via session ids, tighten eval timeouts, and cover OAuth/resume continuity with integration and eval coverage.

Co-Authored-By: GPT-5 Codex <codex@openai.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 3 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 17e3aed. Configure here.

Comment thread packages/junior/src/chat/prompt.ts
Comment thread packages/junior/src/chat/pi/derived-state.ts
const juniorPackageRoot = path.resolve(__dirname, "../junior");
const workspaceRoot = path.resolve(__dirname, "../..");
const applyEnvFile = createEnvFileLoader();
const EVAL_TEST_TIMEOUT_MS = 60_000;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Eval timeout cut from 5 minutes to 1 minute

Medium Severity

The eval test timeout was reduced from 300,000ms (5 minutes) to 60,000ms (1 minute). The OAuth workflow evals involve multiple LLM round trips, MCP provider connections, authorization pauses with auto-completion, and resumed turns — workloads that routinely exceed 1 minute under real LLM latency conditions. This risks widespread flaky eval failures.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 17e3aed. Configure here.

Keep loadSkill from advertising plugin-backed skills as MCP-capable unless runtime provider activation returns MCP catalog metadata. This prevents non-MCP skills like Sentry from steering the agent toward searchMcpTools instead of their CLI workflow.

Co-Authored-By: GPT-5 Codex <codex@openai.com>
@dcramer
Copy link
Copy Markdown
Member

dcramer commented May 31, 2026

Closing this draft so the branch can be re-opened as a fresh PR with the larger session-log scope.

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