Repository navigation
feat: store MCP OAuth client secrets in OS secret storage - #317950
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
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 newworkbench.mcp.setOAuthClientSecretcommand to set/replace/delete the stored secret via QuickInput. - Emit a “Set/Replace Client Secret” CodeLens above
oauth.clientIdentries inmcp.json, updating when secret storage changes. - Extend dynamic auth provider creation plumbing to accept an optional
clientSecretand 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
force-pushed
the
tyleonha/mcp-oauth-client-secret
branch
from
May 22, 2026 15:55
7b3d728 to
261c47c
Compare
TylerLeonhardt
marked this pull request as ready for review
May 22, 2026 16:02
Dirk Bäumer (dbaeumer)
approved these changes
May 22, 2026
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]>
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 subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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 #257415
Motivation
Some MCP OAuth flows require a client secret alongside the public
client_id. Storing that secret in plain-textmcp.jsonis 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 existingmcp.jsoneditor experience.What changed
New "Set / Replace Client Secret" CodeLens above the
oauth.clientIdproperty inmcp.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 aurl(OAuth requires HTTP).QuickInput UX for entering / replacing / deleting the secret:
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. agitserver in both workspace and usermcp.json— never collide on each other's secrets.End-to-end plumbing through the auth provider host:
mainThreadMcp.$getTokenFromServerMetadataresolves the stored secret before creating the auth provider.IAuthenticationService.createDynamicAuthenticationProvider→IAuthenticationProviderHostDelegate.create→$registerDynamicAuthProvider→DynamicAuthProviderconstructor, 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._clientSecretwould 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:
mcp.jsonwith anoauth.clientIdshows the "Set Client Secret" CodeLens.Screenshots and logs captured for each step.
Council review
Reviewed by a 3-model council pre-PR; flagged issues are addressed in this PR:
DynamicAuthProvidercaches_clientSecretat 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.resolvedClientIdvsauthDetails.clientIdmismatch at provider creation. ✅ Fixed.Co-authored-by: Copilot [email protected]