@ai-sdk/mcp 1.0.36 → 1.0.38
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 +27 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +11 -6
- package/dist/index.mjs.map +1 -1
- package/dist/mcp-stdio/index.js +15 -10
- package/dist/mcp-stdio/index.js.map +1 -1
- package/dist/mcp-stdio/index.mjs +15 -10
- package/dist/mcp-stdio/index.mjs.map +1 -1
- package/package.json +6 -5
- package/src/tool/json-rpc-message.ts +7 -0
- package/src/tool/mcp-client.ts +29 -29
- package/src/tool/mcp-http-transport.ts +10 -6
- package/src/tool/mcp-sse-transport.ts +9 -9
- package/src/tool/mcp-stdio/create-child-process.ts +2 -2
- package/src/tool/mcp-stdio/mcp-stdio-transport.ts +17 -14
- package/src/tool/mcp-transport.ts +3 -3
- package/src/tool/mock-mcp-transport.ts +6 -6
- package/src/tool/oauth.ts +10 -8
- package/src/tool/types.ts +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @ai-sdk/mcp
|
|
2
2
|
|
|
3
|
+
## 1.0.38
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a727da4: chore: ensure consistent import handling and avoid import duplicates or cycles
|
|
8
|
+
- 5fee301: fix(mcp): prevent prototype pollution by using secureJsonParse
|
|
9
|
+
- Updated dependencies [a727da4]
|
|
10
|
+
- @ai-sdk/provider-utils@4.0.25
|
|
11
|
+
- @ai-sdk/provider@3.0.10
|
|
12
|
+
|
|
13
|
+
## 1.0.37
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- a7f3c72: trigger release for all packages after provenance setup
|
|
18
|
+
- Updated dependencies [a7f3c72]
|
|
19
|
+
- @ai-sdk/provider@3.0.9
|
|
20
|
+
- @ai-sdk/provider-utils@4.0.24
|
|
21
|
+
|
|
3
22
|
## 1.0.36
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
package/dist/index.js
CHANGED
|
@@ -40,7 +40,7 @@ __export(index_exports, {
|
|
|
40
40
|
module.exports = __toCommonJS(index_exports);
|
|
41
41
|
|
|
42
42
|
// src/tool/mcp-client.ts
|
|
43
|
-
var
|
|
43
|
+
var import_provider_utils5 = require("@ai-sdk/provider-utils");
|
|
44
44
|
|
|
45
45
|
// src/error/mcp-client-error.ts
|
|
46
46
|
var import_provider = require("@ai-sdk/provider");
|
|
@@ -67,9 +67,10 @@ var MCPClientError = class extends (_b = import_provider.AISDKError, _a = symbol
|
|
|
67
67
|
};
|
|
68
68
|
|
|
69
69
|
// src/tool/mcp-sse-transport.ts
|
|
70
|
-
var
|
|
70
|
+
var import_provider_utils3 = require("@ai-sdk/provider-utils");
|
|
71
71
|
|
|
72
72
|
// src/tool/json-rpc-message.ts
|
|
73
|
+
var import_provider_utils = require("@ai-sdk/provider-utils");
|
|
73
74
|
var import_v42 = require("zod/v4");
|
|
74
75
|
|
|
75
76
|
// src/tool/types.ts
|
|
@@ -310,6 +311,9 @@ var JSONRPCMessageSchema = import_v42.z.union([
|
|
|
310
311
|
JSONRPCResponseSchema,
|
|
311
312
|
JSONRPCErrorSchema
|
|
312
313
|
]);
|
|
314
|
+
async function parseJSONRPCMessage(text) {
|
|
315
|
+
return JSONRPCMessageSchema.parse(await (0, import_provider_utils.parseJSON)({ text }));
|
|
316
|
+
}
|
|
313
317
|
|
|
314
318
|
// src/version.ts
|
|
315
319
|
var VERSION = typeof __PACKAGE_VERSION__ !== "undefined" ? __PACKAGE_VERSION__ : "0.0.0-test";
|
|
@@ -494,6 +498,7 @@ function checkResourceAllowed({
|
|
|
494
498
|
}
|
|
495
499
|
|
|
496
500
|
// src/tool/oauth.ts
|
|
501
|
+
var import_provider_utils2 = require("@ai-sdk/provider-utils");
|
|
497
502
|
var UnauthorizedError = class extends Error {
|
|
498
503
|
constructor(message = "Unauthorized") {
|
|
499
504
|
super(message);
|
|
@@ -775,7 +780,9 @@ async function parseErrorResponse(input) {
|
|
|
775
780
|
const statusCode = input instanceof Response ? input.status : void 0;
|
|
776
781
|
const body = input instanceof Response ? await input.text() : input;
|
|
777
782
|
try {
|
|
778
|
-
const result = OAuthErrorResponseSchema.parse(
|
|
783
|
+
const result = OAuthErrorResponseSchema.parse(
|
|
784
|
+
await (0, import_provider_utils2.parseJSON)({ text: body })
|
|
785
|
+
);
|
|
779
786
|
const { error, error_description, error_uri } = result;
|
|
780
787
|
const errorClass = OAUTH_ERRORS[error] || ServerError;
|
|
781
788
|
return new errorClass({
|
|
@@ -1106,10 +1113,10 @@ var SseMCPTransport = class {
|
|
|
1106
1113
|
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
1107
1114
|
}
|
|
1108
1115
|
}
|
|
1109
|
-
return (0,
|
|
1116
|
+
return (0, import_provider_utils3.withUserAgentSuffix)(
|
|
1110
1117
|
headers,
|
|
1111
1118
|
`ai-sdk/${VERSION}`,
|
|
1112
|
-
(0,
|
|
1119
|
+
(0, import_provider_utils3.getRuntimeEnvironmentUserAgent)()
|
|
1113
1120
|
);
|
|
1114
1121
|
}
|
|
1115
1122
|
async start() {
|
|
@@ -1159,7 +1166,7 @@ var SseMCPTransport = class {
|
|
|
1159
1166
|
(_d = this.onerror) == null ? void 0 : _d.call(this, error);
|
|
1160
1167
|
return reject(error);
|
|
1161
1168
|
}
|
|
1162
|
-
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
1169
|
+
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils3.EventSourceParserStream());
|
|
1163
1170
|
const reader = stream.getReader();
|
|
1164
1171
|
const processEvents = async () => {
|
|
1165
1172
|
var _a4, _b4, _c2;
|
|
@@ -1187,9 +1194,7 @@ var SseMCPTransport = class {
|
|
|
1187
1194
|
resolve();
|
|
1188
1195
|
} else if (event === "message") {
|
|
1189
1196
|
try {
|
|
1190
|
-
const message =
|
|
1191
|
-
JSON.parse(data)
|
|
1192
|
-
);
|
|
1197
|
+
const message = await parseJSONRPCMessage(data);
|
|
1193
1198
|
(_a4 = this.onmessage) == null ? void 0 : _a4.call(this, message);
|
|
1194
1199
|
} catch (error) {
|
|
1195
1200
|
const e = new MCPClientError({
|
|
@@ -1288,7 +1293,7 @@ var SseMCPTransport = class {
|
|
|
1288
1293
|
};
|
|
1289
1294
|
|
|
1290
1295
|
// src/tool/mcp-http-transport.ts
|
|
1291
|
-
var
|
|
1296
|
+
var import_provider_utils4 = require("@ai-sdk/provider-utils");
|
|
1292
1297
|
var HttpMCPTransport = class {
|
|
1293
1298
|
constructor({
|
|
1294
1299
|
url,
|
|
@@ -1325,10 +1330,10 @@ var HttpMCPTransport = class {
|
|
|
1325
1330
|
headers["Authorization"] = `Bearer ${tokens.access_token}`;
|
|
1326
1331
|
}
|
|
1327
1332
|
}
|
|
1328
|
-
return (0,
|
|
1333
|
+
return (0, import_provider_utils4.withUserAgentSuffix)(
|
|
1329
1334
|
headers,
|
|
1330
1335
|
`ai-sdk/${VERSION}`,
|
|
1331
|
-
(0,
|
|
1336
|
+
(0, import_provider_utils4.getRuntimeEnvironmentUserAgent)()
|
|
1332
1337
|
);
|
|
1333
1338
|
}
|
|
1334
1339
|
async start() {
|
|
@@ -1433,7 +1438,7 @@ var HttpMCPTransport = class {
|
|
|
1433
1438
|
(_e = this.onerror) == null ? void 0 : _e.call(this, error2);
|
|
1434
1439
|
throw error2;
|
|
1435
1440
|
}
|
|
1436
|
-
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
1441
|
+
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils4.EventSourceParserStream());
|
|
1437
1442
|
const reader = stream.getReader();
|
|
1438
1443
|
const processEvents = async () => {
|
|
1439
1444
|
var _a4, _b4, _c2;
|
|
@@ -1444,7 +1449,7 @@ var HttpMCPTransport = class {
|
|
|
1444
1449
|
const { event, data } = value;
|
|
1445
1450
|
if (event === "message") {
|
|
1446
1451
|
try {
|
|
1447
|
-
const msg =
|
|
1452
|
+
const msg = await parseJSONRPCMessage(data);
|
|
1448
1453
|
(_a4 = this.onmessage) == null ? void 0 : _a4.call(this, msg);
|
|
1449
1454
|
} catch (error2) {
|
|
1450
1455
|
const e = new MCPClientError({
|
|
@@ -1557,7 +1562,7 @@ var HttpMCPTransport = class {
|
|
|
1557
1562
|
(_d = this.onerror) == null ? void 0 : _d.call(this, error);
|
|
1558
1563
|
return;
|
|
1559
1564
|
}
|
|
1560
|
-
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new
|
|
1565
|
+
const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils4.EventSourceParserStream());
|
|
1561
1566
|
const reader = stream.getReader();
|
|
1562
1567
|
const processEvents = async () => {
|
|
1563
1568
|
var _a4, _b4, _c2, _d2;
|
|
@@ -1571,7 +1576,7 @@ var HttpMCPTransport = class {
|
|
|
1571
1576
|
}
|
|
1572
1577
|
if (event === "message") {
|
|
1573
1578
|
try {
|
|
1574
|
-
const msg =
|
|
1579
|
+
const msg = await parseJSONRPCMessage(data);
|
|
1575
1580
|
(_a4 = this.onmessage) == null ? void 0 : _a4.call(this, msg);
|
|
1576
1581
|
} catch (error) {
|
|
1577
1582
|
const e = new MCPClientError({
|
|
@@ -1982,17 +1987,17 @@ var DefaultMCPClient = class {
|
|
|
1982
1987
|
}
|
|
1983
1988
|
return result;
|
|
1984
1989
|
};
|
|
1985
|
-
const toolWithExecute = schemas === "automatic" ? (0,
|
|
1990
|
+
const toolWithExecute = schemas === "automatic" ? (0, import_provider_utils5.dynamicTool)({
|
|
1986
1991
|
description,
|
|
1987
1992
|
title: resolvedTitle,
|
|
1988
|
-
inputSchema: (0,
|
|
1993
|
+
inputSchema: (0, import_provider_utils5.jsonSchema)({
|
|
1989
1994
|
...inputSchema,
|
|
1990
1995
|
properties: (_b3 = inputSchema.properties) != null ? _b3 : {},
|
|
1991
1996
|
additionalProperties: false
|
|
1992
1997
|
}),
|
|
1993
1998
|
execute,
|
|
1994
1999
|
toModelOutput: mcpToModelOutput
|
|
1995
|
-
}) : (0,
|
|
2000
|
+
}) : (0, import_provider_utils5.tool)({
|
|
1996
2001
|
description,
|
|
1997
2002
|
title: resolvedTitle,
|
|
1998
2003
|
inputSchema: schemas[name3].inputSchema,
|
|
@@ -2009,9 +2014,9 @@ var DefaultMCPClient = class {
|
|
|
2009
2014
|
*/
|
|
2010
2015
|
async extractStructuredContent(result, outputSchema, toolName) {
|
|
2011
2016
|
if ("structuredContent" in result && result.structuredContent != null) {
|
|
2012
|
-
const validationResult = await (0,
|
|
2017
|
+
const validationResult = await (0, import_provider_utils5.safeValidateTypes)({
|
|
2013
2018
|
value: result.structuredContent,
|
|
2014
|
-
schema: (0,
|
|
2019
|
+
schema: (0, import_provider_utils5.asSchema)(outputSchema)
|
|
2015
2020
|
});
|
|
2016
2021
|
if (!validationResult.success) {
|
|
2017
2022
|
throw new MCPClientError({
|
|
@@ -2024,7 +2029,7 @@ var DefaultMCPClient = class {
|
|
|
2024
2029
|
if ("content" in result && Array.isArray(result.content)) {
|
|
2025
2030
|
const textContent = result.content.find((c) => c.type === "text");
|
|
2026
2031
|
if (textContent && "text" in textContent) {
|
|
2027
|
-
const parseResult = await (0,
|
|
2032
|
+
const parseResult = await (0, import_provider_utils5.safeParseJSON)({
|
|
2028
2033
|
text: textContent.text,
|
|
2029
2034
|
schema: outputSchema
|
|
2030
2035
|
});
|