@ai-sdk/mcp 1.0.80 → 1.0.81
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/index.js +19 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +19 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/tool/oauth.ts +30 -5
package/package.json
CHANGED
package/src/tool/oauth.ts
CHANGED
|
@@ -1199,6 +1199,10 @@ async function authInternal(
|
|
|
1199
1199
|
): Promise<AuthResult> {
|
|
1200
1200
|
let resourceMetadata: OAuthProtectedResourceMetadata | undefined;
|
|
1201
1201
|
let authorizationServerUrl: string | URL | undefined;
|
|
1202
|
+
let clientInformation: OAuthClientInformation | undefined;
|
|
1203
|
+
let callbackAuthorizationServerInformation:
|
|
1204
|
+
| OAuthAuthorizationServerInformation
|
|
1205
|
+
| undefined;
|
|
1202
1206
|
|
|
1203
1207
|
/** Reject Protected Resource Metadata URLs outside the configured MCP server origin. */
|
|
1204
1208
|
assertResourceMetadataUrlSameOrigin(serverUrl, resourceMetadataUrl);
|
|
@@ -1218,9 +1222,27 @@ async function authInternal(
|
|
|
1218
1222
|
}
|
|
1219
1223
|
} catch {}
|
|
1220
1224
|
|
|
1221
|
-
/**
|
|
1225
|
+
/**
|
|
1226
|
+
* A callback may not have the original PRM URL from the authentication
|
|
1227
|
+
* challenge. Use the authorization server pinned before redirecting when
|
|
1228
|
+
* rediscovery does not select one.
|
|
1229
|
+
*/
|
|
1230
|
+
if (authorizationCode !== undefined) {
|
|
1231
|
+
clientInformation = await Promise.resolve(provider.clientInformation());
|
|
1232
|
+
if (clientInformation) {
|
|
1233
|
+
callbackAuthorizationServerInformation =
|
|
1234
|
+
await getStoredAuthorizationServerInformation({
|
|
1235
|
+
provider,
|
|
1236
|
+
clientInformation,
|
|
1237
|
+
});
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
/** Reuse the callback pin, then fall back to the legacy MCP-as-AS behavior. */
|
|
1222
1242
|
if (!authorizationServerUrl) {
|
|
1223
|
-
authorizationServerUrl =
|
|
1243
|
+
authorizationServerUrl =
|
|
1244
|
+
callbackAuthorizationServerInformation?.authorizationServerUrl ??
|
|
1245
|
+
serverUrl;
|
|
1224
1246
|
}
|
|
1225
1247
|
|
|
1226
1248
|
/** Validate and select the resource value sent to the AS */
|
|
@@ -1253,7 +1275,9 @@ async function authInternal(
|
|
|
1253
1275
|
});
|
|
1254
1276
|
|
|
1255
1277
|
/** Load or register client credentials with the AS pin attached. */
|
|
1256
|
-
|
|
1278
|
+
if (authorizationCode === undefined) {
|
|
1279
|
+
clientInformation = await Promise.resolve(provider.clientInformation());
|
|
1280
|
+
}
|
|
1257
1281
|
if (!clientInformation) {
|
|
1258
1282
|
if (authorizationCode !== undefined) {
|
|
1259
1283
|
throw new Error(
|
|
@@ -1295,10 +1319,11 @@ async function authInternal(
|
|
|
1295
1319
|
}
|
|
1296
1320
|
|
|
1297
1321
|
const storedAuthorizationServerInformation =
|
|
1298
|
-
|
|
1322
|
+
callbackAuthorizationServerInformation ??
|
|
1323
|
+
(await getStoredAuthorizationServerInformation({
|
|
1299
1324
|
provider,
|
|
1300
1325
|
clientInformation,
|
|
1301
|
-
});
|
|
1326
|
+
}));
|
|
1302
1327
|
if (!storedAuthorizationServerInformation) {
|
|
1303
1328
|
throw new MCPClientOAuthError({
|
|
1304
1329
|
message:
|