Add OAuth protected resource metadata endpoint for separate mode
Fixes MCP Inspector connection by providing OAuth discovery endpoint that points to the external auth server at http://localhost:3001
This commit is contained in:
parent
34fe20efc4
commit
e393cb2129
1 changed files with 17 additions and 7 deletions
18
src/index.ts
18
src/index.ts
|
|
@ -1,5 +1,5 @@
|
||||||
import { BearerAuthMiddlewareOptions, requireBearerAuth } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
import { BearerAuthMiddlewareOptions, requireBearerAuth } from "@modelcontextprotocol/sdk/server/auth/middleware/bearerAuth.js";
|
||||||
import { AuthRouterOptions, getOAuthProtectedResourceMetadataUrl, mcpAuthRouter, mcpAuthMetadataRouter } from "@modelcontextprotocol/sdk/server/auth/router.js";
|
import { AuthRouterOptions, getOAuthProtectedResourceMetadataUrl, mcpAuthRouter } from "@modelcontextprotocol/sdk/server/auth/router.js";
|
||||||
import cors from "cors";
|
import cors from "cors";
|
||||||
import rateLimit from "express-rate-limit";
|
import rateLimit from "express-rate-limit";
|
||||||
import express from "express";
|
import express from "express";
|
||||||
|
|
@ -227,9 +227,19 @@ if (AUTH_MODE === 'integrated') {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// In separate mode, we don't serve OAuth metadata endpoints
|
// In separate mode, we serve minimal OAuth metadata that points to the auth server
|
||||||
// The auth server handles all OAuth metadata
|
// This allows OAuth clients to discover the authorization endpoints
|
||||||
// We only need to configure the bearer auth middleware
|
|
||||||
|
// Serve OAuth protected resource metadata endpoint
|
||||||
|
app.get('/.well-known/oauth-protected-resource', (req, res) => {
|
||||||
|
res.json({
|
||||||
|
resource: BASE_URI,
|
||||||
|
authorization_server: AUTH_SERVER_URL,
|
||||||
|
bearer_methods_supported: ['header'],
|
||||||
|
resource_documentation: `${BASE_URI}/docs`,
|
||||||
|
resource_signing_alg_values_supported: ['HS256']
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Configure bearer auth with external verifier
|
// Configure bearer auth with external verifier
|
||||||
const externalVerifier = new ExternalAuthVerifier(AUTH_SERVER_URL);
|
const externalVerifier = new ExternalAuthVerifier(AUTH_SERVER_URL);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue