|
7 | 7 | exchangeAuthorization, |
8 | 8 | discoverOAuthProtectedResourceMetadata, |
9 | 9 | } from "@modelcontextprotocol/sdk/client/auth.js"; |
10 | | -import { |
11 | | - resourceUrlFromServerUrl |
12 | | -} from "@modelcontextprotocol/sdk/shared/auth-utils.js"; |
| 10 | +import { resourceUrlFromServerUrl } from "@modelcontextprotocol/sdk/shared/auth-utils.js"; |
13 | 11 | import { |
14 | 12 | OAuthMetadataSchema, |
15 | 13 | OAuthProtectedResourceMetadata, |
@@ -51,11 +49,11 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = { |
51 | 49 | } |
52 | 50 | } |
53 | 51 |
|
54 | | - let resource: string| undefined; |
| 52 | + let resource: URL | undefined; |
55 | 53 | if (resourceMetadata) { |
56 | | - resource = resourceUrlFromServerUrl(context.serverUrl); |
57 | 54 | // TODO: use SDK function selectResourceURL once version bump lands to be consistent |
58 | | - if (resource !== resourceMetadata.resource) |
| 55 | + resource = resourceUrlFromServerUrl(new URL(context.serverUrl)); |
| 56 | + if (resource.href !== resourceMetadata.resource) { |
59 | 57 | resourceMetadataError = new Error( |
60 | 58 | `Warning: metadata resource ${resourceMetadata.resource} does not match serverUrl ${context.serverUrl}`, |
61 | 59 | ); |
@@ -126,7 +124,7 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = { |
126 | 124 | clientInformation, |
127 | 125 | redirectUrl: context.provider.redirectUrl, |
128 | 126 | scope, |
129 | | - resource: context.state.resource, |
| 127 | + resource: context.state.resource ?? undefined, |
130 | 128 | }, |
131 | 129 | ); |
132 | 130 |
|
@@ -177,7 +175,7 @@ export const oauthTransitions: Record<OAuthStep, StateTransition> = { |
177 | 175 | authorizationCode: context.state.authorizationCode, |
178 | 176 | codeVerifier, |
179 | 177 | redirectUri: context.provider.redirectUrl, |
180 | | - resource: context.state.resource, |
| 178 | + resource: context.state.resource ?? undefined, |
181 | 179 | }); |
182 | 180 |
|
183 | 181 | context.provider.saveTokens(tokens); |
|
0 commit comments