Repository navigation
Fix MCP auth spinner after rejected token - #340547
Conversation
Stop retrying an unchanged MCP authentication challenge after the server restart rejects a forwarded token. Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
🟡 Changes recommended
Remaining authentication-state edge cases can leave the spinner active or suppress a needed retry.
2 open findings
What changed in this PR
Updates Agent Host MCP authentication tracking to stop retrying rejected tokens and restore the Sign In action.
Changes:
- Preserves silent-authentication attempts across server restarts.
- Marks a returning unchanged challenge as rejected.
- Adds regression coverage for the rejection sequence.
| File | Description |
|---|---|
| src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostCustomizationService.test.ts | Tests rejection handling and retry suppression. |
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostCustomizationService.ts | Tracks token forwarding, restarts, and rejection. |
🧠 Review effort: Balanced
💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
UI validation videosThese recordings use deterministic Agent Host lifecycle data with the production Customizations widget. The pre-fix replay models the Before the fixThe connector remains on the Authenticating spinner after the unchanged insufficient-scope challenge returns, and no Sign In action is available. After the fixThe same terminal mcp-connector-before-fix.mp4mcp-connector-after-fix.mp4 |
Reconcile silent authentication attempts from customization notifications and include the protected resource name in challenge identity. Co-authored-by: Copilot <[email protected]>
…ation (#342479) <!-- Thank you for submitting a Pull Request. Please: * Read our Pull Request guidelines: https://github.com/microsoft/vscode/wiki/How-to-Contribute#pull-requests * Associate an issue with the Pull Request. * Ensure that the code is up-to-date with the `main` branch. * Include a description of the proposed changes and how to test them. --> Fixes #341123 ## Problem The runtime sends Copilot Connector MCP requests with **only** the SDK session's GitHub credential (the token set through `gitHubAuth.setCredentials` / `gitHubToken`). When the gateway returned `403 insufficient_scope`, the runtime fell back to a generic `mcp.oauth_required` (`reason=upscope`). VS Code's **Sign In**, and silent auto-auth, then created a GitHub session with only `write:plugin_gateway_connections` and forwarded it as an MCP token. The runtime ignores that token for connector servers, so the server restarted with the old credential, got another 403, and looped. Meanwhile the client logged "MCP authentication succeeded". A second issue made the working path unreachable. `CopilotConnectorsService.authorize()` returned early if **any** same-account session had the connector scope. That includes the narrow session created by MCP Sign In, which never qualifies as the Copilot credential. So Authorize did nothing in exactly the state the issue logs show. ## Changes **Sign In for connector servers goes through Connector authorization** - `authenticateMcpServer` detects connector-owned servers. Detection uses new host-published `vscode.mcpServerConnectorName` metadata, or a `write:plugin_gateway_connections` challenge as a fallback. - For those servers it calls `ICopilotConnectorsService.authorize()`, forwards the Copilot credential (which prefers the full-scope session), then force-reconciles that connector through a new narrow `refreshAgentHostSessions(connectorName)` API. - `resolveMcpServerAuthentication` refuses connector-scope challenges. So neither the silent nor the interactive path creates a narrow session or forwards an MCP token for a connector. - `authorize()` now skips consent only when a session has the connector scope **and** every scope of the default session. **The agent host does not answer connector upscope requests with tokens** - `CopilotAgentSession.resolveMcpAuthentication` skips connector-owned pending requests. - Before a forced reconcile, affected servers are shown as Starting. After the reconcile succeeds, pending requests from before it are cancelled; requests raised by the restarted server are kept. If a turn is active, refresh is deferred, so stale requests are released straight away instead. - #340547's rejected-token suppression is unchanged. **Truthful reporting** - The forwarding log now says the token was forwarded, not that authentication succeeded. - `authenticateMcpServer` reports success only once the server leaves AuthRequired. This is a bounded wait (60s) that is cancellation-safe and cleans up its listeners. Connector servers must reach Ready. - If a connector returns the same challenge after restarting, Sign In returns `false` and shows a localized message. It asks the user to authorize Copilot connectors with the same GitHub account they use for Copilot. - **Behaviour change for non-connector servers:** if a forwarded token leaves the challenge unchanged, Sign In now waits up to 60s and returns `false`. Previously it returned `true` right after forwarding. **`ConnectorStatus.authorizationRequirement`** - Reconcile now reports connector ownership for each runtime server, and `authorizationRequirement`. - A connector server in `needs-auth` with no `mcp.oauth_required` is shown as AuthRequired (insufficient scope). This covers the planned runtime fix that will stop emitting `mcp.oauth_required` for connector 403s. ## Notes for reviewers - **Same token string after Authorize (#338934):** `_applyGitHubToken` skips `setCredentials`. That should be fine, because the runtime re-reads the session credential on every request and the forced reconcile always restarts the server. I have not confirmed against the live gateway that GitHub widens scope on the same token string. - **Forced reconcile:** the runtime's `replace_managed_servers` already cancels its pending OAuth before restarting the server, so cancelling VS Code's stale entry afterwards is safe. - **Mission Control / scoped credentials:** `updateGitHubCredentials` is only called for static-token sessions, so nothing throws. The challenge comes back and Sign In returns `false` with the message. - **Known gaps:** - Connector refresh only exists for the local agent host, so on a remote host Sign In authorizes but usually times out. - Servers identified only by the scope fallback can't get a targeted reconcile. - The end-to-end integration test (coexisting sessions, Sign In through tool discovery) was not added. It needs a real runtime and gateway. ## How to test 1. Use a default GitHub session that lacks `write:plugin_gateway_connections`. Optionally add a narrow session that has only that scope. 2. Open an Agents session with the WorkIQ / Kusto connectors and click **Sign In** on a connector row. 3. Expect a consent prompt for the default scopes plus `write:plugin_gateway_connections` on the same account. Then the connector restarts, reaches Ready, and lists its tools. The gateway's `x-oauth-scopes` should include the connector scope. Validation run locally: | Command | Result | |---|---| | `./scripts/test.sh --run` agentHostAuth, copilotConnectorsService, agentHostCustomizationService, copilotAgentSession, copilotSessionLauncher, agentMetaReaders | 1621 passing | | `./scripts/test.sh --run` mcpCustomizationController, sessions agentHostCustomizationService, agentHostChatContribution, workbenchAgentHostCustomizationService, chatMcpAuthenticationContentPart, chatToolAuthenticationSubPart | 781 passing | | `./scripts/test.sh --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostClientTools.test.ts` | 73 passing | | `npm run eslint -- <changed files>` | passed | | `npm run typecheck-client` | passed | | `npm run valid-layers-check` | passed | Not run: integration tests (`copilotConnectors.integrationTest.ts` was only updated for the new reconcile result shape) and a manual end-to-end run against the live gateway.

Fixes #340546
Description
When silent MCP authentication forwards a token, keep the Authenticating presentation through the expected server restart so the Sign In action does not flash. If that restart returns the same authentication challenge, treat the token as rejected, stop retrying it, and expose the host's Authentication required state.
Authentication attempts are reconciled from host customization notifications, including while another session is being viewed. The challenge identity includes the protected resource name because it affects MCP scope selection.
This prevents Copilot connectors with an insufficient-scope token from spinning indefinitely and repeatedly forwarding the unchanged credential.
Testing
npm run build-fast -- --client-only— passed./scripts/test.sh --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostCustomizationService.test.ts— passed, 29 testsnpm run eslint -- src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostCustomizationService.ts src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostCustomizationService.test.ts— passednpm run typecheck-client— passed