@@ -17,6 +17,13 @@ export type AuthRouterOptions = {
17
17
*/
18
18
issuerUrl : URL ;
19
19
20
+ /**
21
+ * The base URL of the authorization server to use for the metadata endpoints.
22
+ *
23
+ * If not provided, the issuer URL will be used as the base URL.
24
+ */
25
+ baseUrl ?: URL ;
26
+
20
27
/**
21
28
* An optional URL of a page containing human-readable information that developers might want or need to know when using the authorization server.
22
29
*/
@@ -41,6 +48,7 @@ export type AuthRouterOptions = {
41
48
*/
42
49
export function mcpAuthRouter ( options : AuthRouterOptions ) : RequestHandler {
43
50
const issuer = options . issuerUrl ;
51
+ const baseUrl = options . baseUrl ;
44
52
45
53
// Technically RFC 8414 does not permit a localhost HTTPS exemption, but this will be necessary for ease of testing
46
54
if ( issuer . protocol !== "https:" && issuer . hostname !== "localhost" && issuer . hostname !== "127.0.0.1" ) {
@@ -62,18 +70,18 @@ export function mcpAuthRouter(options: AuthRouterOptions): RequestHandler {
62
70
issuer : issuer . href ,
63
71
service_documentation : options . serviceDocumentationUrl ?. href ,
64
72
65
- authorization_endpoint : new URL ( authorization_endpoint , issuer ) . href ,
73
+ authorization_endpoint : new URL ( authorization_endpoint , baseUrl || issuer ) . href ,
66
74
response_types_supported : [ "code" ] ,
67
75
code_challenge_methods_supported : [ "S256" ] ,
68
76
69
- token_endpoint : new URL ( token_endpoint , issuer ) . href ,
77
+ token_endpoint : new URL ( token_endpoint , baseUrl || issuer ) . href ,
70
78
token_endpoint_auth_methods_supported : [ "client_secret_post" ] ,
71
79
grant_types_supported : [ "authorization_code" , "refresh_token" ] ,
72
80
73
- revocation_endpoint : revocation_endpoint ? new URL ( revocation_endpoint , issuer ) . href : undefined ,
81
+ revocation_endpoint : revocation_endpoint ? new URL ( revocation_endpoint , baseUrl || issuer ) . href : undefined ,
74
82
revocation_endpoint_auth_methods_supported : revocation_endpoint ? [ "client_secret_post" ] : undefined ,
75
83
76
- registration_endpoint : registration_endpoint ? new URL ( registration_endpoint , issuer ) . href : undefined ,
84
+ registration_endpoint : registration_endpoint ? new URL ( registration_endpoint , baseUrl || issuer ) . href : undefined ,
77
85
} ;
78
86
79
87
const router = express . Router ( ) ;
0 commit comments