@ai-sdk/mcp 0.0.16 → 0.0.18

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,24 @@
1
1
  # @ai-sdk/mcp
2
2
 
3
+ ## 0.0.18
4
+
5
+ ### Patch Changes
6
+
7
+ - 783fa6c: chore: ensure consistent import handling and avoid import duplicates or cycles
8
+ - c327fb9: fix(mcp): prevent prototype pollution by using secureJsonParse
9
+ - Updated dependencies [783fa6c]
10
+ - @ai-sdk/provider-utils@3.0.25
11
+ - @ai-sdk/provider@2.0.3
12
+
13
+ ## 0.0.17
14
+
15
+ ### Patch Changes
16
+
17
+ - 0a00b9b: trigger release for all packages after provenance setup
18
+ - Updated dependencies [0a00b9b]
19
+ - @ai-sdk/provider@2.0.2
20
+ - @ai-sdk/provider-utils@3.0.24
21
+
3
22
  ## 0.0.16
4
23
 
5
24
  ### Patch Changes
package/dist/index.js CHANGED
@@ -39,7 +39,7 @@ __export(index_exports, {
39
39
  module.exports = __toCommonJS(index_exports);
40
40
 
41
41
  // src/tool/mcp-client.ts
42
- var import_provider_utils3 = require("@ai-sdk/provider-utils");
42
+ var import_provider_utils5 = require("@ai-sdk/provider-utils");
43
43
 
44
44
  // src/error/mcp-client-error.ts
45
45
  var import_provider = require("@ai-sdk/provider");
@@ -66,9 +66,10 @@ var MCPClientError = class extends (_b = import_provider.AISDKError, _a = symbol
66
66
  };
67
67
 
68
68
  // src/tool/mcp-sse-transport.ts
69
- var import_provider_utils = require("@ai-sdk/provider-utils");
69
+ var import_provider_utils3 = require("@ai-sdk/provider-utils");
70
70
 
71
71
  // src/tool/json-rpc-message.ts
72
+ var import_provider_utils = require("@ai-sdk/provider-utils");
72
73
  var import_v42 = require("zod/v4");
73
74
 
74
75
  // src/tool/types.ts
@@ -288,6 +289,9 @@ var JSONRPCMessageSchema = import_v42.z.union([
288
289
  JSONRPCResponseSchema,
289
290
  JSONRPCErrorSchema
290
291
  ]);
292
+ async function parseJSONRPCMessage(text) {
293
+ return JSONRPCMessageSchema.parse(await (0, import_provider_utils.parseJSON)({ text }));
294
+ }
291
295
 
292
296
  // src/version.ts
293
297
  var VERSION = typeof __PACKAGE_VERSION__ !== "undefined" ? __PACKAGE_VERSION__ : "0.0.0-test";
@@ -465,6 +469,7 @@ function checkResourceAllowed({
465
469
  }
466
470
 
467
471
  // src/tool/oauth.ts
472
+ var import_provider_utils2 = require("@ai-sdk/provider-utils");
468
473
  var UnauthorizedError = class extends Error {
469
474
  constructor(message = "Unauthorized") {
470
475
  super(message);
@@ -743,7 +748,9 @@ async function parseErrorResponse(input) {
743
748
  const statusCode = input instanceof Response ? input.status : void 0;
744
749
  const body = input instanceof Response ? await input.text() : input;
745
750
  try {
746
- const result = OAuthErrorResponseSchema.parse(JSON.parse(body));
751
+ const result = OAuthErrorResponseSchema.parse(
752
+ await (0, import_provider_utils2.parseJSON)({ text: body })
753
+ );
747
754
  const { error, error_description, error_uri } = result;
748
755
  const errorClass = OAUTH_ERRORS[error] || ServerError;
749
756
  return new errorClass({
@@ -1057,10 +1064,10 @@ var SseMCPTransport = class {
1057
1064
  headers["Authorization"] = `Bearer ${tokens.access_token}`;
1058
1065
  }
1059
1066
  }
1060
- return (0, import_provider_utils.withUserAgentSuffix)(
1067
+ return (0, import_provider_utils3.withUserAgentSuffix)(
1061
1068
  headers,
1062
1069
  `ai-sdk/${VERSION}`,
1063
- (0, import_provider_utils.getRuntimeEnvironmentUserAgent)()
1070
+ (0, import_provider_utils3.getRuntimeEnvironmentUserAgent)()
1064
1071
  );
1065
1072
  }
1066
1073
  async start() {
@@ -1108,7 +1115,7 @@ var SseMCPTransport = class {
1108
1115
  (_d = this.onerror) == null ? void 0 : _d.call(this, error);
1109
1116
  return reject(error);
1110
1117
  }
1111
- const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils.EventSourceParserStream());
1118
+ const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils3.EventSourceParserStream());
1112
1119
  const reader = stream.getReader();
1113
1120
  const processEvents = async () => {
1114
1121
  var _a4, _b4, _c2;
@@ -1136,9 +1143,7 @@ var SseMCPTransport = class {
1136
1143
  resolve();
1137
1144
  } else if (event === "message") {
1138
1145
  try {
1139
- const message = JSONRPCMessageSchema.parse(
1140
- JSON.parse(data)
1141
- );
1146
+ const message = await parseJSONRPCMessage(data);
1142
1147
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, message);
1143
1148
  } catch (error) {
1144
1149
  const e = new MCPClientError({
@@ -1235,7 +1240,7 @@ var SseMCPTransport = class {
1235
1240
  };
1236
1241
 
1237
1242
  // src/tool/mcp-http-transport.ts
1238
- var import_provider_utils2 = require("@ai-sdk/provider-utils");
1243
+ var import_provider_utils4 = require("@ai-sdk/provider-utils");
1239
1244
  var HttpMCPTransport = class {
1240
1245
  constructor({
1241
1246
  url,
@@ -1268,10 +1273,10 @@ var HttpMCPTransport = class {
1268
1273
  headers["Authorization"] = `Bearer ${tokens.access_token}`;
1269
1274
  }
1270
1275
  }
1271
- return (0, import_provider_utils2.withUserAgentSuffix)(
1276
+ return (0, import_provider_utils4.withUserAgentSuffix)(
1272
1277
  headers,
1273
1278
  `ai-sdk/${VERSION}`,
1274
- (0, import_provider_utils2.getRuntimeEnvironmentUserAgent)()
1279
+ (0, import_provider_utils4.getRuntimeEnvironmentUserAgent)()
1275
1280
  );
1276
1281
  }
1277
1282
  async start() {
@@ -1369,7 +1374,7 @@ var HttpMCPTransport = class {
1369
1374
  (_e = this.onerror) == null ? void 0 : _e.call(this, error2);
1370
1375
  throw error2;
1371
1376
  }
1372
- const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils2.EventSourceParserStream());
1377
+ const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils4.EventSourceParserStream());
1373
1378
  const reader = stream.getReader();
1374
1379
  const processEvents = async () => {
1375
1380
  var _a4, _b4, _c2;
@@ -1380,7 +1385,7 @@ var HttpMCPTransport = class {
1380
1385
  const { event, data } = value;
1381
1386
  if (event === "message") {
1382
1387
  try {
1383
- const msg = JSONRPCMessageSchema.parse(JSON.parse(data));
1388
+ const msg = await parseJSONRPCMessage(data);
1384
1389
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, msg);
1385
1390
  } catch (error2) {
1386
1391
  const e = new MCPClientError({
@@ -1491,7 +1496,7 @@ var HttpMCPTransport = class {
1491
1496
  (_d = this.onerror) == null ? void 0 : _d.call(this, error);
1492
1497
  return;
1493
1498
  }
1494
- const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils2.EventSourceParserStream());
1499
+ const stream = response.body.pipeThrough(new TextDecoderStream()).pipeThrough(new import_provider_utils4.EventSourceParserStream());
1495
1500
  const reader = stream.getReader();
1496
1501
  const processEvents = async () => {
1497
1502
  var _a4, _b4, _c2, _d2;
@@ -1505,7 +1510,7 @@ var HttpMCPTransport = class {
1505
1510
  }
1506
1511
  if (event === "message") {
1507
1512
  try {
1508
- const msg = JSONRPCMessageSchema.parse(JSON.parse(data));
1513
+ const msg = await parseJSONRPCMessage(data);
1509
1514
  (_a4 = this.onmessage) == null ? void 0 : _a4.call(this, msg);
1510
1515
  } catch (error) {
1511
1516
  const e = new MCPClientError({
@@ -1867,15 +1872,15 @@ var DefaultMCPClient = class {
1867
1872
  (_a4 = options == null ? void 0 : options.abortSignal) == null ? void 0 : _a4.throwIfAborted();
1868
1873
  return self.callTool({ name: name3, args, options });
1869
1874
  };
1870
- const toolWithExecute = schemas === "automatic" ? (0, import_provider_utils3.dynamicTool)({
1875
+ const toolWithExecute = schemas === "automatic" ? (0, import_provider_utils5.dynamicTool)({
1871
1876
  description,
1872
- inputSchema: (0, import_provider_utils3.jsonSchema)({
1877
+ inputSchema: (0, import_provider_utils5.jsonSchema)({
1873
1878
  ...inputSchema,
1874
1879
  properties: (_a3 = inputSchema.properties) != null ? _a3 : {},
1875
1880
  additionalProperties: false
1876
1881
  }),
1877
1882
  execute
1878
- }) : (0, import_provider_utils3.tool)({
1883
+ }) : (0, import_provider_utils5.tool)({
1879
1884
  description,
1880
1885
  inputSchema: schemas[name3].inputSchema,
1881
1886
  execute