Skip to content

feat: store MCP OAuth client secrets in OS secret storage - #317950

Merged
TylerLeonhardt merged 1 commit into
mainfrom
tyleonha/mcp-oauth-client-secret
May 22, 2026
Merged

TylerLeonhardt merged 1 commit into
mainfrom
tyleonha/mcp-oauth-client-secret

Conversation

@TylerLeonhardt

@TylerLeonhardt TylerLeonhardt commented May 22, 2026 •

Copy link
Copy Markdown
Member

Fixes #257415

Motivation

Some MCP OAuth flows require a client secret alongside the public client_id. Storing that secret in plain-text mcp.json is unacceptable — it gets checked into repos, leaks into screenshares, and sits unencrypted on disk. This PR moves the MCP OAuth client secret out of config into VS Code's OS-backed secret storage service, with a CodeLens UI on top of the existing mcp.json editor experience.

What changed

  • New "Set / Replace Client Secret" CodeLens above the oauth.clientId property in mcp.json. The label flips between Set (no stored secret) and Replace (secret stored) so the user can tell at a glance whether they need to set one. The CodeLens is only emitted when the server entry has a url (OAuth requires HTTP).

  • QuickInput UX for entering / replacing / deleting the secret:

    • When a secret is already stored, the input is pre-seeded with the existing value, with the entire content selected so it can be replaced (or cleared with Backspace) in one keystroke.
    • A 🗑️ trash titlebar button deletes the stored secret in one click.
    • A 👁️ / 🙈 eye toggle reveals / hides the password masking, so users can verify the secret they're about to save.
  • URL-scoped storage key: secrets are stored under mcp.oauth.clientSecret:<mcpServerUrl>:<clientId>. Using the server URL (vs. the human-friendly server name) means two servers with the same name in different configs — e.g. a git server in both workspace and user mcp.json — never collide on each other's secrets.

  • End-to-end plumbing through the auth provider host:

    • mainThreadMcp.$getTokenFromServerMetadata resolves the stored secret before creating the auth provider.
    • The secret is threaded through IAuthenticationService.createDynamicAuthenticationProvider → IAuthenticationProviderHostDelegate.create → $registerDynamicAuthProvider → DynamicAuthProvider constructor, where it's used in the OAuth token exchange.
  • Stale-secret detection: if an MCP auth provider was already registered with a different client secret than the one currently stored (because the user just replaced or deleted it via the CodeLens after a successful auth flow), the provider is unregistered and re-created so the next token exchange uses the freshly resolved secret. Without this, DynamicAuthProvider._clientSecret would stay cached at whatever the provider was first registered with.

Testing

E2E verified locally end-to-end via Code OSS Dev against the xaa.dev sample IDP / MCP server pair:

  1. mcp.json with an oauth.clientId shows the "Set Client Secret" CodeLens.
  2. Clicking it opens the QuickInput; typing the secret and hitting Enter saves it.
  3. CodeLens flips to "Replace Client Secret".
  4. Clicking again pre-seeds and selects the stored value; eye toggle reveals it in plaintext.
  5. Trash button deletes the secret; CodeLens flips back to "Set Client Secret".

Screenshots and logs captured for each step.

Council review

Reviewed by a 3-model council pre-PR; flagged issues are addressed in this PR:

  1. Storage key scoping — Use server URL (stable) instead of server name (collides across config files). ✅ Fixed.
  2. Stale cached secret — DynamicAuthProvider caches _clientSecret at construction. If the secret changes after the provider is already registered, the cached value is used during token exchange. ✅ Now re-registers the provider when stored secret differs from registered secret.
  3. resolvedClientId vs authDetails.clientId mismatch at provider creation. ✅ Fixed.

Co-authored-by: Copilot [email protected]

Copilot AI review requested due to automatic review settings May 22, 2026 07:30

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 moves MCP OAuth client secrets out of mcp.json and into OS-backed secret storage, and threads the resolved secret through dynamic authentication provider creation so OAuth token exchange can use it without persisting secrets in plaintext configuration.

Changes:

  • Add an MCP mcpOAuthClientSecretStorageKey(url, clientId) helper and a new workbench.mcp.setOAuthClientSecret command to set/replace/delete the stored secret via QuickInput.
  • Emit a “Set/Replace Client Secret” CodeLens above oauth.clientId entries in mcp.json, updating when secret storage changes.
  • Extend dynamic auth provider creation plumbing to accept an optional clientSecret and re-register a provider when the stored secret changes (stale-secret detection).
Show a summary per file
File Description
src/vs/workbench/services/authentication/common/authentication.ts Extends dynamic auth host delegate/service API to accept an optional clientSecret.
src/vs/workbench/services/authentication/browser/authenticationService.ts Passes clientSecret through to the host delegate when creating dynamic providers.
src/vs/workbench/contrib/mcp/common/mcpTypes.ts Adds helper to build the secret-storage key for MCP OAuth client secrets.
src/vs/workbench/contrib/mcp/common/mcpConfiguration.ts Updates schema tooltip to instruct using CodeLens for secure secret storage.
src/vs/workbench/contrib/mcp/common/mcpCommandIds.ts Adds command id for setting the OAuth client secret.
src/vs/workbench/contrib/mcp/browser/mcpLanguageFeatures.ts Adds CodeLens that reads secret storage to show Set/Replace state and triggers refresh on secret changes.
src/vs/workbench/contrib/mcp/browser/mcpCommands.ts Implements QuickInput flow (set/replace/reveal/delete) to manage the stored secret.
src/vs/workbench/contrib/mcp/browser/mcp.contribution.ts Registers the new command contribution.
src/vs/workbench/api/browser/mainThreadMcp.ts Resolves the stored secret, passes it through session/provider creation, and forces re-registration when it changes.
src/vs/workbench/api/browser/mainThreadAuthentication.ts Accepts overrideClientSecret and forwards it to $registerDynamicAuthProvider.

Copilot's findings

  • Files reviewed: 10/10 changed files
  • Comments generated: 3

Some MCP OAuth flows require a client secret in addition to the public
client_id. Storing the secret in plain-text mcp.json is unacceptable, so
this change moves the secret out of config and into the workbench secret
storage service.

Changes:

- A new "Set/Replace Client Secret" codelens is shown above the
  oauth.clientId property in mcp.json. The label flips between Set and
  Replace based on whether a secret is already stored. The codelens is
  only shown when the server has a url (OAuth requires HTTP).

- The codelens opens a QuickInput. When a secret is already stored the
  input is pre-seeded with the existing value (select-all so it can be
  replaced or cleared with Backspace), a trash titlebar button deletes
  the stored secret, and an eye/eye-closed toggle reveals/hides the
  password masking.

- Secrets are keyed by the MCP server URL plus the clientId, so two
  servers with the same name in different configs (workspace vs user
  mcp.json) don't collide.

- The stored secret is threaded through createDynamicAuthenticationProvider
  -> IAuthenticationProviderHostDelegate.create -> $registerDynamicAuthProvider
  so that DynamicAuthProvider is constructed with the resolved secret and
  uses it in the token exchange. The lookup happens before provider
  creation in mainThreadMcp.$getTokenFromServerMetadata.

- If an MCP auth provider was already registered with a different
  client secret than the one currently stored (e.g. the user just
  replaced or deleted it via the QuickInput), the provider is
  unregistered and re-created so the next token exchange uses the
  freshly resolved secret.

Co-authored-by: Copilot <[email protected]>
@TylerLeonhardt
TylerLeonhardt force-pushed the tyleonha/mcp-oauth-client-secret branch from 7b3d728 to 261c47c Compare May 22, 2026 15:55
@TylerLeonhardt
TylerLeonhardt marked this pull request as ready for review May 22, 2026 16:02
TylerLeonhardt added a commit that referenced this pull request May 22, 2026
Implements Cross App Access (XAA) authentication for enterprise-managed MCP
servers using OAuth Identity Assertion Authorization Grant (ID-JAG,
draft-ietf-oauth-identity-assertion-authz-grant-03).

3-leg flow:
1. Auth Code + PKCE against configured SSO IdP (mcp.enterpriseManagedAuth.issuer)
2. ID-JAG token exchange at IdP: id_token -> id-jag assertion
3. Resource AS redemption: id-jag -> access token for MCP server

Stacks on top of the MCP OAuth client-secret feature (#317950).

Reference: xaa-plan.md

Co-authored-by: Copilot <[email protected]>
TylerLeonhardt added a commit that referenced this pull request May 22, 2026
Implements Cross App Access (XAA) authentication for enterprise-managed MCP
servers using OAuth Identity Assertion Authorization Grant (ID-JAG,
draft-ietf-oauth-identity-assertion-authz-grant-03).

3-leg flow:
1. Auth Code + PKCE against configured SSO IdP (mcp.enterpriseManagedAuth.issuer)
2. ID-JAG token exchange at IdP: id_token -> id-jag assertion
3. Resource AS redemption: id-jag -> access token for MCP server

Stacks on top of the MCP OAuth client-secret feature (#317950).

Reference: xaa-plan.md

Co-authored-by: Copilot <[email protected]>
@TylerLeonhardt
TylerLeonhardt merged commit bf74570 into main May 22, 2026
25 checks passed
@TylerLeonhardt
TylerLeonhardt deleted the tyleonha/mcp-oauth-client-secret branch May 22, 2026 23:30
@vs-code-engineering vs-code-engineering Bot added this to the 1.122.0 milestone May 22, 2026
@vs-code-engineering vs-code-engineering Bot locked and limited conversation to collaborators Jul 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP Server Configuration - No Option to disable Dynamic Client Registration and use custom(static) client information for Authorization

3 participants