const { requireAuth } = await protectMcpServer({
app, resourceServerUrl: 'https://mcp.example.com',
issuer: 'https://auth.example.com',
verifier: jwtVerifier({ issuer: 'https://auth.example.com', audience: 'https://mcp.example.com' }),
scopesSupported: ['mcp:tools'],
});
app.post('/mcp', requireAuth, mcpHttpHandler);
Turn an Express app into a spec-compliant MCP OAuth 2.1 Resource Server in one call: serve Protected Resource Metadata (RFC 9728), and return a
requireAuthmiddleware that validates bearer tokens with your verifier and emits a discovery-pointingWWW-Authenticateheader on 401. You wirerequireAuthonto your Streamable-HTTP MCP route.