This is the documentation for the v2 beta — looking for the v1 documentation?
Skip to content

MCP TypeScript SDK (V2) / @modelcontextprotocol/express / auth/bearerAuth

auth/bearerAuth

Type Aliases

BearerAuthMiddlewareOptions

BearerAuthMiddlewareOptions = BearerAuthOptions

Defined in: middleware/express/src/auth/bearerAuth.ts:8

Options for requireBearerAuth.

Functions

requireBearerAuth()

requireBearerAuth(options): RequestHandler

Defined in: middleware/express/src/auth/bearerAuth.ts:26

Express middleware that requires a valid Bearer token in the Authorization header.

The Express adapter over the runtime-neutral core in @modelcontextprotocol/server (verifyBearerToken / bearerAuthChallengeResponse — or requireBearerAuth from that package for web-standard fetch(request) hosts). The token is validated via the supplied OAuthTokenVerifier and the resulting AuthInfo is attached to req.auth. The MCP Streamable HTTP transport reads req.auth and surfaces it to handlers as ctx.http.authInfo.

On failure the middleware sends a JSON OAuth error body and a WWW-Authenticate: Bearer … challenge that includes the configured resource_metadata URL so clients can discover the Authorization Server.

Parameters

options

BearerAuthOptions

Returns

RequestHandler