@ai-sdk/mcp 1.0.90 → 1.0.91

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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 1.0.91
4
+
5
+ ### Patch Changes
6
+
7
+ - 5267a7a: Preserve stored OAuth credentials when an authorization-code exchange returns `invalid_grant`, without retrying the rejected code.
8
+
9
+ Add optional token context to `OAuthClientProvider.invalidateCredentials` so providers sharing storage can atomically delete only the rejected token generation and preserve tokens saved by a concurrent refresh.
10
+
3
11
  ## 1.0.90
4
12
 
5
13
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -184,8 +184,15 @@ interface OAuthClientProvider {
184
184
  * If implemented, provides a way for the client to invalidate (e.g. delete) the specified
185
185
  * credentials, in the case where the server has indicated that they are no longer valid.
186
186
  * This avoids requiring the user to intervene manually.
187
+ *
188
+ * For token invalidation, context identifies the token generation being invalidated
189
+ * when available. Providers sharing storage must atomically compare and delete
190
+ * that generation so a concurrent refresh's tokens are preserved. Omitting or
191
+ * ignoring context retains unconditional invalidation.
187
192
  */
188
- invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier'): void | Promise<void>;
193
+ invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier', context?: {
194
+ tokens: OAuthTokens;
195
+ }): void | Promise<void>;
189
196
  get redirectUrl(): string | URL;
190
197
  get clientMetadata(): OAuthClientMetadata;
191
198
  clientInformation(): OAuthClientInformation | undefined | Promise<OAuthClientInformation | undefined>;
package/dist/index.d.ts CHANGED
@@ -184,8 +184,15 @@ interface OAuthClientProvider {
184
184
  * If implemented, provides a way for the client to invalidate (e.g. delete) the specified
185
185
  * credentials, in the case where the server has indicated that they are no longer valid.
186
186
  * This avoids requiring the user to intervene manually.
187
+ *
188
+ * For token invalidation, context identifies the token generation being invalidated
189
+ * when available. Providers sharing storage must atomically compare and delete
190
+ * that generation so a concurrent refresh's tokens are preserved. Omitting or
191
+ * ignoring context retains unconditional invalidation.
187
192
  */
188
- invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier'): void | Promise<void>;
193
+ invalidateCredentials?(scope: 'all' | 'client' | 'tokens' | 'verifier', context?: {
194
+ tokens: OAuthTokens;
195
+ }): void | Promise<void>;
189
196
  get redirectUrl(): string | URL;
190
197
  get clientMetadata(): OAuthClientMetadata;
191
198
  clientInformation(): OAuthClientInformation | undefined | Promise<OAuthClientInformation | undefined>;
package/dist/index.js CHANGED
@@ -1215,8 +1215,9 @@ async function registerClient(authorizationServerUrl, {
1215
1215
  }
1216
1216
  async function auth(provider, options) {
1217
1217
  var _a3, _b3, _c;
1218
+ const refreshAttempt = {};
1218
1219
  try {
1219
- return await authInternal(provider, options);
1220
+ return await authInternal(provider, options, refreshAttempt);
1220
1221
  } catch (error) {
1221
1222
  if (error instanceof InvalidClientError || error instanceof UnauthorizedClientError) {
1222
1223
  if (options.authorizationCode !== void 0 || !await ((_a3 = provider.isClientInformationDynamicallyRegistered) == null ? void 0 : _a3.call(provider))) {
@@ -1224,8 +1225,10 @@ async function auth(provider, options) {
1224
1225
  }
1225
1226
  await ((_b3 = provider.invalidateCredentials) == null ? void 0 : _b3.call(provider, "all"));
1226
1227
  return await authInternal(provider, options);
1227
- } else if (error instanceof InvalidGrantError) {
1228
- await ((_c = provider.invalidateCredentials) == null ? void 0 : _c.call(provider, "tokens"));
1228
+ } else if (error instanceof InvalidGrantError && refreshAttempt.tokens) {
1229
+ await ((_c = provider.invalidateCredentials) == null ? void 0 : _c.call(provider, "tokens", {
1230
+ tokens: refreshAttempt.tokens
1231
+ }));
1229
1232
  return await authInternal(provider, options);
1230
1233
  }
1231
1234
  throw error;
@@ -1259,7 +1262,7 @@ async function authInternal(provider, {
1259
1262
  scope,
1260
1263
  resourceMetadataUrl,
1261
1264
  fetchFn
1262
- }) {
1265
+ }, refreshAttempt) {
1263
1266
  var _a3, _b3, _c;
1264
1267
  let resourceMetadata;
1265
1268
  let authorizationServerUrl;
@@ -1403,10 +1406,15 @@ async function authInternal(provider, {
1403
1406
  currentAuthorizationServerInformation
1404
1407
  });
1405
1408
  } else {
1406
- await ((_c = provider.invalidateCredentials) == null ? void 0 : _c.call(provider, "tokens"));
1409
+ await ((_c = provider.invalidateCredentials) == null ? void 0 : _c.call(provider, "tokens", {
1410
+ tokens: { ...tokens }
1411
+ }));
1407
1412
  }
1408
1413
  try {
1409
1414
  if (storedAuthorizationServerInformation) {
1415
+ if (refreshAttempt) {
1416
+ refreshAttempt.tokens = { ...tokens };
1417
+ }
1410
1418
  const newTokens = await refreshAuthorization(authorizationServerUrl, {
1411
1419
  metadata,
1412
1420
  clientInformation,