@ai-sdk/mcp 1.0.83 → 1.0.85

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,24 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 1.0.85
4
+
5
+ ### Patch Changes
6
+
7
+ - 03c91a0: fix(mcp): preserve pre-registered OAuth clients after client authentication errors and require explicit provider provenance before replacing dynamically registered credentials
8
+ - f7f36d2: chore: enable dead code lint rules
9
+ - Updated dependencies [069a945]
10
+ - Updated dependencies [d1a36d2]
11
+ - Updated dependencies [f7f36d2]
12
+ - @ai-sdk/provider-utils@4.0.54
13
+
14
+ ## 1.0.84
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies [da2e17b]
19
+ - @ai-sdk/provider@3.0.17
20
+ - @ai-sdk/provider-utils@4.0.53
21
+
3
22
  ## 1.0.83
4
23
 
5
24
  ### Patch Changes
package/dist/index.d.mts CHANGED
@@ -189,6 +189,16 @@ interface OAuthClientProvider {
189
189
  get redirectUrl(): string | URL;
190
190
  get clientMetadata(): OAuthClientMetadata;
191
191
  clientInformation(): OAuthClientInformation | undefined | Promise<OAuthClientInformation | undefined>;
192
+ /**
193
+ * Returns whether the current client information was obtained through
194
+ * dynamic client registration.
195
+ *
196
+ * Return `true` only when the current client information was saved after a
197
+ * dynamic registration response. When this method is omitted or returns
198
+ * `false`, the client information is treated as pre-registered and is not
199
+ * automatically invalidated after client authentication errors.
200
+ */
201
+ isClientInformationDynamicallyRegistered?(): boolean | Promise<boolean>;
192
202
  saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
193
203
  authorizationServerInformation?(): OAuthAuthorizationServerInformation | undefined | Promise<OAuthAuthorizationServerInformation | undefined>;
194
204
  saveAuthorizationServerInformation?(authorizationServerInformation: OAuthAuthorizationServerInformation): void | Promise<void>;
package/dist/index.d.ts CHANGED
@@ -189,6 +189,16 @@ interface OAuthClientProvider {
189
189
  get redirectUrl(): string | URL;
190
190
  get clientMetadata(): OAuthClientMetadata;
191
191
  clientInformation(): OAuthClientInformation | undefined | Promise<OAuthClientInformation | undefined>;
192
+ /**
193
+ * Returns whether the current client information was obtained through
194
+ * dynamic client registration.
195
+ *
196
+ * Return `true` only when the current client information was saved after a
197
+ * dynamic registration response. When this method is omitted or returns
198
+ * `false`, the client information is treated as pre-registered and is not
199
+ * automatically invalidated after client authentication errors.
200
+ */
201
+ isClientInformationDynamicallyRegistered?(): boolean | Promise<boolean>;
192
202
  saveClientInformation?(clientInformation: OAuthClientInformation): void | Promise<void>;
193
203
  authorizationServerInformation?(): OAuthAuthorizationServerInformation | undefined | Promise<OAuthAuthorizationServerInformation | undefined>;
194
204
  saveAuthorizationServerInformation?(authorizationServerInformation: OAuthAuthorizationServerInformation): void | Promise<void>;
package/dist/index.js CHANGED
@@ -1156,15 +1156,18 @@ async function registerClient(authorizationServerUrl, {
1156
1156
  return OAuthClientInformationFullSchema.parse(await response.json());
1157
1157
  }
1158
1158
  async function auth(provider, options) {
1159
- var _a3, _b3;
1159
+ var _a3, _b3, _c;
1160
1160
  try {
1161
1161
  return await authInternal(provider, options);
1162
1162
  } catch (error) {
1163
1163
  if (error instanceof InvalidClientError || error instanceof UnauthorizedClientError) {
1164
- await ((_a3 = provider.invalidateCredentials) == null ? void 0 : _a3.call(provider, "all"));
1164
+ if (options.authorizationCode !== void 0 || !await ((_a3 = provider.isClientInformationDynamicallyRegistered) == null ? void 0 : _a3.call(provider))) {
1165
+ throw error;
1166
+ }
1167
+ await ((_b3 = provider.invalidateCredentials) == null ? void 0 : _b3.call(provider, "all"));
1165
1168
  return await authInternal(provider, options);
1166
1169
  } else if (error instanceof InvalidGrantError) {
1167
- await ((_b3 = provider.invalidateCredentials) == null ? void 0 : _b3.call(provider, "tokens"));
1170
+ await ((_c = provider.invalidateCredentials) == null ? void 0 : _c.call(provider, "tokens"));
1168
1171
  return await authInternal(provider, options);
1169
1172
  }
1170
1173
  throw error;
@@ -2486,93 +2489,69 @@ var DefaultMCPClient = class {
2486
2489
  args,
2487
2490
  options
2488
2491
  }) {
2489
- try {
2490
- return this.callToolWithRetry({
2491
- options,
2492
- execute: () => this.request({
2493
- request: {
2494
- method: "tools/call",
2495
- params: { name: name3, arguments: args }
2496
- },
2497
- resultSchema: CallToolResultSchema,
2498
- options: {
2499
- signal: options == null ? void 0 : options.abortSignal
2500
- }
2501
- })
2502
- });
2503
- } catch (error) {
2504
- throw error;
2505
- }
2492
+ return this.callToolWithRetry({
2493
+ options,
2494
+ execute: () => this.request({
2495
+ request: {
2496
+ method: "tools/call",
2497
+ params: { name: name3, arguments: args }
2498
+ },
2499
+ resultSchema: CallToolResultSchema,
2500
+ options: {
2501
+ signal: options == null ? void 0 : options.abortSignal
2502
+ }
2503
+ })
2504
+ });
2506
2505
  }
2507
2506
  async listResourcesInternal({
2508
2507
  params,
2509
2508
  options
2510
2509
  } = {}) {
2511
- try {
2512
- return this.request({
2513
- request: { method: "resources/list", params },
2514
- resultSchema: ListResourcesResultSchema,
2515
- options
2516
- });
2517
- } catch (error) {
2518
- throw error;
2519
- }
2510
+ return this.request({
2511
+ request: { method: "resources/list", params },
2512
+ resultSchema: ListResourcesResultSchema,
2513
+ options
2514
+ });
2520
2515
  }
2521
2516
  async readResourceInternal({
2522
2517
  uri,
2523
2518
  options
2524
2519
  }) {
2525
- try {
2526
- return this.request({
2527
- request: { method: "resources/read", params: { uri } },
2528
- resultSchema: ReadResourceResultSchema,
2529
- options
2530
- });
2531
- } catch (error) {
2532
- throw error;
2533
- }
2520
+ return this.request({
2521
+ request: { method: "resources/read", params: { uri } },
2522
+ resultSchema: ReadResourceResultSchema,
2523
+ options
2524
+ });
2534
2525
  }
2535
2526
  async listResourceTemplatesInternal({
2536
2527
  options
2537
2528
  } = {}) {
2538
- try {
2539
- return this.request({
2540
- request: { method: "resources/templates/list" },
2541
- resultSchema: ListResourceTemplatesResultSchema,
2542
- options
2543
- });
2544
- } catch (error) {
2545
- throw error;
2546
- }
2529
+ return this.request({
2530
+ request: { method: "resources/templates/list" },
2531
+ resultSchema: ListResourceTemplatesResultSchema,
2532
+ options
2533
+ });
2547
2534
  }
2548
2535
  async listPromptsInternal({
2549
2536
  params,
2550
2537
  options
2551
2538
  } = {}) {
2552
- try {
2553
- return this.request({
2554
- request: { method: "prompts/list", params },
2555
- resultSchema: ListPromptsResultSchema,
2556
- options
2557
- });
2558
- } catch (error) {
2559
- throw error;
2560
- }
2539
+ return this.request({
2540
+ request: { method: "prompts/list", params },
2541
+ resultSchema: ListPromptsResultSchema,
2542
+ options
2543
+ });
2561
2544
  }
2562
2545
  async getPromptInternal({
2563
2546
  name: name3,
2564
2547
  args,
2565
2548
  options
2566
2549
  }) {
2567
- try {
2568
- return this.request({
2569
- request: { method: "prompts/get", params: { name: name3, arguments: args } },
2570
- resultSchema: GetPromptResultSchema,
2571
- options
2572
- });
2573
- } catch (error) {
2574
- throw error;
2575
- }
2550
+ return this.request({
2551
+ request: { method: "prompts/get", params: { name: name3, arguments: args } },
2552
+ resultSchema: GetPromptResultSchema,
2553
+ options
2554
+ });
2576
2555
  }
2577
2556
  async completeInternal({
2578
2557
  options,