fix(binding-mcp): defer mcp(client) lifecycle connect until guard decides - #2426
Merged
Conversation
…ides McpLifecycleStream -- the one persistent south connection an mcp(client) binding multiplexes every subsequent method call over -- inherited the base McpStream#proceedWithRequest, which resolves the configured guard synchronously and connects regardless of the outcome. A guard whose authorization decision is asynchronous, or needs an interactive step (GuardHandler#NEEDS_PREAUTHORIZE), never actually got the chance to gate or challenge this connection: proceedWithRequest returned true before the guard had decided anything. McpLifecycleStream now overrides proceedWithRequest to defer the actual connect until guard.reauthorize's completion callback fires, mirroring the pattern already used for the per-request McpRequestStream. A NEEDS_PREAUTHORIZE decision is surfaced as an elicitCreate challenge -- the same challenge already sent for a backend-initiated elicitation -- so the existing north-facing challenge relay carries it through unchanged; the login callback answer resumes the deferred connect through the existing onReauthorized handling. Resuming also grants the app-level window, matching McpRequestStream#onAcquireCompleted, since omitting it left the connection timing out and reconnecting in a loop. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W7N8Z9vABdU8pVPGthRodY
…ect fix Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01W7N8Z9vABdU8pVPGthRodY
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.
Description
McpLifecycleStream— the one persistent south connection anmcp(client)binding multiplexes every subsequent method call over — inherited the baseMcpStream#proceedWithRequest, which resolves the configured guard synchronously and connects regardless of the outcome. A guard whose authorization decision is asynchronous, or needs an interactive step (GuardHandler#NEEDS_PREAUTHORIZE), never actually got the chance to gate or challenge this connection:proceedWithRequestreturnedtruebefore the guard had decided anything, so the connection was established unauthorized/unchallenged rather than deferred.McpLifecycleStreamnow overridesproceedWithRequestto defer the actual connect untilguard.reauthorize's completion callback fires, mirroring the pattern already used for the per-requestMcpRequestStream. ANEEDS_PREAUTHORIZEdecision is surfaced as anelicitCreatechallenge — the same challenge already sent for a backend-initiated elicitation — so the existing north-facing challenge relay carries it through unchanged; the login callback answer resumes the deferred connect through the existingonReauthorizedhandling. Resuming also grants the app-level window, matchingMcpRequestStream#onAcquireCompleted, since omitting it left the connection timing out and reconnecting in a loop.Validated via
zilla dumpframe-level tracing against a lifecycle-stylemcp(client)binding guarded by a DCR + authorization-code guard: the connection now correctly defers, emits theelicitCreatechallenge, and resumes cleanly once the login callback answers it, with no reconnect storm../mvnw -pl runtime/binding-mcp -am testpasses (178 tests, 0 failures/errors).Fixes # (issue)
Generated by Claude Code