Agent-host MCP authentication + accurate/persisted MCP auth state#323968
Merged
Conversation
The Agents window showed a connected GitHub MCP server flipping back to 'Starting' when navigating away from and back to a session. A client re-subscribe re-published the session's customizations, and the SessionCustomizationsChanged full-replace reset each MCP entry's state to the 'Starting' default baked into makeMcpServerCustomization. - Skip no-op customization re-syncs in SessionPluginController.sync so an identical re-publish (e.g. navigating back) does no work. - SessionPluginController now overlays live MCP runtime state/channel onto every published customization via _projectForPublish, so a genuine single-customization change no longer resets otherwise-unchanged MCP servers. The overlay is driven by an ISettableObservable kept up to date by the session from McpCustomizationController. - McpCustomizationController._live is now an observable and exposes runtimeStates as a derived; mutations are batched in transactions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # package-lock.json # package.json # remote/package-lock.json # remote/package.json # src/vs/platform/agentHost/node/copilot/copilotAgent.ts # src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts # src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts # src/vs/workbench/contrib/chat/common/model/chatModel.ts
- Key remembered MCP auth on a stable id (session authority + server name + resource URL) instead of the unstable customization id, so grants survive reloads and don't require re-auth. - Record agent-host metadata (authority + host label) on allowed MCP servers and surface agent-host servers in their own section of the Manage Trusted MCP Servers picker instead of filtering them out. - Make the auth-required chat prompt reactive: servers is now an observable so servers whose auth requirement surfaces later join the existing prompt, and the part marks itself used once hidden so later requirements re-prompt. - Show an 'Authenticating <server>...' progress state while each server auths. - Drop the never-serialized mcpAuthenticationRequired part from the serialized response-part unions. - Add unit tests for the stable-id helper, agentHost metadata persistence, and query-service exposure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts
Contributor
📬 CODENOTIFYThe following users are being notified based on files changed in this PR: @TylerLeonhardtMatched files:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds end-to-end MCP OAuth authentication support for agent-host MCP servers (including an in-chat auth-required prompt + interactive auth flow), and fixes persisted/auth-related state so MCP server identity, grants, and live runtime state remain accurate across reloads and republish cycles.
Changes:
- Introduces a stable agent-host MCP server identity (
agentHostMcpServerId) and persists agent-host metadata on allowed MCP server grants for correct management UX and grant reuse across reloads. - Adds a new chat content part for reactive “MCP authentication required” prompting and wires it to agent-host authentication APIs (silent auto-grant on reconnect + interactive auth on demand).
- Preserves and overlays live MCP runtime state (
state/channel) across customization republishes to avoid resetting MCP servers back to “Starting”, with expanded test coverage.
Show a summary per file
| File | Description |
|---|---|
| src/vs/workbench/test/browser/componentFixtures/sessions/aiCustomizationManagementEditor.fixture.ts | Updates fixture data to include MCP auth-required state details. |
| src/vs/workbench/services/authentication/test/browser/authenticationQueryService.test.ts | Adds test coverage for exposing agent-host metadata via query service. |
| src/vs/workbench/services/authentication/test/browser/authenticationMcpAccessService.test.ts | Adds tests ensuring agent-host metadata persists across toggles/updates. |
| src/vs/workbench/services/authentication/common/authenticationQuery.ts | Extends query return type to include MCP server url and agentHost metadata. |
| src/vs/workbench/services/authentication/browser/authenticationQueryService.ts | Implements updated query surface for allowed MCP servers. |
| src/vs/workbench/services/authentication/browser/authenticationMcpAccessService.ts | Persists agent-host metadata on stored allowed-server entries without clearing on partial updates. |
| src/vs/workbench/contrib/mcp/browser/mcpCommands.ts | Adds “Authenticate” action for agent-host MCP servers in auth-required state. |
| src/vs/workbench/contrib/chat/test/browser/agentSessions/agentHostAuth.test.ts | Adds tests for stable agent-host MCP server id generation. |
| src/vs/workbench/contrib/chat/common/model/chatViewModel.ts | Adds new renderer content kind for MCP auth-required prompt. |
| src/vs/workbench/contrib/chat/common/model/chatSessionOperationLog.ts | Excludes transient MCP auth-required part from serialized operation log output. |
| src/vs/workbench/contrib/chat/common/model/chatModel.ts | Extends chat progress unions to include MCP auth-required part. |
| src/vs/workbench/contrib/chat/common/chatService/chatService.ts | Introduces IChatMcpAuthenticationRequired + server shape (observable server list). |
| src/vs/workbench/contrib/chat/browser/widget/chatListRenderer.ts | Renders the new MCP auth-required content part. |
| src/vs/workbench/contrib/chat/browser/widget/chatContentParts/chatMcpAuthenticationContentPart.ts | New UI part that prompts for MCP authentication and drives auth flow via agent-host customization service. |
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostSessionHandler.ts | Derives auth-required MCP servers from session state, supports silent auto-grant, and emits reactive prompt part. |
| src/vs/workbench/contrib/chat/browser/agentSessions/agentHost/agentHostCustomizationService.ts | Adds authenticateMcpServer and refactors customization handling around an abstract target-based service. |
| src/vs/sessions/services/agentHost/browser/agentHostCustomizationService.ts | Adopts shared abstract customization service in Agents window context. |
| src/vs/sessions/contrib/providers/remoteAgentHost/test/browser/remoteAgentHostCustomizationHarness.test.ts | Updates test harness for new customization service API surface. |
| src/vs/sessions/contrib/providers/agentHost/browser/baseAgentHostSessionsProvider.ts | Adds authenticate forwarding + scopes MCP server ids by authority and exposes full state. |
| src/vs/sessions/common/agentHostSessionsProvider.ts | Extends provider contract to include authenticate + exposes full MCP server state. |
| src/vs/platform/agentHost/test/node/shared/mcpCustomizationController.test.ts | Adds runtime-state snapshot and auth-required state preservation tests. |
| src/vs/platform/agentHost/test/node/copilotAgentSession.test.ts | Adds tests for publishing auth-required MCP state and resolving auth via authenticate token. |
| src/vs/platform/agentHost/test/node/copilotAgent.test.ts | Adjusts test session creation to align with updated agent internals. |
| src/vs/platform/agentHost/node/shared/mcpCustomizationController.ts | Tracks live MCP runtime state observably and preserves auth-required state across coarse “Starting” updates. |
| src/vs/platform/agentHost/node/copilot/copilotSessionLauncher.ts | Wires SDK MCP auth hook through to runtime. |
| src/vs/platform/agentHost/node/copilot/copilotAgentSession.ts | Implements MCP auth request handling, state publication, and token resolution plumbing. |
| src/vs/platform/agentHost/node/copilot/copilotAgent.ts | Propagates session MCP runtime states to plugin controller and handles MCP auth tokens across sessions. |
| src/vs/platform/agentHost/node/agentHostAuthenticationService.ts | Fans out authentication tokens to both protected-resource handlers and session-scoped handlers. |
| src/vs/platform/agentHost/common/agentService.ts | Adds optional handleAuthenticationToken hook to agent interface. |
| src/vs/workbench/contrib/authentication/browser/actions/manageTrustedMcpServersForAccountAction.ts | Shows agent-host servers in trusted MCP management UI, grouped per agent host. |
Review details
- Files reviewed: 31/31 changed files
- Comments generated: 3
- Review effort level: Low
- Don't emit an empty mcpAuthenticationRequired progress part (was adding a stray part and breaking AgentHostChatContribution tool-progress tests). - Guard the async auth filter with a run id so out-of-order completions can't overwrite a newer server list. - Group agent-host servers in the Manage Trusted MCP Servers picker by stable authority (sorted by label) instead of label, which could collide. - Scope the authenticate link to the #authenticate target and give it button semantics (role=button, cleared href). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
dmitrivMS
approved these changes
Jul 2, 2026
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.
Agent-host MCP authentication, plus fixes so MCP server auth state is accurate and remembered.
MCP authentication through the agent host
AuthRequiredMCP servers from an agent-host session as an in-chat prompt, and drive the OAuth flow (interactive on click, silent auto-grant on reconnect) forwarding the resulting token to the agent host.Remembered auth persists across reloads
"Manage Trusted MCP Servers" shows agent-host servers
IMcpService) are no longer filtered out — they're shown in their own per-host section of the picker.Live MCP server state no longer resets to "Starting"
Startingwhen navigating away and back, or on any customization change, because a full customization re-publish reset each server's live state.McpCustomizationController) onto every published customization.Reactive auth-required prompt
serversis now an observable, so servers whose auth requirement surfaces after the prompt appears join the existing prompt instead of being dropped.<server>…" progress state while each server authenticates.Tests
runtimeStatessnapshotting, and query-service exposure.