Repository navigation
Description
Describe the bug
For a remote HTTP MCP server using Entra ID OAuth (Azure DevOps remote MCP,
https://mcp.dev.azure.com/<org>), the interactive CLI completes the browser
round-trip but never exchanges the authorization code for a token.
Observed with Copilot CLI running inside WSL2 (Ubuntu 26.04 on a Windows 11
host). I have not tested native Windows or native Linux, so I cannot say whether
this is WSL-specific — see the note at the end.
Observed sequence:
- On startup the CLI auto-connects, gets the expected
401with
WWW-Authenticate: Bearer resource_metadata="https://mcp.dev.azure.com/.well-known/oauth-protected-resource/<org>". - Metadata discovery and dynamic client registration succeed — a registration
record is written to~/.copilot/mcp-oauth-config/<key>.json, with
authorizationServerUrl,clientId: aebc6443-996d-45c2-90f0-388ff96faa56,
redirectUri: http://127.0.0.1:41003/. - The CLI logs
Opening browser for <server> authentication...then
Requesting access token for <server>.... - I complete the sign-in. The browser lands on
http://127.0.0.1:41003/?nonce=<nonce>&code=<code>and the CLI's own
callback page renders ("Authorization Successful"). So the code reaches
the CLI's listener. - Nothing further happens. The TUI stays on "Authenticating: " /
"Connecting to ...". No<key>.tokens.jsonis ever written, and no
log line is emitted after this point.
The <key>.verifier file is not removed. Per the runtime's own state
machine (MCP OAuth token exchange completed; saving tokens ->
MCP OAuth tokens saved; clearing code verifier), a surviving verifier means
the exchange never completed successfully.
The MCP transport worker meanwhile keeps cycling:
[ERROR] [rust:rmcp::transport::worker] worker quit with fatal: Transport channel closed,
when Client(OAuthChallenge { www_authenticate_header: "...oauth-protected-resource/<org>",
response: McpOAuthHttpResponse { status_code: 401, ... } })
The failure is in the CLI, not the environment
I reproduced the identical flow manually with a small script — same client ID,
same scope, same vscode.dev relay, same loopback pattern — and it succeeds
on the first attempt:
TOKEN EXCHANGE: HTTP 200 SUCCESS
scope : https://mcp.dev.azure.com/Ado.Mcp.Tools https://mcp.dev.azure.com/.default
token_type : Bearer
expires_in : 4102
refresh_token: present
Driving the MCP server with that token also works:
[initialize] HTTP 200 serverInfo: {"name": "AzureDevOps.Mcp", "version": "1.0.0.0"}
[tools/list] HTTP 200 tool count: 43
Writing that token into ~/.copilot/mcp-oauth-config/<key>.tokens.json in the
CLI's own schema (accessToken, refreshToken, expiresAt, requestedScope,
scope) makes the server connect normally. grant_type=refresh_token renewal
against the same endpoint also works.
So tenant config, consent, scopes, app registration, the vscode.dev relay,
loopback reachability and the MCP server are all confirmed working. The only
step that fails is the CLI's own code->token exchange.
Affected version
GitHub Copilot CLI 1.0.105
Steps to reproduce the behavior
~/.copilot/mcp-config.json:{"mcpServers":{"ado-remote-mcp":{"type":"http","url":"https://mcp.dev.azure.com/<org>"}}}- Start
copilot. It auto-connects and begins the OAuth flow. - Run
/mcp auth ado-remote-mcp, pressc, open the URL, complete sign-in. - Browser shows the CLI's "Authorization Successful" page.
ls ~/.copilot/mcp-oauth-config/— no.tokens.json; the.verifier
remains. The TUI never leaves the connecting state.
Expected behavior
After the callback is received, the CLI proceeds to exchanging_code, stores
the tokens, clears the verifier, and connects the server.
Additional context
- No diagnostics are available for this step.
RUST_LOGis accepted but
produces no additional output, and the process log contains nothing at all
between the callback and the stall. The runtime has specific failure strings
(ExchangeResponseFailure,failed to clear OAuth code verifier after authorization failure) but none reach the log file. Surfacing the token
endpoint's response on failure would make this self-diagnosable. ctrl+g(device code) does not help:mcp.dev.azure.comadvertises no
device-code support, so the CLI logsServer does not support device code flow - falling back to browserand retries the browser path.- The callback arrives as
?nonce=<nonce>&code=<code>with nostate
parameter —vscode.dev/redirectconsumesstate(the CLI encodes the
nonce in the state fragment). If the handler validatesstate, that may be
relevant. Unverified. - Possibly related: Regression (1.0.88 → 1.0.89): MCP OAuth authorization page opens on every ACP session instead of the challenge being resolved silently #4994, ACP mode: MCP OAuth token is never persisted after successful sign-in — every new session re-opens the browser #5192, MCP OAuth tokens for HTTP servers not reliably reused across sessions — duplicate cache-key entries force repeated re-auth #4695 — all ACP-mode or cross-session reuse.
This one is plain interactive mode on first sign-in. - Environment caveat (WSL2). This was only observed with the CLI running
inside WSL2; I have not reproduced it on native Windows or native Linux, so I
cannot confirm whether the platform matters. Two WSL-specific points, both
ruled out as causes:- WSL has no browser launcher by default (
xdg-open/wslviewabsent), so the
CLI'sOpening browser...step is a silent no-op untilBROWSERis set.
That produces a separate earlier symptom (no prompt at all). After adding a
launcher the browser opens correctly, and the stall described above persists. - Windows→WSL loopback forwarding works. An independent listener inside WSL
received the browser's redirect on127.0.0.1(including the follow-up
favicon.icorequest), so the callback path itself is sound.
- WSL has no browser launcher by default (
Activity
hstaudacher commentedon Nov 18, 2026
@poppj1 thanks for the thorough analysis. Several fixes to the MCP sign-in callback handling have landed since 1.0.105, including one for WSL setups where the browser can't be launched and the callback code was never consumed. Could you retry on the latest release (and again after the next one) and tell us whether the browser opened automatically or you had to copy the URL, and share a
--log-level debuglog if it still stalls?svkatta commentedon Nov 18, 2026
Retested on November 18, 2026, using Copilot CLI 1.0.114, confirmed as latest stable by copilot update stable.
Environment: Ubuntu 24.04 / WSL2, Linux x64. BROWSER=/usr/bin/wslview; wslview works, but xdg-open is absent. Tested with a fresh COPILOT_HOME, no cached MCP tokens, and without the external OAuth workaround.
Browser did not open automatically. I manually opened the CLI-displayed authorization URL using wslview. The browser reported “Authorization successful”, but Copilot remained stuck. No .tokens.json was written, and the PKCE verifier remained.
Relevant exact debug lines:
2026-11-18T18:19:30.319Z [DEBUG] [rust:mcp_client::oauth_flow] Entra broker not eligible; using the browser OAuth flow {"server_url":"https://mcp.dev.azure.com/","broker_available":false,"force_device_code":false}
2026-11-18T18:19:30.327Z [ERROR] Opening browser for ado-remote-mcp authentication...
2026-11-18T18:19:30.478Z [DEBUG] [rust:mcp_client::oauth_flow] failed to open OAuth browser {"error":"Spawn { command: "xdg-open", source: Os { code: 2, kind: NotFound, message: "No such file or directory" } }"}
2026-11-18T18:19:30.485Z [ERROR] Requesting access token for ado-remote-mcp...
Manual browser launch occurred at 18:20:32 UTC. After successful browser authorization, the CLI was still running without tokens at 18:25:38, and remained in that state until deliberate shutdown at 18:27:36.
Sequencing caveat: startup initiated authentication before folder trust was accepted. I subsequently ran /mcp auth ado-remote-mcp, so two authentication requests overlapped. Both remained pending until shutdown:
2026-11-18T18:27:36.979Z [WARNING] [rust:copilot_sdk::jsonrpc] JsonRpcClient::send_request JSON-RPC request finished {"elapsed_ms":"487131","method":"session.mcp.oauth.authenticate","request_id":28,"status":"failed","code":-32603,"error":"Request session.mcp.oauth.authenticate failed with message: MCP_OAUTH_ERROR[aborted]: OAuth flow aborted"}
2026-11-18T18:27:36.981Z [WARNING] [rust:copilot_sdk::jsonrpc] JsonRpcClient::send_request JSON-RPC request finished {"elapsed_ms":"454347","method":"session.mcp.oauth.authenticate","request_id":41,"status":"failed","code":-32603,"error":"Request session.mcp.oauth.authenticate failed with message: MCP_OAUTH_ERROR[aborted]: OAuth flow aborted"}
Those final abort messages resulted from intentional test shutdown, not spontaneous authentication failure. The stall persists in this reproduction, but its precise internal cause remains unconfirmed.
svkatta commentedon Nov 18, 2026
@hstaudacher i can send more detailed logs zip in team chat(sakatta@microsoft.com) . i am worried what sensitive info (auth tokens) it might contain to post it publically.
hstaudacher commentedon Nov 19, 2026
Thanks for the careful retest, @svkatta. This matches #5510 (Entra browser sign-in on WSL when
xdg-openis missing), so we're closing this as a duplicate and tracking it there. Please don't post the log bundle publicly; I'll reach out internally to collect it.xdg-openis missing, and/mcpAuthenticate shows a URL that fails with "State mismatch" #5510