Skip to content

fix(auth): keep OAuth revocation fields in OIDC discovery metadata - #3214

Open
marcus-beauregard wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
marcus-beauregard:fix/oidc-discovery-keeps-oauth-fields
Open

marcus-beauregard wants to merge 1 commit into
modelcontextprotocol:v1.xfrom
marcus-beauregard:fix/oidc-discovery-keeps-oauth-fields

Conversation

@marcus-beauregard

Copy link
Copy Markdown

What this fixes

OpenIdProviderDiscoveryMetadataSchema was built by spreading OpenIdProviderMetadataSchema.shape into a plain z.object:

export const OpenIdProviderDiscoveryMetadataSchema = z.object({
    ...OpenIdProviderMetadataSchema.shape,
    ...OAuthMetadataSchema.pick({ code_challenge_methods_supported: true }).shape
});

OpenIdProviderMetadataSchema is a z.looseObject, but spreading its .shape into a plain object drops that behaviour — zod then strips every key the new schema does not declare. revocation_endpoint is one of them, so for an authorization server that publishes only OpenID discovery (no RFC 8414 document) the endpoint disappeared during parse:

OpenIdProviderDiscoveryMetadataSchema.parse(doc).revocation_endpoint  // undefined
OAuthMetadataSchema.parse(doc).revocation_endpoint                    // "https://issuer.example.com/oauth2/revoke"

discoverAuthorizationServerMetadata() (src/client/auth.ts:1127) parses the discovery response with this schema and hands the result on as AuthorizationServerMetadata, so a client reading revocation_endpoint from it saw undefined and had no way to know the server supports revocation.

The change

  • src/shared/auth.ts: build the schema with z.looseObject again, and pick revocation_endpoint, revocation_endpoint_auth_methods_supported and revocation_endpoint_auth_signing_alg_values_supported from OAuthMetadataSchema so they arrive typed and keep the SafeUrlSchema guard. Nothing else is declared — other undeclared fields now survive untyped rather than being silently dropped, which is what the "mix of OpenID Connect and OAuth 2.0 metadata fields" comment on the schema already promised.
  • test/shared/auth.test.ts: four tests — the revocation fields survive parse; a field neither schema declares survives; a document missing the required response_types_supported still throws; a javascript: revocation_endpoint is rejected with the same guard message as the other URL fields.
  • .changeset/oidc-discovery-keeps-oauth-fields.md: patch.

With src/shared/auth.ts reverted to v1.x, exactly three of the new tests fail (revocation fields, unknown field, unsafe URL) and the required-field test still passes.

Verification

  • npx vitest run test/shared/auth.test.ts — 17 passed
  • npx vitest run test/shared test/client/auth.test.ts — 461 passed
  • npm run typecheck (tsgo --noEmit) — clean
  • eslint + prettier --check on the touched files — clean

Fixes #3213. Based on v1.x per CONTRIBUTING (v1 bug fix); the same construction exists on main in packages/core/src/auth.ts, and I'm happy to open the mirror there if you'd rather land it on both lines in one go.

`OpenIdProviderDiscoveryMetadataSchema` spread
`OpenIdProviderMetadataSchema.shape` into a plain `z.object`, which dropped
the loose behaviour the source schema had: every field the discovery document
published but the schema did not declare was stripped on parse. A server that
publishes only OpenID discovery therefore lost `revocation_endpoint` before
the client could ever read it, and the client concluded revocation was
unsupported.

Build the schema with `z.looseObject` again, and declare the three RFC 7009
revocation fields so they arrive typed rather than merely present.

Fixes modelcontextprotocol#3213.
@changeset-bot

changeset-bot Bot commented Nov 19, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9f7dba5

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

This branch has not been deployed

No deployments
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.

1 participant