@@ -35,17 +35,8 @@ export class DemoInMemoryAuthProvider implements OAuthServerProvider {
35
35
params : AuthorizationParams ,
36
36
client : OAuthClientInformationFull } > ( ) ;
37
37
private tokens = new Map < string , AuthInfo > ( ) ;
38
- private validateResource ?: ( resource ?: URL ) => boolean ;
39
-
40
- constructor ( { mcpServerUrl} : { mcpServerUrl ?: URL } = { } ) {
41
- if ( mcpServerUrl ) {
42
- const expectedResource = resourceUrlFromServerUrl ( mcpServerUrl ) ;
43
- this . validateResource = ( resource ?: URL ) => {
44
- if ( ! resource ) return false ;
45
- return resource . toString ( ) === expectedResource . toString ( ) ;
46
- } ;
47
- }
48
- }
38
+
39
+ constructor ( private validateResource ?: ( resource ?: URL ) => boolean ) { }
49
40
50
41
async authorize (
51
42
client : OAuthClientInformationFull ,
@@ -153,13 +144,20 @@ export class DemoInMemoryAuthProvider implements OAuthServerProvider {
153
144
}
154
145
155
146
156
- export const setupAuthServer = ( authServerUrl : URL , mcpServerUrl : URL ) : OAuthMetadata => {
147
+ export const setupAuthServer = ( { authServerUrl, mcpServerUrl , strictResource } : { authServerUrl : URL , mcpServerUrl : URL , strictResource : boolean } ) : OAuthMetadata => {
157
148
// Create separate auth server app
158
149
// NOTE: This is a separate app on a separate port to illustrate
159
150
// how to separate an OAuth Authorization Server from a Resource
160
151
// server in the SDK. The SDK is not intended to be provide a standalone
161
152
// authorization server.
162
- const provider = new DemoInMemoryAuthProvider ( { mcpServerUrl} ) ;
153
+
154
+ const validateResource = strictResource ? ( resource ?: URL ) => {
155
+ if ( ! resource ) return false ;
156
+ const expectedResource = resourceUrlFromServerUrl ( mcpServerUrl ) ;
157
+ return resource . toString ( ) === expectedResource . toString ( ) ;
158
+ } : undefined ;
159
+
160
+ const provider = new DemoInMemoryAuthProvider ( validateResource ) ;
163
161
const authApp = express ( ) ;
164
162
authApp . use ( express . json ( ) ) ;
165
163
// For introspection requests
0 commit comments