Skip to content

feat(express): restore Resource-Server auth glue (requireBearerAuth, mcpAuthMetadataRouter)#1907

Draft
felixweinberger wants to merge 1 commit intomainfrom
fweinberger/v2-bc-express-rs-glue
Draft

feat(express): restore Resource-Server auth glue (requireBearerAuth, mcpAuthMetadataRouter)#1907
felixweinberger wants to merge 1 commit intomainfrom
fweinberger/v2-bc-express-rs-glue

Conversation

@felixweinberger
Copy link
Copy Markdown
Contributor

Part of the v2 backwards-compatibility series — see reviewer guide.

v2 removed all server-side auth. The Resource-Server half (bearer-token verification, RFC 9728 PRM metadata) is MCP-spec-mandated and v2's own examples reimplement ~688 LOC of it. This restores those pieces in /express first-class (not deprecated). v1's auth was Express-specific.

Motivation and Context

v2 removed all server-side auth. The Resource-Server half (bearer-token verification, RFC 9728 PRM metadata) is MCP-spec-mandated and v2's own examples reimplement ~688 LOC of it. This restores those pieces in /express first-class (not deprecated). v1's auth was Express-specific.

v1 vs v2 pattern & evidence

v1 pattern:

`import { requireBearerAuth } from '@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js'`

v2-native:

`import { requireBearerAuth } from '@modelcontextprotocol/express'`

Evidence: Express peer widened to ^4 || ^5.

How Has This Been Tested?

  • packages/middleware/express/test/auth/resourceServer.test.ts
  • Integration: validated bump-only against 5 OSS repos via the v2-bc-integration validation branch
  • pnpm typecheck:all && pnpm lint:all && pnpm test:all green

Breaking Changes

None — additive @deprecated shim. Removed in v3.

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added or updated documentation as needed

Additional context

Stacks on: none

@felixweinberger felixweinberger added the v2-bc v2 backwards-compatibility series label Apr 15, 2026
@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Apr 15, 2026

🦋 Changeset detected

Latest commit: 15c44b6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@modelcontextprotocol/express Minor

Not sure what this means? Click here to learn what changesets are.

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

@felixweinberger felixweinberger added this to the v2.0.0-bc milestone Apr 15, 2026
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new bot commented Apr 15, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/@modelcontextprotocol/client@1907

@modelcontextprotocol/server

npm i https://pkg.pr.new/@modelcontextprotocol/server@1907

@modelcontextprotocol/express

npm i https://pkg.pr.new/@modelcontextprotocol/express@1907

@modelcontextprotocol/fastify

npm i https://pkg.pr.new/@modelcontextprotocol/fastify@1907

@modelcontextprotocol/hono

npm i https://pkg.pr.new/@modelcontextprotocol/hono@1907

@modelcontextprotocol/node

npm i https://pkg.pr.new/@modelcontextprotocol/node@1907

commit: 15c44b6

@felixweinberger felixweinberger force-pushed the fweinberger/v2-bc-express-rs-glue branch from f9f1d76 to d1e0ddf Compare April 16, 2026 09:37
…col/express

Adds first-class (not deprecated) OAuth Resource-Server helpers to the
Express adapter, restoring the v1 src/server/auth pieces that an MCP
server needs when it delegates to an external Authorization Server:

- requireBearerAuth: Express middleware that validates a Bearer token
  via a pluggable OAuthTokenVerifier, attaches AuthInfo to req.auth,
  and on failure emits RFC 6750 WWW-Authenticate challenges (with
  optional resource_metadata pointer per RFC 9728).
- mcpAuthMetadataRouter: serves RFC 9728 Protected Resource Metadata at
  /.well-known/oauth-protected-resource[/<path>] and mirrors the AS
  metadata at /.well-known/oauth-authorization-server, with permissive
  CORS and a GET/OPTIONS allow-list.
- getOAuthProtectedResourceMetadataUrl: builds the path-aware PRM URL
  for a given server URL.
- OAuthTokenVerifier interface, plus metadataHandler / allowedMethods
  building blocks.

Adapted to v2's single OAuthError + OAuthErrorCode (no per-code
subclasses) and to types re-exported via @modelcontextprotocol/server.
Adds cors as a runtime dependency and supertest as a dev dependency for
the integration tests.
@felixweinberger felixweinberger force-pushed the fweinberger/v2-bc-express-rs-glue branch from d1e0ddf to 15c44b6 Compare April 16, 2026 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

v2-bc v2 backwards-compatibility series

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant