Skip to content

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

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

fix(mcp): lazy on-demand provider activation with checkpoint persistence#444
sentry-junior[bot] wants to merge 2 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 29, 2026 7:13pm

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

0 participants