fix: accept null introspection_endpoint in OAuthMetadataSchema#1923
Open
billyriaz wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix: accept null introspection_endpoint in OAuthMetadataSchema#1923billyriaz wants to merge 1 commit intomodelcontextprotocol:mainfrom
billyriaz wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Some OAuth authorization servers (e.g. Dotdigital's MCP server) return introspection_endpoint: null in their .well-known/oauth-authorization-server metadata rather than omitting the field entirely. The current schema uses z.string().optional() which accepts undefined but rejects null, causing OAuth flow initiation to fail with: "Invalid input: expected string, received null" Changing to z.string().nullish() accepts both undefined and null, which aligns with RFC 7662 where introspection_endpoint is optional and a server returning null should be treated the same as not including it.
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/fastify
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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.
Problem
Some OAuth authorization servers return
introspection_endpoint: nullin their/.well-known/oauth-authorization-servermetadata rather than omitting the field entirely. This is valid per RFC 7662 — the field is optional andnullshould be treated the same as absent.The current schema uses
z.string().optional()which acceptsundefinedbut rejectsnull, causing OAuth flow initiation to fail with:Fix
Change
z.string().optional()toz.string().nullish()forintrospection_endpoint. This acceptsstring | null | undefined, correctly handling servers that explicitly set the field tonull.Reproduction
Connect any MCP client to an OAuth server whose
/.well-known/oauth-authorization-serverreturns"introspection_endpoint": null. The OAuth flow fails immediately at metadata validation before the authorization redirect is attempted.Example metadata that triggers the bug:
{ "issuer": "https://example.com", "authorization_endpoint": "https://example.com/oauth/authorize", "token_endpoint": "https://example.com/oauth/token", "introspection_endpoint": null, "registration_endpoint": "https://example.com/oauth/register" }