Skip to content

Commit ab19990

Browse files
refactor(examples/bearer-auth): drop unused mcpAuthMetadataRouter + oauthMetadata (#2373)
1 parent abe0590 commit ab19990

2 files changed

Lines changed: 9 additions & 34 deletions

File tree

examples/bearer-auth/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# bearer-auth
22

3-
Resource-server-only auth: `requireBearerAuth` + `mcpAuthMetadataRouter` from `@modelcontextprotocol/express` in front of `createMcpHandler`. The client asserts `401` + `WWW-Authenticate` without a token, and that the verified `authInfo` reaches the factory (`ctx.authInfo`) with
3+
Resource-server-only auth: `requireBearerAuth` from `@modelcontextprotocol/express` in front of `createMcpHandler`. The client asserts `401` + `WWW-Authenticate` without a token, and that the verified `authInfo` reaches the factory (`ctx.authInfo`) with
44
one.
55

66
**HTTP-only** by definition. The full interactive OAuth set lives under `../oauth/` (run headlessly in CI via the demo AS's auto-consent mode).

examples/bearer-auth/server.ts

Lines changed: 8 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,16 @@
11
/**
2-
* Minimal Resource-Server-only auth using the SDK's RS helpers
3-
* (`mcpAuthMetadataRouter`, `requireBearerAuth`, `OAuthTokenVerifier`).
2+
* Minimal Resource-Server-only auth: `requireBearerAuth` + `OAuthTokenVerifier`
3+
* in front of `createMcpHandler`. The verifier accepts a single static
4+
* `demo-token`; the verified `authInfo` reaches the factory as `ctx.authInfo`.
45
*
5-
* No Authorization Server in this repo — the metadata points at a placeholder
6-
* issuer; the token verifier accepts a single static `demo-token`. The MCP
7-
* endpoint is hosted on `createMcpHandler` with the verified `authInfo` passed
8-
* through to the factory (`ctx.authInfo`). HTTP-only by definition.
6+
* No Authorization Server here, and no metadata endpoints — see `examples/oauth/`
7+
* for the full RS + AS discovery flow. HTTP-only by definition.
98
*/
109
import { parseExampleArgs } from '@mcp-examples/shared';
1110
import type { OAuthTokenVerifier } from '@modelcontextprotocol/express';
12-
import {
13-
createMcpExpressApp,
14-
getOAuthProtectedResourceMetadataUrl,
15-
mcpAuthMetadataRouter,
16-
requireBearerAuth
17-
} from '@modelcontextprotocol/express';
11+
import { createMcpExpressApp, requireBearerAuth } from '@modelcontextprotocol/express';
1812
import { toNodeHandler } from '@modelcontextprotocol/node';
19-
import type { AuthInfo, McpServerFactory, OAuthMetadata } from '@modelcontextprotocol/server';
13+
import type { AuthInfo, McpServerFactory } from '@modelcontextprotocol/server';
2014
import { createMcpHandler, McpServer, OAuthError, OAuthErrorCode } from '@modelcontextprotocol/server';
2115
import * as z from 'zod/v4';
2216

@@ -29,14 +23,6 @@ const buildServer: McpServerFactory = ctx => {
2923
};
3024

3125
const { port } = parseExampleArgs();
32-
const mcpServerUrl = new URL(`http://localhost:${port}/mcp`);
33-
34-
const oauthMetadata: OAuthMetadata = {
35-
issuer: 'https://auth.example.com',
36-
authorization_endpoint: 'https://auth.example.com/authorize',
37-
token_endpoint: 'https://auth.example.com/token',
38-
response_types_supported: ['code']
39-
};
4026

4127
// Replace with JWT verification, RFC 7662 introspection, etc.
4228
const staticTokenVerifier: OAuthTokenVerifier = {
@@ -54,18 +40,7 @@ const staticTokenVerifier: OAuthTokenVerifier = {
5440
const handler = createMcpHandler(buildServer);
5541

5642
const app = createMcpExpressApp();
57-
app.use(
58-
mcpAuthMetadataRouter({
59-
oauthMetadata,
60-
resourceServerUrl: mcpServerUrl,
61-
resourceName: 'bearer-auth example'
62-
})
63-
);
64-
const auth = requireBearerAuth({
65-
verifier: staticTokenVerifier,
66-
requiredScopes: ['mcp'],
67-
resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(mcpServerUrl)
68-
});
43+
const auth = requireBearerAuth({ verifier: staticTokenVerifier, requiredScopes: ['mcp'] });
6944
// `requireBearerAuth` sets `req.auth`; `toNodeHandler` reads it and passes it
7045
// to the factory as `ctx.authInfo`.
7146
const node = toNodeHandler(handler);

0 commit comments

Comments
 (0)