Skip to main content
When a client reaches your server without a token, it needs to know where the user signs in. mcpAuthMetadataRouter advertises that, so clients can discover your authorization server on their own.

Example

The server publishes where to authorize, so a client hitting a 401 can find the authorization server on its own.
server.ts

Signature

Parameters

options

Check your OAuth provider’s docs for the metadata values it expects.

Returns

An Express Router to pass to server.use. It serves your OAuth 2.0 Protected Resource Metadata at /.well-known/oauth-protected-resource.

requireBearerAuth

Require a token on every request

optionalBearerAuth

Accept a token when present, allow anonymous otherwise

Authenticate Users

Add sign-in to your app end to end