|
1 | 1 | import { BearerAuthMiddlewareOptions, requireBearerAuth } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js"; |
2 | | -import { AuthRouterOptions, getOAuthProtectedResourceMetadataUrl, mcpAuthRouter, mcpAuthMetadataRouter } from "@modelcontextprotocol/sdk/server/auth/router.js"; |
| 2 | +import { AuthRouterOptions, getOAuthProtectedResourceMetadataUrl, mcpAuthRouter } from "@modelcontextprotocol/sdk/server/auth/router.js"; |
3 | 3 | import cors from "cors"; |
4 | 4 | import rateLimit from "express-rate-limit"; |
5 | 5 | import express from "express"; |
@@ -227,18 +227,28 @@ if (AUTH_MODE === 'integrated') { |
227 | 227 | } |
228 | 228 | } |
229 | 229 |
|
230 | | - // In separate mode, we don't serve OAuth metadata endpoints |
231 | | - // The auth server handles all OAuth metadata |
232 | | - // We only need to configure the bearer auth middleware |
233 | | - |
| 230 | + // In separate mode, we serve minimal OAuth metadata that points to the auth server |
| 231 | + // This allows OAuth clients to discover the authorization endpoints |
| 232 | + |
| 233 | + // Serve OAuth protected resource metadata endpoint |
| 234 | + app.get('/.well-known/oauth-protected-resource', (req, res) => { |
| 235 | + res.json({ |
| 236 | + resource: BASE_URI, |
| 237 | + authorization_server: AUTH_SERVER_URL, |
| 238 | + bearer_methods_supported: ['header'], |
| 239 | + resource_documentation: `${BASE_URI}/docs`, |
| 240 | + resource_signing_alg_values_supported: ['HS256'] |
| 241 | + }); |
| 242 | + }); |
| 243 | + |
234 | 244 | // Configure bearer auth with external verifier |
235 | 245 | const externalVerifier = new ExternalAuthVerifier(AUTH_SERVER_URL); |
236 | | - |
| 246 | + |
237 | 247 | const bearerAuthOptions: BearerAuthMiddlewareOptions = { |
238 | 248 | verifier: externalVerifier, |
239 | 249 | resourceMetadataUrl: getOAuthProtectedResourceMetadataUrl(new URL(BASE_URI)), |
240 | 250 | }; |
241 | | - |
| 251 | + |
242 | 252 | bearerAuth = requireBearerAuth(bearerAuthOptions); |
243 | 253 | } |
244 | 254 |
|
|
0 commit comments