Skip to content

ProxyOAuthServerProvider fails with Zod validation error when using Ory Hydra as OAuth provider #754

Open

Description

@boogie-amplitude

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:

  1. Configure ProxyOAuthServerProvider with Hydra endpoints (e.g., registrationUrl pointing to Hydra's /oauth2/register)
  2. Attempt client registration through the MCP server
  3. 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.

Logs

Unexpected error registering client: ZodError: [
    {
      "code": "invalid_type",
      "expected": "array",
      "received": "null",
      "path": [
        "contacts"
      ],
      "message": "Expected array, received null"
    }
  ]
  at Object.registerClient 
  (/node_modules/@modelcontextprotocol/sdk/src/server/auth/providers/proxyProvider.ts:113:51)

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.

Activity

  1. self-assigned this
    on Jul 16, 2025
  2. jeffdyke commented on Nov 12, 2025

    @jeffdyke

    Still an issue

  3. added
    ready for workEnough information for someone to start working on
    P2Moderate issues affecting some users, edge cases, potentially valuable feature
    authIssues and PRs related to Authentication / OAuth
    on Dec 16, 2025
  4. punkpeye commented on Jan 29, 2026

    @punkpeye

    Still an issue.

    Hacky workaround is to use something like this:

    /**
     * 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.
     */
    export const createNullStrippingFetch = (): typeof fetch => {
      return async (input, init) => {
        const response = await fetch(input, init);
    
        if (!response.ok) {
          return response;
        }
    
        const contentType = response.headers.get('content-type');
    
        if (!contentType?.includes('application/json')) {
          return response;
        }
    
        const body = await response.json();
    
        const sanitized = Object.fromEntries(
          Object.entries(body as Record<string, unknown>).filter(
            ([, value]) => value !== null,
          ),
        );
    
        return new Response(JSON.stringify(sanitized), {
          headers: response.headers,
          status: response.status,
          statusText: response.statusText,
        });
      };
    };
  5. sstklen commented on Feb 22, 2026

    @sstklen

    @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. 👍

  6. ghost added
    fix proposedBot has a verified fix diff in the comment
    on Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P2Moderate issues affecting some users, edge cases, potentially valuable featureauthIssues and PRs related to Authentication / OAuthbugSomething isn't workingfix proposedBot has a verified fix diff in the commentready for workEnough information for someone to start working on

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions