@ai-sdk/mcp 1.0.47 → 1.0.49

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
@@ -1075,7 +1075,7 @@ async function authInternal(provider, {
1075
1075
  resourceMetadataUrl,
1076
1076
  fetchFn
1077
1077
  }) {
1078
- var _a3;
1078
+ var _a3, _b3;
1079
1079
  let resourceMetadata;
1080
1080
  let authorizationServerUrl;
1081
1081
  assertResourceMetadataUrlSameOrigin(serverUrl, resourceMetadataUrl);
@@ -1098,6 +1098,11 @@ async function authInternal(provider, {
1098
1098
  provider,
1099
1099
  resourceMetadata
1100
1100
  );
1101
+ await ((_a3 = provider.validateAuthorizationServerURL) == null ? void 0 : _a3.call(
1102
+ provider,
1103
+ serverUrl,
1104
+ authorizationServerUrl
1105
+ ));
1101
1106
  const metadata = await discoverAuthorizationServerMetadata(
1102
1107
  authorizationServerUrl,
1103
1108
  {
@@ -1182,7 +1187,7 @@ async function authInternal(provider, {
1182
1187
  currentAuthorizationServerInformation
1183
1188
  });
1184
1189
  } else {
1185
- await ((_a3 = provider.invalidateCredentials) == null ? void 0 : _a3.call(provider, "tokens"));
1190
+ await ((_b3 = provider.invalidateCredentials) == null ? void 0 : _b3.call(provider, "tokens"));
1186
1191
  }
1187
1192
  try {
1188
1193
  if (storedAuthorizationServerInformation) {
@@ -1258,6 +1263,9 @@ var SseMCPTransport = class {
1258
1263
  this.redirectMode = redirect;
1259
1264
  this.fetchFn = fetchFn != null ? fetchFn : globalThis.fetch;
1260
1265
  }
1266
+ setProtocolVersion(version) {
1267
+ this.protocolVersion = version;
1268
+ }
1261
1269
  async commonHeaders(base) {
1262
1270
  var _a3;
1263
1271
  const headers = {
@@ -1327,7 +1335,7 @@ var SseMCPTransport = class {
1327
1335
  const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream());
1328
1336
  const reader = stream.getReader();
1329
1337
  const processEvents = async () => {
1330
- var _a4, _b4, _c2;
1338
+ var _a4, _b4, _c2, _d2, _e2;
1331
1339
  try {
1332
1340
  while (true) {
1333
1341
  const { done, value } = await reader.read();
@@ -1342,24 +1350,32 @@ var SseMCPTransport = class {
1342
1350
  }
1343
1351
  const { event, data } = value;
1344
1352
  if (event === "endpoint") {
1345
- this.endpoint = new URL(data, this.url);
1346
- if (this.endpoint.origin !== this.url.origin) {
1353
+ if (this.endpoint) {
1354
+ continue;
1355
+ }
1356
+ const endpoint = new URL(data, this.url);
1357
+ if (endpoint.origin !== this.url.origin) {
1358
+ this.connected = false;
1359
+ this.endpoint = void 0;
1360
+ (_a4 = this.sseConnection) == null ? void 0 : _a4.close();
1361
+ (_b4 = this.abortController) == null ? void 0 : _b4.abort();
1347
1362
  throw new MCPClientError({
1348
- message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${this.endpoint.origin}`
1363
+ message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${endpoint.origin}`
1349
1364
  });
1350
1365
  }
1366
+ this.endpoint = endpoint;
1351
1367
  this.connected = true;
1352
1368
  resolve();
1353
1369
  } else if (event === "message") {
1354
1370
  try {
1355
1371
  const message = await parseJSONRPCMessage(data);
1356
- (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, message);
1372
+ (_c2 = this.onmessage) == null ? void 0 : _c2.call(this, message);
1357
1373
  } catch (error) {
1358
1374
  const e = new MCPClientError({
1359
1375
  message: "MCP SSE Transport Error: Failed to parse message",
1360
1376
  cause: error
1361
1377
  });
1362
- (_b4 = this.onerror) == null ? void 0 : _b4.call(this, e);
1378
+ (_d2 = this.onerror) == null ? void 0 : _d2.call(this, e);
1363
1379
  }
1364
1380
  }
1365
1381
  }
@@ -1367,7 +1383,7 @@ var SseMCPTransport = class {
1367
1383
  if (error instanceof Error && error.name === "AbortError") {
1368
1384
  return;
1369
1385
  }
1370
- (_c2 = this.onerror) == null ? void 0 : _c2.call(this, error);
1386
+ (_e2 = this.onerror) == null ? void 0 : _e2.call(this, error);
1371
1387
  reject(error);
1372
1388
  }
1373
1389
  };
@@ -1389,6 +1405,7 @@ var SseMCPTransport = class {
1389
1405
  async close() {
1390
1406
  var _a3, _b3, _c;
1391
1407
  this.connected = false;
1408
+ this.endpoint = void 0;
1392
1409
  (_a3 = this.sseConnection) == null ? void 0 : _a3.close();
1393
1410
  (_b3 = this.abortController) == null ? void 0 : _b3.abort();
1394
1411
  (_c = this.onclose) == null ? void 0 : _c.call(this);
@@ -1477,6 +1494,9 @@ var HttpMCPTransport = class {
1477
1494
  this.redirectMode = redirect;
1478
1495
  this.fetchFn = fetchFn != null ? fetchFn : globalThis.fetch;
1479
1496
  }
1497
+ setProtocolVersion(version) {
1498
+ this.protocolVersion = version;
1499
+ }
1480
1500
  async commonHeaders(base) {
1481
1501
  var _a3;
1482
1502
  const headers = {
@@ -1920,8 +1940,12 @@ var DefaultMCPClient = class {
1920
1940
  }
1921
1941
  this.serverCapabilities = result.capabilities;
1922
1942
  this._serverInfo = result.serverInfo;
1943
+ if (this.transport.setProtocolVersion) {
1944
+ this.transport.setProtocolVersion(result.protocolVersion);
1945
+ } else {
1946
+ this.transport.protocolVersion = result.protocolVersion;
1947
+ }
1923
1948
  this._serverInstructions = result.instructions;
1924
- this.transport.protocolVersion = result.protocolVersion;
1925
1949
  await this.notification({
1926
1950
  method: "notifications/initialized"
1927
1951
  });
@@ -2158,7 +2182,7 @@ var DefaultMCPClient = class {
2158
2182
  _meta
2159
2183
  } of definitions.tools) {
2160
2184
  const resolvedTitle = title != null ? title : annotations == null ? void 0 : annotations.title;
2161
- if (schemas !== "automatic" && !(name3 in schemas)) {
2185
+ if (schemas !== "automatic" && !Object.prototype.hasOwnProperty.call(schemas, name3)) {
2162
2186
  continue;
2163
2187
  }
2164
2188
  const self = this;