@ai-sdk/mcp 2.0.6 → 2.0.8

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,21 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 2.0.8
4
+
5
+ ### Patch Changes
6
+
7
+ - 3e6e955: Reject in-flight MCP requests when their abort signal fires and remove the pending response handler.
8
+ - eebd14b: Prevent streamable HTTP MCP background SSE disconnects from surfacing as unhandled promise rejections.
9
+
10
+ ## 2.0.7
11
+
12
+ ### Patch Changes
13
+
14
+ - 5c5c0f5: Add experimental streaming transcription support for transcription models, including OpenAI `gpt-realtime-whisper` and xAI WebSocket STT.
15
+ - Updated dependencies [5c5c0f5]
16
+ - @ai-sdk/provider@4.0.2
17
+ - @ai-sdk/provider-utils@5.0.5
18
+
3
19
  ## 2.0.6
4
20
 
5
21
  ### Patch Changes
package/dist/index.js CHANGED
@@ -1635,7 +1635,7 @@ var HttpMCPTransport = class {
1635
1635
  });
1636
1636
  }
1637
1637
  this.abortController = new AbortController();
1638
- void this.openInboundSse();
1638
+ this.startInboundSse();
1639
1639
  }
1640
1640
  async close() {
1641
1641
  var _a3, _b3, _c;
@@ -1693,7 +1693,7 @@ var HttpMCPTransport = class {
1693
1693
  }
1694
1694
  if (response.status === 202) {
1695
1695
  if (!this.inboundSseConnection) {
1696
- void this.openInboundSse();
1696
+ this.startInboundSse();
1697
1697
  }
1698
1698
  return;
1699
1699
  }
@@ -1769,7 +1769,13 @@ var HttpMCPTransport = class {
1769
1769
  (_c2 = this.onerror) == null ? void 0 : _c2.call(this, error2);
1770
1770
  }
1771
1771
  };
1772
- processEvents();
1772
+ void processEvents().catch((error2) => {
1773
+ var _a4;
1774
+ if (error2 instanceof Error && error2.name === "AbortError") {
1775
+ return;
1776
+ }
1777
+ (_a4 = this.onerror) == null ? void 0 : _a4.call(this, error2);
1778
+ });
1773
1779
  return;
1774
1780
  }
1775
1781
  const error = new MCPClientError({
@@ -1811,12 +1817,21 @@ var HttpMCPTransport = class {
1811
1817
  }
1812
1818
  const delay = this.getNextReconnectionDelay(this.inboundReconnectAttempts);
1813
1819
  this.inboundReconnectAttempts += 1;
1814
- setTimeout(async () => {
1820
+ setTimeout(() => {
1815
1821
  var _a4;
1816
1822
  if ((_a4 = this.abortController) == null ? void 0 : _a4.signal.aborted) return;
1817
- await this.openInboundSse(false, this.lastInboundEventId);
1823
+ this.startInboundSse(false, this.lastInboundEventId);
1818
1824
  }, delay);
1819
1825
  }
1826
+ startInboundSse(triedAuth = false, resumeToken) {
1827
+ void this.openInboundSse(triedAuth, resumeToken).catch((error) => {
1828
+ var _a3;
1829
+ if (error instanceof Error && error.name === "AbortError") {
1830
+ return;
1831
+ }
1832
+ (_a3 = this.onerror) == null ? void 0 : _a3.call(this, error);
1833
+ });
1834
+ }
1820
1835
  // Open optional inbound SSE stream; best-effort and resumable
1821
1836
  async openInboundSse(triedAuth = false, resumeToken) {
1822
1837
  var _a3, _b3, _c, _d, _e, _f;
@@ -1903,10 +1918,27 @@ var HttpMCPTransport = class {
1903
1918
  }
1904
1919
  };
1905
1920
  this.inboundSseConnection = {
1906
- close: () => reader.cancel()
1921
+ close: () => {
1922
+ void reader.cancel().catch((error) => {
1923
+ var _a4;
1924
+ if (error instanceof Error && error.name === "AbortError") {
1925
+ return;
1926
+ }
1927
+ (_a4 = this.onerror) == null ? void 0 : _a4.call(this, error);
1928
+ });
1929
+ }
1907
1930
  };
1908
1931
  this.inboundReconnectAttempts = 0;
1909
- processEvents();
1932
+ void processEvents().catch((error) => {
1933
+ var _a4, _b4;
1934
+ if (error instanceof Error && error.name === "AbortError") {
1935
+ return;
1936
+ }
1937
+ (_a4 = this.onerror) == null ? void 0 : _a4.call(this, error);
1938
+ if (!((_b4 = this.abortController) == null ? void 0 : _b4.signal.aborted)) {
1939
+ this.scheduleInboundSseReconnection();
1940
+ }
1941
+ });
1910
1942
  } catch (error) {
1911
1943
  if (error instanceof Error && error.name === "AbortError") {
1912
1944
  return;
@@ -2306,35 +2338,49 @@ var DefaultMCPClient = class {
2306
2338
  jsonrpc: "2.0",
2307
2339
  id: messageId
2308
2340
  };
2341
+ const rejectWithAbortError = () => {
2342
+ reject(
2343
+ new MCPClientError({
2344
+ message: "Request was aborted",
2345
+ cause: signal == null ? void 0 : signal.reason
2346
+ })
2347
+ );
2348
+ };
2309
2349
  const cleanup = () => {
2310
2350
  this.responseHandlers.delete(messageId);
2351
+ signal == null ? void 0 : signal.removeEventListener("abort", onAbort);
2352
+ };
2353
+ const rejectAndCleanup = (error) => {
2354
+ cleanup();
2355
+ reject(error);
2356
+ };
2357
+ const onAbort = () => {
2358
+ cleanup();
2359
+ rejectWithAbortError();
2311
2360
  };
2312
2361
  this.responseHandlers.set(messageId, (response) => {
2313
2362
  if (signal == null ? void 0 : signal.aborted) {
2314
- return reject(
2315
- new MCPClientError({
2316
- message: "Request was aborted",
2317
- cause: signal.reason
2318
- })
2319
- );
2363
+ cleanup();
2364
+ return rejectWithAbortError();
2320
2365
  }
2321
2366
  if (response instanceof Error) {
2322
- return reject(response);
2367
+ return rejectAndCleanup(response);
2323
2368
  }
2324
2369
  try {
2325
2370
  const result = resultSchema.parse(response.result);
2371
+ cleanup();
2326
2372
  resolve(result);
2327
2373
  } catch (error) {
2328
2374
  const parseError = new MCPClientError({
2329
2375
  message: "Failed to parse server response",
2330
2376
  cause: error
2331
2377
  });
2332
- reject(parseError);
2378
+ rejectAndCleanup(parseError);
2333
2379
  }
2334
2380
  });
2381
+ signal == null ? void 0 : signal.addEventListener("abort", onAbort, { once: true });
2335
2382
  this.transport.send(jsonrpcRequest).catch((error) => {
2336
- cleanup();
2337
- reject(error);
2383
+ rejectAndCleanup(error);
2338
2384
  });
2339
2385
  });
2340
2386
  }