@ai-sdk/mcp 1.0.97 → 1.0.98
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.d.mts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +48 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -5
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/tool/oauth-types.ts +1 -0
- package/src/tool/oauth.ts +78 -3
package/dist/index.mjs
CHANGED
|
@@ -429,6 +429,7 @@ var OAuthClientInformationSchema = z3.object({
|
|
|
429
429
|
client_secret: z3.string().optional(),
|
|
430
430
|
client_id_issued_at: z3.number().optional(),
|
|
431
431
|
client_secret_expires_at: z3.number().optional(),
|
|
432
|
+
issuer: SafeUrlSchema.optional(),
|
|
432
433
|
authorization_server: SafeUrlSchema.optional(),
|
|
433
434
|
token_endpoint: SafeUrlSchema.optional()
|
|
434
435
|
}).strip();
|
|
@@ -1209,10 +1210,16 @@ async function auth(provider, options) {
|
|
|
1209
1210
|
await ((_b3 = provider.invalidateCredentials) == null ? void 0 : _b3.call(provider, "all"));
|
|
1210
1211
|
return await authInternal(provider, options);
|
|
1211
1212
|
} else if (error instanceof InvalidGrantError && refreshAttempt.tokens) {
|
|
1213
|
+
const retryAuthorizationServerInformation = getAuthorizationServerInformationFromCredentials(refreshAttempt.tokens);
|
|
1212
1214
|
await ((_c = provider.invalidateCredentials) == null ? void 0 : _c.call(provider, "tokens", {
|
|
1213
1215
|
tokens: refreshAttempt.tokens
|
|
1214
1216
|
}));
|
|
1215
|
-
return await authInternal(
|
|
1217
|
+
return await authInternal(
|
|
1218
|
+
provider,
|
|
1219
|
+
options,
|
|
1220
|
+
void 0,
|
|
1221
|
+
retryAuthorizationServerInformation
|
|
1222
|
+
);
|
|
1216
1223
|
}
|
|
1217
1224
|
throw error;
|
|
1218
1225
|
}
|
|
@@ -1245,8 +1252,8 @@ async function authInternal(provider, {
|
|
|
1245
1252
|
scope,
|
|
1246
1253
|
resourceMetadataUrl,
|
|
1247
1254
|
fetchFn
|
|
1248
|
-
}, refreshAttempt) {
|
|
1249
|
-
var _a3, _b3, _c;
|
|
1255
|
+
}, refreshAttempt, retryAuthorizationServerInformation) {
|
|
1256
|
+
var _a3, _b3, _c, _d, _e;
|
|
1250
1257
|
let resourceMetadata;
|
|
1251
1258
|
let authorizationServerUrl;
|
|
1252
1259
|
let clientInformation;
|
|
@@ -1301,6 +1308,12 @@ async function authInternal(provider, {
|
|
|
1301
1308
|
}
|
|
1302
1309
|
);
|
|
1303
1310
|
const currentAuthorizationServerInformation = createAuthorizationServerInformation(authorizationServerUrl, metadata);
|
|
1311
|
+
if (retryAuthorizationServerInformation) {
|
|
1312
|
+
assertAuthorizationServerInformationMatches({
|
|
1313
|
+
storedAuthorizationServerInformation: retryAuthorizationServerInformation,
|
|
1314
|
+
currentAuthorizationServerInformation
|
|
1315
|
+
});
|
|
1316
|
+
}
|
|
1304
1317
|
const clientMetadata = provider.clientMetadata;
|
|
1305
1318
|
const selectedScope = selectScope({
|
|
1306
1319
|
scope,
|
|
@@ -1310,6 +1323,37 @@ async function authInternal(provider, {
|
|
|
1310
1323
|
if (authorizationCode === void 0) {
|
|
1311
1324
|
clientInformation = await Promise.resolve(provider.clientInformation());
|
|
1312
1325
|
}
|
|
1326
|
+
const tokens = authorizationCode === void 0 ? await provider.tokens() : void 0;
|
|
1327
|
+
if (clientInformation) {
|
|
1328
|
+
if (clientInformation.issuer != null && clientInformation.issuer !== ((_c = metadata == null ? void 0 : metadata.issuer) != null ? _c : authorizationServerUrl.toString())) {
|
|
1329
|
+
throw new MCPClientOAuthError({
|
|
1330
|
+
message: "OAuth authorization server does not match the issuer of the client credentials"
|
|
1331
|
+
});
|
|
1332
|
+
}
|
|
1333
|
+
const clientAuthorizationServerInformation = getAuthorizationServerInformationFromCredentials(clientInformation);
|
|
1334
|
+
if (clientAuthorizationServerInformation) {
|
|
1335
|
+
assertAuthorizationServerInformationMatches({
|
|
1336
|
+
storedAuthorizationServerInformation: clientAuthorizationServerInformation,
|
|
1337
|
+
currentAuthorizationServerInformation
|
|
1338
|
+
});
|
|
1339
|
+
}
|
|
1340
|
+
const storedAuthorizationServerInformation = (_d = callbackAuthorizationServerInformation != null ? callbackAuthorizationServerInformation : await getStoredAuthorizationServerInformation({
|
|
1341
|
+
provider,
|
|
1342
|
+
clientInformation,
|
|
1343
|
+
tokens
|
|
1344
|
+
})) != null ? _d : retryAuthorizationServerInformation;
|
|
1345
|
+
if (storedAuthorizationServerInformation) {
|
|
1346
|
+
assertAuthorizationServerInformationMatches({
|
|
1347
|
+
storedAuthorizationServerInformation,
|
|
1348
|
+
currentAuthorizationServerInformation
|
|
1349
|
+
});
|
|
1350
|
+
}
|
|
1351
|
+
if ((clientInformation.client_secret != null || provider.addClientAuthentication) && clientInformation.issuer == null && !storedAuthorizationServerInformation) {
|
|
1352
|
+
throw new MCPClientOAuthError({
|
|
1353
|
+
message: "OAuth client credentials must be bound to an authorization server: configure their issuer or store authorization server information"
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1313
1357
|
if (!clientInformation) {
|
|
1314
1358
|
if (authorizationCode !== void 0) {
|
|
1315
1359
|
throw new Error(
|
|
@@ -1376,7 +1420,6 @@ async function authInternal(provider, {
|
|
|
1376
1420
|
);
|
|
1377
1421
|
return "AUTHORIZED";
|
|
1378
1422
|
}
|
|
1379
|
-
const tokens = await provider.tokens();
|
|
1380
1423
|
if (tokens == null ? void 0 : tokens.refresh_token) {
|
|
1381
1424
|
const storedAuthorizationServerInformation = await getStoredAuthorizationServerInformation({
|
|
1382
1425
|
provider,
|
|
@@ -1389,7 +1432,7 @@ async function authInternal(provider, {
|
|
|
1389
1432
|
currentAuthorizationServerInformation
|
|
1390
1433
|
});
|
|
1391
1434
|
} else {
|
|
1392
|
-
await ((
|
|
1435
|
+
await ((_e = provider.invalidateCredentials) == null ? void 0 : _e.call(provider, "tokens", {
|
|
1393
1436
|
tokens: { ...tokens }
|
|
1394
1437
|
}));
|
|
1395
1438
|
}
|