@@ -7,6 +7,9 @@ import { type FastifyInstance } from 'fastify';
77 */
88export default async function oauthDiscoveryRoutes ( server : FastifyInstance ) {
99 const backendUrl = process . env . DEPLOYSTACK_BACKEND_URL || 'http://localhost:3000' ;
10+ // Public URL for OAuth metadata - what MCP clients will use to reach the backend
11+ // Falls back to backendUrl for simple deployments where internal = external URL
12+ const backendPublicUrl = process . env . DEPLOYSTACK_BACKEND_PUBLIC_URL || backendUrl ;
1013 const satelliteUrl = process . env . DEPLOYSTACK_SATELLITE_URL || `http://localhost:${ process . env . PORT || 3001 } ` ;
1114
1215 // RFC 9728: OAuth 2.0 Protected Resource Metadata
@@ -31,7 +34,7 @@ export default async function oauthDiscoveryRoutes(server: FastifyInstance) {
3134 } , async ( request , reply ) => {
3235 const metadata = {
3336 resource : satelliteUrl ,
34- authorization_servers : [ backendUrl ]
37+ authorization_servers : [ backendPublicUrl ]
3538 } ;
3639
3740 server . log . debug ( {
@@ -81,15 +84,15 @@ export default async function oauthDiscoveryRoutes(server: FastifyInstance) {
8184 }
8285 } , async ( request , reply ) => {
8386 const metadata = {
84- issuer : backendUrl ,
85- authorization_endpoint : `${ backendUrl } /api/oauth2/auth` ,
86- token_endpoint : `${ backendUrl } /api/oauth2/token` ,
87- introspection_endpoint : `${ backendUrl } /api/oauth2/introspect` ,
87+ issuer : backendPublicUrl ,
88+ authorization_endpoint : `${ backendPublicUrl } /api/oauth2/auth` ,
89+ token_endpoint : `${ backendPublicUrl } /api/oauth2/token` ,
90+ introspection_endpoint : `${ backendPublicUrl } /api/oauth2/introspect` ,
8891 response_types_supported : [ 'code' ] ,
8992 grant_types_supported : [ 'authorization_code' ] ,
9093 code_challenge_methods_supported : [ 'S256' ] ,
9194 scopes_supported : [ 'mcp:read' , 'mcp:tools:execute' , 'offline_access' ] ,
92- registration_endpoint : `${ backendUrl } /api/oauth2/register`
95+ registration_endpoint : `${ backendPublicUrl } /api/oauth2/register`
9396 } ;
9497
9598 server . log . debug ( {
@@ -145,15 +148,15 @@ export default async function oauthDiscoveryRoutes(server: FastifyInstance) {
145148 } , async ( request , reply ) => {
146149 // Return the same metadata as OAuth authorization server for compatibility
147150 const metadata = {
148- issuer : backendUrl ,
149- authorization_endpoint : `${ backendUrl } /api/oauth2/auth` ,
150- token_endpoint : `${ backendUrl } /api/oauth2/token` ,
151- introspection_endpoint : `${ backendUrl } /api/oauth2/introspect` ,
151+ issuer : backendPublicUrl ,
152+ authorization_endpoint : `${ backendPublicUrl } /api/oauth2/auth` ,
153+ token_endpoint : `${ backendPublicUrl } /api/oauth2/token` ,
154+ introspection_endpoint : `${ backendPublicUrl } /api/oauth2/introspect` ,
152155 response_types_supported : [ 'code' ] ,
153156 grant_types_supported : [ 'authorization_code' ] ,
154157 code_challenge_methods_supported : [ 'S256' ] ,
155158 scopes_supported : [ 'mcp:read' , 'mcp:tools:execute' , 'offline_access' ] ,
156- registration_endpoint : `${ backendUrl } /api/oauth2/register`
159+ registration_endpoint : `${ backendPublicUrl } /api/oauth2/register`
157160 } ;
158161
159162 server . log . debug ( {
0 commit comments