@ai-sdk/mcp 1.0.43 → 1.0.45

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,26 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 1.0.45
4
+
5
+ ### Patch Changes
6
+
7
+ - ec5fceb: fix(mcp): respond to ping requests with an empty result per JSON-RPC spec (closes #6282)
8
+
9
+ ## 1.0.44
10
+
11
+ ### Patch Changes
12
+
13
+ - 77775a4: feat(mcp): expose `statusCode`, `url`, and `responseBody` on `MCPClientError` for HTTP transport failures
14
+
15
+ `MCPClientError` now carries structured HTTP context when it originates from the
16
+ streamable HTTP transport. This lets downstream consumers (e.g. agent frameworks
17
+ that need to decide whether to fall back from streamable HTTP to legacy SSE
18
+ transport per the MCP spec) branch on the actual response status without parsing
19
+ the error message string.
20
+
21
+ Fields are optional — they remain `undefined` for stdio transport errors and for
22
+ non-response failures (network errors, aborts).
23
+
3
24
  ## 1.0.43
4
25
 
5
26
  ### Patch Changes
package/dist/index.js CHANGED
@@ -54,12 +54,18 @@ var MCPClientError = class extends (_b = import_provider.AISDKError, _a = symbol
54
54
  message,
55
55
  cause,
56
56
  data,
57
- code
57
+ code,
58
+ statusCode,
59
+ url,
60
+ responseBody
58
61
  }) {
59
62
  super({ name: name3, message, cause });
60
63
  this[_a] = true;
61
64
  this.data = data;
62
65
  this.code = code;
66
+ this.statusCode = statusCode;
67
+ this.url = url;
68
+ this.responseBody = responseBody;
63
69
  }
64
70
  static isInstance(error) {
65
71
  return import_provider.AISDKError.hasMarker(error, marker);
@@ -1443,7 +1449,10 @@ var HttpMCPTransport = class {
1443
1449
  errorMessage += ". This server does not support HTTP transport. Try using `sse` transport instead";
1444
1450
  }
1445
1451
  const error2 = new MCPClientError({
1446
- message: errorMessage
1452
+ message: errorMessage,
1453
+ statusCode: response.status,
1454
+ url: this.url.href,
1455
+ responseBody: text != null ? text : void 0
1447
1456
  });
1448
1457
  (_c = this.onerror) == null ? void 0 : _c.call(this, error2);
1449
1458
  throw error2;
@@ -1462,7 +1471,9 @@ var HttpMCPTransport = class {
1462
1471
  if (contentType.includes("text/event-stream")) {
1463
1472
  if (!response.body) {
1464
1473
  const error2 = new MCPClientError({
1465
- message: "MCP HTTP Transport Error: text/event-stream response without body"
1474
+ message: "MCP HTTP Transport Error: text/event-stream response without body",
1475
+ statusCode: response.status,
1476
+ url: this.url.href
1466
1477
  });
1467
1478
  (_e = this.onerror) == null ? void 0 : _e.call(this, error2);
1468
1479
  throw error2;
@@ -1500,7 +1511,9 @@ var HttpMCPTransport = class {
1500
1511
  return;
1501
1512
  }
1502
1513
  const error = new MCPClientError({
1503
- message: `MCP HTTP Transport Error: Unexpected content type: ${contentType}`
1514
+ message: `MCP HTTP Transport Error: Unexpected content type: ${contentType}`,
1515
+ statusCode: response.status,
1516
+ url: this.url.href
1504
1517
  });
1505
1518
  (_f = this.onerror) == null ? void 0 : _f.call(this, error);
1506
1519
  throw error;
@@ -1582,7 +1595,9 @@ var HttpMCPTransport = class {
1582
1595
  }
1583
1596
  if (!response.ok || !response.body) {
1584
1597
  const error = new MCPClientError({
1585
- message: `MCP HTTP Transport Error: GET SSE failed: ${response.status} ${response.statusText}`
1598
+ message: `MCP HTTP Transport Error: GET SSE failed: ${response.status} ${response.statusText}`,
1599
+ statusCode: response.status,
1600
+ url: this.url.href
1586
1601
  });
1587
1602
  (_d = this.onerror) == null ? void 0 : _d.call(this, error);
1588
1603
  return;
@@ -2123,6 +2138,14 @@ var DefaultMCPClient = class {
2123
2138
  }
2124
2139
  async onRequestMessage(request) {
2125
2140
  try {
2141
+ if (request.method === "ping") {
2142
+ await this.transport.send({
2143
+ jsonrpc: "2.0",
2144
+ id: request.id,
2145
+ result: {}
2146
+ });
2147
+ return;
2148
+ }
2126
2149
  if (request.method !== "elicitation/create") {
2127
2150
  await this.transport.send({
2128
2151
  jsonrpc: "2.0",