fix(mcp): open the browser and keep the authorization URL visible for /mcp auth - #920
Open
ismetanin wants to merge 2 commits into
Open
fix(mcp): open the browser and keep the authorization URL visible for /mcp auth#920ismetanin wants to merge 2 commits into
ismetanin wants to merge 2 commits into
Conversation
`/mcp auth <server>` announced "Opening browser to authorize <server>..." but nothing ever launched a browser: the auth command bridge wired `openBrowser` to a notification instead of `utils/open-browser.ts`. The URL that notification carried was then destroyed, because the announcement followed it immediately and consecutive status lines coalesce in the TUI (`showStatus` rewrites the trailing status text in place). With no browser and no reachable URL, the interactive flow blocked on its loopback callback until the session ended. The bridge now calls the real launcher, and each branch of `runInteractive` emits a single notification that carries the authorization URL, so a failed launch still leaves the user a copy-pasteable link.
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.
Problem
/mcp auth <server>can never complete an interactive OAuth login. It printsand then hangs forever with no further output.
Two bugs compound:
auth/commands-auth-dispatch.tswired theopenBrowserdependency toctx.ui.notify(...), so the announcement was simply untrue. The repo already ships a real launcher atsrc/utils/open-browser.ts(used by the provider login dialog).redirectToAuthorizationinsidebeginAuthorization, and theOpening browser…line was emitted immediately after it. Consecutive status notifications coalesce in the TUI —showStatusrewrites the trailing status text in place when the last two chat children are the previous status spacer/text — so the second line overwrote the URL milliseconds after it appeared.With no browser and no reachable authorization URL,
runInteractiveparks onchannel.waitForCode()until the session ends.Fix
auth/commands-auth-dispatch.ts—openBrowsercallsutils/open-browser.tsfor real.auth/commands-auth.ts— each branch ofrunInteractiveemits exactly one notification, carrying the authorization URL, so a failed launch still leaves a copy-pasteable link. Behavior for thecallbackUrl-override (paste) branch is unchanged apart from the merged message.builtin/mcp/changes.md— fork ledger entry.No config, transport, or token-storage behavior changes.
Tests
test/mcp/oauth-callback.test.tsgains an assertion that the single announcement contains the authorization URL, for both the loopback and the callback-override branch. Both assertions fail onmainand pass with the fix (verified by reverting the two source files with the test in place).Verification
npm run checktest/mcp/oauth-callback.test.ts,oauth-headless.test.ts,auth-modes.test.tssenpi-qaChannel 4 (cli-smoke.mjs --self-test)senpi-qaflow driver (evidence20260817-mcp-oauth-browser-launch)The QA driver runs
runAuthfrom source against the repo's fake IdP fixture, with a recording stub namedopenfirst onPATHso no real browser opens:Note:
test/mcp/oauth-race.test.tsfails identically with and without this change in my environment (@earendil-works/pi-tuiworkspace dist not built); unrelated to this PR.