|
1 | 1 | /** |
2 | 2 | * Example Apps Module - Mounts ext-apps example servers at /:slug/mcp |
3 | 3 | * |
4 | | - * Each example MCP App server is mounted at its own path, sharing the same |
5 | | - * OAuth authentication as the main MCP server. |
| 4 | + * Each example MCP App server is mounted at its own path without authentication. |
| 5 | + * The root /mcp endpoint requires OAuth bearer token authentication, but these |
| 6 | + * additional example servers are publicly accessible. |
6 | 7 | * |
7 | 8 | * These servers run in STATELESS mode - each request creates a fresh server |
8 | 9 | * instance without maintaining session state across requests. |
9 | 10 | */ |
10 | 11 |
|
11 | 12 | import { Router, Request, Response, NextFunction } from 'express'; |
12 | 13 | import cors from 'cors'; |
13 | | -import { BearerAuthMiddlewareOptions, requireBearerAuth } from '@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js'; |
14 | | -import { getOAuthProtectedResourceMetadataUrl } from '@modelcontextprotocol/sdk/server/auth/router.js'; |
15 | 14 | import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js'; |
16 | 15 | import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; |
17 | | -import { ITokenValidator } from '../../interfaces/auth-validator.js'; |
18 | 16 | import { AuthInfo } from '@modelcontextprotocol/sdk/server/auth/types.js'; |
19 | 17 | import { isInitializeRequest } from '@modelcontextprotocol/sdk/types.js'; |
20 | 18 |
|
@@ -66,7 +64,6 @@ export class ExampleAppsModule { |
66 | 64 |
|
67 | 65 | constructor( |
68 | 66 | private config: ExampleAppsConfig, |
69 | | - private tokenValidator: ITokenValidator |
70 | 67 | ) { |
71 | 68 | this.router = this.setupRouter(); |
72 | 69 | } |
@@ -94,13 +91,6 @@ export class ExampleAppsModule { |
94 | 91 | next(); |
95 | 92 | }; |
96 | 93 |
|
97 | | - // Bearer auth middleware |
98 | | - const bearerAuthOptions: BearerAuthMiddlewareOptions = { |
99 | | - verifier: this.tokenValidator, |
100 | | - resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(new URL(this.config.baseUri)) |
101 | | - }; |
102 | | - const bearerAuth = requireBearerAuth(bearerAuthOptions); |
103 | | - |
104 | 94 | // Handler for /:slug/mcp - stateless: each request creates a fresh server |
105 | 95 | const handleExampleMcp = async (req: Request, res: Response) => { |
106 | 96 | const { slug } = req.params; |
@@ -155,10 +145,10 @@ export class ExampleAppsModule { |
155 | 145 | } |
156 | 146 | }; |
157 | 147 |
|
158 | | - // Mount routes for each example server |
159 | | - router.get('/:slug/mcp', cors(corsOptions), bearerAuth, securityHeaders, handleExampleMcp); |
160 | | - router.post('/:slug/mcp', cors(corsOptions), bearerAuth, securityHeaders, handleExampleMcp); |
161 | | - router.delete('/:slug/mcp', cors(corsOptions), bearerAuth, securityHeaders, handleExampleMcp); |
| 148 | + // Mount routes for each example server (unauthenticated) |
| 149 | + router.get('/:slug/mcp', cors(corsOptions), securityHeaders, handleExampleMcp); |
| 150 | + router.post('/:slug/mcp', cors(corsOptions), securityHeaders, handleExampleMcp); |
| 151 | + router.delete('/:slug/mcp', cors(corsOptions), securityHeaders, handleExampleMcp); |
162 | 152 |
|
163 | 153 | return router; |
164 | 154 | } |
|
0 commit comments