Repository navigation
agentHost: route Copilot Connector Sign In through Connector authorization - #342479
Merged
Vritant Bhardwaj (vritant24) merged 2 commits intoOct 19, 2026
Merged
Vritant Bhardwaj (vritant24) merged 2 commits into
Vritant Bhardwaj (vritant24) merged 2 commits into
Conversation
…ation Connector-owned MCP servers authenticate only with the SDK session's GitHub credential, so a token forwarded in answer to mcp.oauth_required was ignored and Sign In looped on insufficient_scope while logging success. Sign In now authorizes Copilot Connectors for the session account, forwards the Copilot credential, and force-reconciles the Connector; connector requests are never satisfied by an MCP token, stale requests are released after reconciliation, and success is reported only once the server leaves the authentication-required state. Also reads ConnectorStatus.authorizationRequirement. Fixes #341123 Co-authored-by: Copilot <[email protected]>
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Credential selection can switch accounts, and refresh cancellation or delays can leave authentication stuck.
3 open issues
What changed in this PR
Routes Agent Host connector Sign In through Copilot Connector authorization rather than generic MCP token delivery.
Changes:
- Publishes connector ownership and authorization requirements.
- Forwards Copilot credentials and refreshes connector servers.
- Adds authentication verification and regression coverage.
| File | Description |
|---|---|
src/vs/workbench/contrib/chat/test/browser/aiCustomization/copilotConnectorsService.test.ts |
Tests narrow-session authorization. |
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostCustomizationService.test.ts |
Tests connector Sign In and verification. |
src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostAuth.test.ts |
Tests credential selection and token suppression. |
src/vs/workbench/contrib/chat/browser/aiCustomization/copilotConnectorsService.ts |
Requires full scopes and exposes refresh. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts |
Skips connector auto-authentication. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostCustomizationService.ts |
Routes authorization and verifies outcomes. |
src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostAuth.ts |
Forwards Copilot credentials instead of connector MCP tokens. |
src/vs/sessions/common/agentHostSessionsProvider.ts |
Exposes connector ownership. |
src/vs/platform/agentHost/test/node/providerIntegration/copilotConnectors.integrationTest.ts |
Adapts reconciliation assertions. |
src/vs/platform/agentHost/test/node/copilotSessionLauncher.test.ts |
Updates connector metadata fixtures. |
src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts |
Tests connector authentication lifecycle. |
src/vs/platform/agentHost/node/shared/mcpCustomizationController.ts |
Publishes connector metadata. |
src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts |
Passes connector reconciliation metadata. |
src/vs/platform/agentHost/node/copilot/copilotConnectors.ts |
Returns ownership and authorization status. |
src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts |
Handles connector challenges and forced refreshes. |
src/vs/platform/agentHost/common/meta/vscode/mcpCustomizationMeta.ts |
Defines connector metadata readers and writers. |
src/vs/platform/agentHost/common/meta/mcpCustomizationMeta.ts |
Exports connector metadata helpers. |
Review effort: Balanced
Forward the Copilot credential of the account that authorized Connectors without falling back to another account, restore the authentication challenge when a forced Connector refresh is cancelled before reconciliation, and release Sign In on its deadline or disposal while the refresh is still pending. Co-authored-by: Copilot <[email protected]>
Vritant Bhardwaj (vritant24)
marked this pull request as ready for review
October 19, 2026 18:42
Bhavya U (bhavyaus)
approved these changes
Oct 19, 2026
Vritant Bhardwaj (vritant24)
deleted the
agents/fix-vscode-copilot-connector-authentication
branch
October 19, 2026 20:37
Elijah King (eli-w-king)
added a commit
that referenced
this pull request
Oct 19, 2026
Authentication forwarding reads the default account since #342104, which merged right after the Connector authorization tests in #342479, so those tests fail on main. Same change as #342706. Co-authored-by: Copilot <[email protected]>
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.


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 returned403 insufficient_scope, the runtime fell back to a genericmcp.oauth_required(reason=upscope). VS Code's Sign In, and silent auto-auth, then created a GitHub session with onlywrite:plugin_gateway_connectionsand 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
authenticateMcpServerdetects connector-owned servers. Detection uses new host-publishedvscode.mcpServerConnectorNamemetadata, or awrite:plugin_gateway_connectionschallenge as a fallback.ICopilotConnectorsService.authorize(), forwards the Copilot credential (which prefers the full-scope session), then force-reconciles that connector through a new narrowrefreshAgentHostSessions(connectorName)API.resolveMcpServerAuthenticationrefuses 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.resolveMcpAuthenticationskips connector-owned pending requests.Truthful reporting
authenticateMcpServerreports 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.falseand shows a localized message. It asks the user to authorize Copilot connectors with the same GitHub account they use for Copilot.false. Previously it returnedtrueright after forwarding.ConnectorStatus.authorizationRequirementauthorizationRequirement.needs-authwith nomcp.oauth_requiredis shown as AuthRequired (insufficient scope). This covers the planned runtime fix that will stop emittingmcp.oauth_requiredfor connector 403s.Notes for reviewers
_applyGitHubTokenskipssetCredentials. 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.replace_managed_serversalready cancels its pending OAuth before restarting the server, so cancelling VS Code's stale entry afterwards is safe.updateGitHubCredentialsis only called for static-token sessions, so nothing throws. The challenge comes back and Sign In returnsfalsewith the message.How to test
write:plugin_gateway_connections. Optionally add a narrow session that has only that scope.write:plugin_gateway_connectionson the same account. Then the connector restarts, reaches Ready, and lists its tools. The gateway'sx-oauth-scopesshould include the connector scope.Validation run locally:
./scripts/test.sh --runagentHostAuth, copilotConnectorsService, agentHostCustomizationService, copilotAgentSession, copilotSessionLauncher, agentMetaReaders./scripts/test.sh --runmcpCustomizationController, sessions agentHostCustomizationService, agentHostChatContribution, workbenchAgentHostCustomizationService, chatMcpAuthenticationContentPart, chatToolAuthenticationSubPart./scripts/test.sh --run src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostClientTools.test.tsnpm run eslint -- <changed files>npm run typecheck-clientnpm run valid-layers-checkNot run: integration tests (
copilotConnectors.integrationTest.tswas only updated for the new reconcile result shape) and a manual end-to-end run against the live gateway.