@ai-sdk/mcp 1.0.48 → 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/CHANGELOG.md +19 -0
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/tool/mcp-client.ts +4 -1
- package/src/tool/mcp-sse-transport.ts +13 -3
package/dist/index.mjs
CHANGED
|
@@ -1335,7 +1335,7 @@ var SseMCPTransport = class {
|
|
|
1335
1335
|
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new EventSourceParserStream());
|
|
1336
1336
|
const reader = stream.getReader();
|
|
1337
1337
|
const processEvents = async () => {
|
|
1338
|
-
var _a4, _b4, _c2;
|
|
1338
|
+
var _a4, _b4, _c2, _d2, _e2;
|
|
1339
1339
|
try {
|
|
1340
1340
|
while (true) {
|
|
1341
1341
|
const { done, value } = await reader.read();
|
|
@@ -1350,24 +1350,32 @@ var SseMCPTransport = class {
|
|
|
1350
1350
|
}
|
|
1351
1351
|
const { event, data } = value;
|
|
1352
1352
|
if (event === "endpoint") {
|
|
1353
|
-
|
|
1354
|
-
|
|
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();
|
|
1355
1362
|
throw new MCPClientError({
|
|
1356
|
-
message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${
|
|
1363
|
+
message: `MCP SSE Transport Error: Endpoint origin does not match connection origin: ${endpoint.origin}`
|
|
1357
1364
|
});
|
|
1358
1365
|
}
|
|
1366
|
+
this.endpoint = endpoint;
|
|
1359
1367
|
this.connected = true;
|
|
1360
1368
|
resolve();
|
|
1361
1369
|
} else if (event === "message") {
|
|
1362
1370
|
try {
|
|
1363
1371
|
const message = await parseJSONRPCMessage(data);
|
|
1364
|
-
(
|
|
1372
|
+
(_c2 = this.onmessage) == null ? void 0 : _c2.call(this, message);
|
|
1365
1373
|
} catch (error) {
|
|
1366
1374
|
const e = new MCPClientError({
|
|
1367
1375
|
message: "MCP SSE Transport Error: Failed to parse message",
|
|
1368
1376
|
cause: error
|
|
1369
1377
|
});
|
|
1370
|
-
(
|
|
1378
|
+
(_d2 = this.onerror) == null ? void 0 : _d2.call(this, e);
|
|
1371
1379
|
}
|
|
1372
1380
|
}
|
|
1373
1381
|
}
|
|
@@ -1375,7 +1383,7 @@ var SseMCPTransport = class {
|
|
|
1375
1383
|
if (error instanceof Error && error.name === "AbortError") {
|
|
1376
1384
|
return;
|
|
1377
1385
|
}
|
|
1378
|
-
(
|
|
1386
|
+
(_e2 = this.onerror) == null ? void 0 : _e2.call(this, error);
|
|
1379
1387
|
reject(error);
|
|
1380
1388
|
}
|
|
1381
1389
|
};
|
|
@@ -1397,6 +1405,7 @@ var SseMCPTransport = class {
|
|
|
1397
1405
|
async close() {
|
|
1398
1406
|
var _a3, _b3, _c;
|
|
1399
1407
|
this.connected = false;
|
|
1408
|
+
this.endpoint = void 0;
|
|
1400
1409
|
(_a3 = this.sseConnection) == null ? void 0 : _a3.close();
|
|
1401
1410
|
(_b3 = this.abortController) == null ? void 0 : _b3.abort();
|
|
1402
1411
|
(_c = this.onclose) == null ? void 0 : _c.call(this);
|
|
@@ -2173,7 +2182,7 @@ var DefaultMCPClient = class {
|
|
|
2173
2182
|
_meta
|
|
2174
2183
|
} of definitions.tools) {
|
|
2175
2184
|
const resolvedTitle = title != null ? title : annotations == null ? void 0 : annotations.title;
|
|
2176
|
-
if (schemas !== "automatic" && !(name3
|
|
2185
|
+
if (schemas !== "automatic" && !Object.prototype.hasOwnProperty.call(schemas, name3)) {
|
|
2177
2186
|
continue;
|
|
2178
2187
|
}
|
|
2179
2188
|
const self = this;
|