@ai-sdk/mcp 0.0.18 → 0.0.20

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/dist/index.mjs CHANGED
@@ -1009,6 +1009,9 @@ async function authInternal(provider, {
1009
1009
  }
1010
1010
 
1011
1011
  // src/tool/mcp-sse-transport.ts
1012
+ function isMessageEvent(event) {
1013
+ return event === void 0 || event === "message";
1014
+ }
1012
1015
  var SseMCPTransport = class {
1013
1016
  constructor({
1014
1017
  url,
@@ -1086,7 +1089,7 @@ var SseMCPTransport = class {
1086
1089
  const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream());
1087
1090
  const reader = stream.getReader();
1088
1091
  const processEvents = async () => {
1089
- var _a4, _b4, _c2;
1092
+ var _a4, _b4, _c2, _d2, _e2;
1090
1093
  try {
1091
1094
  while (true) {
1092
1095
  const { done, value } = await reader.read();
@@ -1101,24 +1104,32 @@ var SseMCPTransport = class {
1101
1104
  }
1102
1105
  const { event, data } = value;
1103
1106
  if (event === "endpoint") {
1104
- this.endpoint = new URL(data, this.url);
1105
- if (this.endpoint.origin !== this.url.origin) {
1107
+ if (this.endpoint) {
1108
+ continue;
1109
+ }
1110
+ const endpoint = new URL(data, this.url);
1111
+ if (endpoint.origin !== this.url.origin) {
1112
+ this.connected = false;
1113
+ this.endpoint = void 0;
1114
+ (_a4 = this.sseConnection) == null ? void 0 : _a4.close();
1115
+ (_b4 = this.abortController) == null ? void 0 : _b4.abort();
1106
1116
  throw new MCPClientError({
1107
- message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${this.endpoint.origin}`
1117
+ message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${endpoint.origin}`
1108
1118
  });
1109
1119
  }
1120
+ this.endpoint = endpoint;
1110
1121
  this.connected = true;
1111
1122
  resolve();
1112
- } else if (event === "message") {
1123
+ } else if (isMessageEvent(event)) {
1113
1124
  try {
1114
1125
  const message = await parseJSONRPCMessage(data);
1115
- (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, message);
1126
+ (_c2 = this.onmessage) == null ? void 0 : _c2.call(this, message);
1116
1127
  } catch (error) {
1117
1128
  const e = new MCPClientError({
1118
1129
  message: "MCP SSE Transport Error: Failed to parse message",
1119
1130
  cause: error
1120
1131
  });
1121
- (_b4 = this.onerror) == null ? void 0 : _b4.call(this, e);
1132
+ (_d2 = this.onerror) == null ? void 0 : _d2.call(this, e);
1122
1133
  }
1123
1134
  }
1124
1135
  }
@@ -1126,7 +1137,7 @@ var SseMCPTransport = class {
1126
1137
  if (error instanceof Error && error.name === "AbortError") {
1127
1138
  return;
1128
1139
  }
1129
- (_c2 = this.onerror) == null ? void 0 : _c2.call(this, error);
1140
+ (_e2 = this.onerror) == null ? void 0 : _e2.call(this, error);
1130
1141
  reject(error);
1131
1142
  }
1132
1143
  };
@@ -1148,6 +1159,7 @@ var SseMCPTransport = class {
1148
1159
  async close() {
1149
1160
  var _a3, _b3, _c;
1150
1161
  this.connected = false;
1162
+ this.endpoint = void 0;
1151
1163
  (_a3 = this.sseConnection) == null ? void 0 : _a3.close();
1152
1164
  (_b3 = this.abortController) == null ? void 0 : _b3.abort();
1153
1165
  (_c = this.onclose) == null ? void 0 : _c.call(this);
@@ -1213,6 +1225,9 @@ import {
1213
1225
  withUserAgentSuffix as withUserAgentSuffix2,
1214
1226
  getRuntimeEnvironmentUserAgent as getRuntimeEnvironmentUserAgent2
1215
1227
  } from "@ai-sdk/provider-utils";
1228
+ function isMessageEvent2(event) {
1229
+ return event === void 0 || event === "message";
1230
+ }
1216
1231
  var HttpMCPTransport = class {
1217
1232
  constructor({
1218
1233
  url,
@@ -1355,7 +1370,7 @@ var HttpMCPTransport = class {
1355
1370
  const { done, value } = await reader.read();
1356
1371
  if (done) return;
1357
1372
  const { event, data } = value;
1358
- if (event === "message") {
1373
+ if (isMessageEvent2(event)) {
1359
1374
  try {
1360
1375
  const msg = await parseJSONRPCMessage(data);
1361
1376
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, msg);
@@ -1480,7 +1495,7 @@ var HttpMCPTransport = class {
1480
1495
  if (id) {
1481
1496
  this.lastInboundEventId = id;
1482
1497
  }
1483
- if (event === "message") {
1498
+ if (isMessageEvent2(event)) {
1484
1499
  try {
1485
1500
  const msg = await parseJSONRPCMessage(data);
1486
1501
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, msg);
@@ -1835,7 +1850,7 @@ var DefaultMCPClient = class {
1835
1850
  try {
1836
1851
  const listToolsResult = await this.listTools();
1837
1852
  for (const { name: name3, description, inputSchema } of listToolsResult.tools) {
1838
- if (schemas !== "automatic" && !(name3 in schemas)) {
1853
+ if (schemas !== "automatic" && !Object.prototype.hasOwnProperty.call(schemas, name3)) {
1839
1854
  continue;
1840
1855
  }
1841
1856
  const self = this;