fix(mcp): lazy on-demand provider activation with checkpoint persistence#444
Draft
sentry-junior[bot] wants to merge 2 commits into
Draft
fix(mcp): lazy on-demand provider activation with checkpoint persistence#444sentry-junior[bot] wants to merge 2 commits into
sentry-junior[bot] wants to merge 2 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
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>
ea7e62f to
665fcea
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 inresolveProviderTools, and activation only happening for checkpoint-preloaded skills. Both are removed.The lazy model
searchMcpTools({ provider: "notion" })andcallMcpTool("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
activeMcpProviderNamesadded toAgentTurnSessionCheckpoint. 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
loadSkillstill works and still activates its plugin provider. Backward compatible with all existing skill/MCP flows.View Session in Sentry