|
1 | 1 | import { BearerAuthMiddlewareOptions, requireBearerAuth } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js"; |
2 | | -import { AuthRouterOptions, getOAuthProtectedResourceMetadataUrl, mcpAuthRouter } from "@modelcontextprotocol/sdk/server/auth/router.js"; |
| 2 | +import { AuthRouterOptions, getOAuthProtectedResourceMetadataUrl, mcpAuthRouter, mcpAuthMetadataRouter } 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,19 +227,15 @@ if (AUTH_MODE === 'integrated') { |
227 | 227 | } |
228 | 228 | } |
229 | 229 |
|
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 | | - }); |
| 230 | + // BACKWARDS COMPATIBILITY: We serve OAuth metadata from the MCP server even in separate mode |
| 231 | + // This is technically redundant since the auth server handles all OAuth operations, |
| 232 | + // but some clients may expect to find .well-known/oauth-authorization-server on the |
| 233 | + // resource server itself. The metadata points to the external auth server endpoints. |
| 234 | + app.use(mcpAuthMetadataRouter({ |
| 235 | + oauthMetadata: authMetadata, |
| 236 | + resourceServerUrl: new URL(BASE_URI), |
| 237 | + resourceName: "MCP Everything Server" |
| 238 | + })); |
243 | 239 |
|
244 | 240 | // Configure bearer auth with external verifier |
245 | 241 | const externalVerifier = new ExternalAuthVerifier(AUTH_SERVER_URL); |
|
0 commit comments