Skip to content

fix: validate clientMetadataUrl at construction time (fail-fast)#1653

Open
rechedev9 wants to merge 2 commits intomodelcontextprotocol:mainfrom
rechedev9:fix/validate-client-metadata-url
Open

fix: validate clientMetadataUrl at construction time (fail-fast)#1653
rechedev9 wants to merge 2 commits intomodelcontextprotocol:mainfrom
rechedev9:fix/validate-client-metadata-url

Conversation

@rechedev9
Copy link

Summary

  • Adds validateClientMetadataUrl() utility that reuses the existing isHttpsUrl() helper to validate clientMetadataUrl early
  • Calls validation at all SDK-controlled entry points: StreamableHTTPClientTransport constructor, SSEClientTransport constructor, auth() function, and withOAuth middleware factory
  • Exports validateClientMetadataUrl() so consumers who implement OAuthClientProvider directly can call it in their own constructors
  • Preserves existing defense-in-depth validation in authInternal() (near-zero cost redundant check)

Motivation

clientMetadataUrl was only validated deep inside authInternal() after network discovery requests had already been made. This meant invalid URL-based client IDs weren't caught until runtime during authentication, producing confusing stack traces far from the configuration source.

This change provides fail-fast behavior: developers discover configuration errors immediately at construction time with clear error messages pointing to where the provider was configured.

Test plan

  • Unit tests for validateClientMetadataUrl() — valid HTTPS URLs, HTTP rejection, root-path rejection, non-URL strings, undefined passthrough, error format
  • Integration tests for each entry point — StreamableHTTPClientTransport, SSEClientTransport, auth(), withOAuth
  • Verified existing defense-in-depth validation in authInternal() is untouched
  • All 278 client tests pass, 440 core tests pass, 37 server tests pass
  • TypeScript typecheck passes with zero errors

Closes #1159

…havior

Move clientMetadataUrl validation to all SDK-controlled entry points
(StreamableHTTP/SSE constructors, auth(), withOAuth factory) so invalid
URLs are caught immediately rather than deep in the auth flow.

Exports validateClientMetadataUrl() for consumers who implement
OAuthClientProvider directly. Existing defense-in-depth validation
in authInternal() is preserved.

Closes modelcontextprotocol#1159
@rechedev9 rechedev9 requested a review from a team as a code owner March 9, 2026 23:21
@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2026

⚠️ No Changeset found

Latest commit: 186e040

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 9, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1653

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1653

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1653

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1653

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1653

commit: 8bc5396

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.

Validate clientMetadataUrl at construction time rather than during auth flow (SEP-991/CIMD)

1 participant