Skip to content

Agent-host MCP authentication + accurate/persisted MCP auth state#323968

Merged
connor4312 merged 6 commits into
mainfrom
connor/ah-mcp-auth
Jul 2, 2026
Merged

Agent-host MCP authentication + accurate/persisted MCP auth state#323968
connor4312 merged 6 commits into
mainfrom
connor/ah-mcp-auth

Conversation

@connor4312

Copy link
Copy Markdown
Member

Agent-host MCP authentication, plus fixes so MCP server auth state is accurate and remembered.

MCP authentication through the agent host

  • Surface AuthRequired MCP 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

  • Key remembered MCP auth (allowed-server access, account preference, usage) on a stable id — session host authority + server name + resource URL — instead of the customization id, which embeds a per-session/per-sync nonce and was orphaning the grant on every reload.

"Manage Trusted MCP Servers" shows agent-host servers

  • Record agent-host metadata (host authority + label) on allowed MCP servers.
  • Agent-host servers (which aren't registered with the workbench 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"

  • A connected MCP server was flipping back to Starting when navigating away and back, or on any customization change, because a full customization re-publish reset each server's live state.
  • No-op customization re-syncs are now skipped, and the plugin controller overlays live MCP runtime state (from an observable owned by McpCustomizationController) onto every published customization.

Reactive auth-required prompt

  • The prompt's servers is now an observable, so servers whose auth requirement surfaces after the prompt appears join the existing prompt instead of being dropped.
  • The prompt marks itself used once hidden, so a later auth requirement re-prompts rather than silently reusing a stale part.
  • Shows an "Authenticating <server>…" progress state while each server authenticates.

Tests

  • Unit tests for the stable-id helper, agent-host metadata persistence, runtimeStates snapshotting, and query-service exposure.

connor4312 and others added 5 commits June 30, 2026 15:11
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
Copilot AI review requested due to automatic review settings July 1, 2026 23:54
@connor4312
connor4312 enabled auto-merge (squash) July 1, 2026 23:54
@vs-code-engineering

Copy link
Copy Markdown
Contributor

📬 CODENOTIFY

The following users are being notified based on files changed in this PR:

@TylerLeonhardt

Matched files:

  • src/vs/workbench/contrib/authentication/browser/actions/manageTrustedMcpServersForAccountAction.ts
  • src/vs/workbench/services/authentication/browser/authenticationMcpAccessService.ts
  • src/vs/workbench/services/authentication/browser/authenticationQueryService.ts
  • src/vs/workbench/services/authentication/common/authenticationQuery.ts
  • src/vs/workbench/services/authentication/test/browser/authenticationMcpAccessService.test.ts
  • src/vs/workbench/services/authentication/test/browser/authenticationQueryService.test.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@connor4312
connor4312 merged commit 17c6cd4 into main Jul 2, 2026
29 checks passed
@connor4312
connor4312 deleted the connor/ah-mcp-auth branch July 2, 2026 00:26
@vs-code-engineering vs-code-engineering Bot added this to the 1.128.0 milestone Jul 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants