You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ProxyOAuthServerProvider fails with Zod validation error when using Ory Hydra as OAuth provider #754
Describe the bug
The ProxyOAuthServerProvider's client registration fails with a Zod schema validation error when using Hydra as the upstream OAuth provider. The error occurs because Hydra returns "contacts": null in the client registration response, but the MCP SDK's OAuthClientInformationFullSchema expects contacts to be an array.
To Reproduce
Steps to reproduce the behavior:
Configure ProxyOAuthServerProvider with Hydra endpoints (e.g., registrationUrl pointing to Hydra's /oauth2/register)
Attempt client registration through the MCP server
Registration request succeeds at Hydra but fails during MCP SDK's response parsing
Expected behavior
Client registration should succeed when using standards-compliant OAuth2 providers like Hydra that return valid OAuth client information responses.
Additional context
Hydra returns valid RFC 7591 compliant client registration responses where optional fields like contacts can be null. The MCP SDK's Zod schema appears to be stricter than the OAuth2 specification requires for these optional fields.
/** * Creates a fetch wrapper that strips `null` values from JSON responses. * * Some OAuth servers return `null` for optional fields (e.g. client_uri, * logo_uri, client_secret) instead of omitting them. The MCP SDK's Zod * schemas use `.optional()` which accepts `undefined` but not `null`, * causing validation to fail. This wrapper intercepts successful JSON * responses and removes null-valued keys before the SDK parses them. */exportconstcreateNullStrippingFetch=(): typeoffetch=>{returnasync(input,init)=>{constresponse=awaitfetch(input,init);if(!response.ok){returnresponse;}constcontentType=response.headers.get('content-type');if(!contentType?.includes('application/json')){returnresponse;}constbody=awaitresponse.json();constsanitized=Object.fromEntries(Object.entries(bodyasRecord<string,unknown>).filter(([,value])=>value!==null,),);returnnewResponse(JSON.stringify(sanitized),{headers: response.headers,status: response.status,statusText: response.statusText,});};};
@punkpeye's null-stripping fetch wrapper works — confirmed on my end with Ory Hydra. The core issue is that Hydra returns "contacts": null instead of omitting the field, and OAuthClientInformationFullSchema uses .optional() which accepts undefined but rejects null. The wrapper that converts null values to undefined before Zod validation is a solid workaround until the SDK handles this natively. 👍
Activity
jeffdyke commentedon Nov 12, 2025
Still an issue
punkpeye commentedon Jan 29, 2026
Still an issue.
Hacky workaround is to use something like this:
sstklen commentedon Feb 22, 2026
@punkpeye's null-stripping fetch wrapper works — confirmed on my end with Ory Hydra. The core issue is that Hydra returns
"contacts": nullinstead of omitting the field, andOAuthClientInformationFullSchemauses.optional()which acceptsundefinedbut rejectsnull. The wrapper that convertsnullvalues toundefinedbefore Zod validation is a solid workaround until the SDK handles this natively. 👍fix: add Envoy DCR sanitizer for Hydra MCP SDK compatibility
fix(auth): normalize null token-response members at parse sites, not …