mcp-use 1.7.0-canary.1 → 1.7.0-canary.3

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.
Files changed (52) hide show
  1. package/dist/.tsbuildinfo +1 -1
  2. package/dist/{chunk-PE7UMCVO.js → chunk-3R5PDYIN.js} +27 -1
  3. package/dist/{chunk-XN2PU4PS.js → chunk-BBEY6HHN.js} +59 -7
  4. package/dist/{chunk-YURRUCIM.js → chunk-CPG2WZUL.js} +9 -11
  5. package/dist/{chunk-R5DJJ4IV.js → chunk-F4UHAA5L.js} +3 -91
  6. package/dist/chunk-MTHLLDCX.js +97 -0
  7. package/dist/{chunk-QSLJXXMG.js → chunk-PSO6HYXH.js} +4 -4
  8. package/dist/{chunk-GVVPUU5K.js → chunk-S6K5QZBJ.js} +739 -29
  9. package/dist/{display-YIYC6WJE.js → display-A5IEINAP.js} +79 -17
  10. package/dist/index.cjs +952 -107
  11. package/dist/index.js +6 -5
  12. package/dist/{langfuse-C4HKZ3NL.js → langfuse-N5Y5BSXK.js} +1 -1
  13. package/dist/{oauth-CNGBFOZW.js → oauth-U4NNKN4B.js} +2 -1
  14. package/dist/src/agents/display.d.ts.map +1 -1
  15. package/dist/src/agents/index.cjs +854 -78
  16. package/dist/src/agents/index.js +3 -2
  17. package/dist/src/auth/index.cjs +30 -5
  18. package/dist/src/auth/index.js +1 -1
  19. package/dist/src/browser.cjs +888 -90
  20. package/dist/src/browser.js +5 -4
  21. package/dist/src/connectors/base.d.ts +53 -391
  22. package/dist/src/connectors/base.d.ts.map +1 -1
  23. package/dist/src/managers/server_manager.d.ts.map +1 -1
  24. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts +2 -2
  25. package/dist/src/managers/tools/acquire_active_mcp_server.d.ts.map +1 -1
  26. package/dist/src/managers/tools/add_server_from_config.d.ts +1 -7
  27. package/dist/src/managers/tools/add_server_from_config.d.ts.map +1 -1
  28. package/dist/src/managers/tools/connect_mcp_server.d.ts +2 -10
  29. package/dist/src/managers/tools/connect_mcp_server.d.ts.map +1 -1
  30. package/dist/src/managers/tools/list_mcp_servers.d.ts +2 -2
  31. package/dist/src/managers/tools/list_mcp_servers.d.ts.map +1 -1
  32. package/dist/src/managers/tools/release_mcp_server_connection.d.ts +2 -2
  33. package/dist/src/managers/tools/release_mcp_server_connection.d.ts.map +1 -1
  34. package/dist/src/observability/langfuse.d.ts +4 -0
  35. package/dist/src/observability/langfuse.d.ts.map +1 -1
  36. package/dist/src/react/McpUseProvider.d.ts.map +1 -1
  37. package/dist/src/react/index.cjs +86 -12
  38. package/dist/src/react/index.js +4 -3
  39. package/dist/src/server/connect-adapter.d.ts.map +1 -1
  40. package/dist/src/server/index.cjs +28 -17
  41. package/dist/src/server/index.js +38 -25
  42. package/dist/src/server/mcp-server.d.ts.map +1 -1
  43. package/dist/src/utils/json-schema-to-zod/JSONSchemaToZod.d.ts +270 -0
  44. package/dist/src/utils/json-schema-to-zod/JSONSchemaToZod.d.ts.map +1 -0
  45. package/dist/src/utils/json-schema-to-zod/Type.d.ts +24 -0
  46. package/dist/src/utils/json-schema-to-zod/Type.d.ts.map +1 -0
  47. package/dist/src/utils/json-schema-to-zod/index.d.ts +3 -0
  48. package/dist/src/utils/json-schema-to-zod/index.d.ts.map +1 -0
  49. package/dist/src/utils/url-sanitize.d.ts +17 -0
  50. package/dist/src/utils/url-sanitize.d.ts.map +1 -0
  51. package/dist/tsup.config.d.ts.map +1 -1
  52. package/package.json +20 -37
@@ -335,13 +335,13 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
335
335
  metadataProvider;
336
336
  tagsProvider;
337
337
  verbose;
338
- constructor(config3, agentId2, metadata2, metadataProvider2, tagsProvider2) {
339
- super(config3);
338
+ constructor(config2, agentId2, metadata2, metadataProvider2, tagsProvider2) {
339
+ super(config2);
340
340
  this.agentId = agentId2;
341
341
  this.metadata = metadata2;
342
342
  this.metadataProvider = metadataProvider2;
343
343
  this.tagsProvider = tagsProvider2;
344
- this.verbose = config3?.verbose ?? false;
344
+ this.verbose = config2?.verbose ?? false;
345
345
  }
346
346
  // Override to add custom metadata to traces
347
347
  async handleChainStart(chain, inputs, runId, parentRunId, tags, metadata2, name, kwargs) {
@@ -466,7 +466,7 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
466
466
  }
467
467
  const initialMetadata = metadata || (metadataProvider ? metadataProvider() : {});
468
468
  const initialTags = tagsProvider ? tagsProvider() : [];
469
- const config2 = {
469
+ const config = {
470
470
  publicKey: process.env.LANGFUSE_PUBLIC_KEY,
471
471
  secretKey: process.env.LANGFUSE_SECRET_KEY,
472
472
  baseUrl: process.env.LANGFUSE_HOST || process.env.LANGFUSE_BASEURL || "https://cloud.langfuse.com",
@@ -491,17 +491,17 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
491
491
  "Langfuse handler config:",
492
492
  JSON.stringify(
493
493
  {
494
- traceName: config2.traceName,
495
- sessionId: config2.sessionId,
496
- userId: config2.userId,
497
- tags: config2.tags
494
+ traceName: config.traceName,
495
+ sessionId: config.sessionId,
496
+ userId: config.userId,
497
+ tags: config.tags
498
498
  },
499
499
  null,
500
500
  2
501
501
  )
502
502
  );
503
503
  langfuseState.handler = new LoggingCallbackHandler(
504
- config2,
504
+ config,
505
505
  agentId,
506
506
  metadata,
507
507
  metadataProvider,
@@ -528,13 +528,11 @@ async function initializeLangfuse(agentId, metadata, metadataProvider, tagsProvi
528
528
  logger.debug(`Langfuse initialization error: ${error}`);
529
529
  }
530
530
  }
531
- var import_dotenv, langfuseDisabled, langfuseState, langfuseHandler, langfuseClient, langfuseInitPromise;
531
+ var langfuseDisabled, langfuseState, langfuseHandler, langfuseClient, langfuseInitPromise;
532
532
  var init_langfuse = __esm({
533
533
  "src/observability/langfuse.ts"() {
534
534
  "use strict";
535
- import_dotenv = require("dotenv");
536
535
  init_logging();
537
- (0, import_dotenv.config)();
538
536
  langfuseDisabled = process.env.MCP_USE_LANGFUSE?.toLowerCase() === "false";
539
537
  langfuseState = {
540
538
  handler: null,
@@ -573,8 +571,24 @@ __export(display_exports, {
573
571
  renderContent: () => renderContent,
574
572
  unwrapToolInput: () => unwrapToolInput
575
573
  });
574
+ function highlightCode(content, language) {
575
+ if (!highlight) {
576
+ return content;
577
+ }
578
+ try {
579
+ return highlight(content, {
580
+ language: language ?? "javascript",
581
+ ignoreIllegals: true
582
+ });
583
+ } catch {
584
+ return content;
585
+ }
586
+ }
576
587
  function stripAnsi(str) {
577
- return (0, import_strip_ansi.default)(str);
588
+ if (stripVTControlCharacters) {
589
+ return stripVTControlCharacters(str);
590
+ }
591
+ return str.replace(/\x1b\[[0-9;]*m/g, "");
578
592
  }
579
593
  function wrapAnsiLine(line, maxWidth) {
580
594
  const stripped = stripAnsi(line);
@@ -614,28 +628,28 @@ function printBox(content, title, language, bgColor = false) {
614
628
  let displayContent = content;
615
629
  if (language) {
616
630
  try {
617
- displayContent = (0, import_cli_highlight.highlight)(content, { language, ignoreIllegals: true });
631
+ displayContent = highlightCode(content, language);
618
632
  } catch {
619
633
  }
620
634
  }
621
635
  const lines = displayContent.split("\n").flatMap((line) => wrapAnsiLine(line, width - 4));
622
- console.log(import_chalk.default.gray("\u250C" + "\u2500".repeat(width - 2) + "\u2510"));
636
+ console.log(chalkHelper.gray("\u250C" + "\u2500".repeat(width - 2) + "\u2510"));
623
637
  if (title) {
624
638
  const stripped = stripAnsi(title);
625
639
  const lineText = `${title} `;
626
640
  const padding = Math.max(0, width - 4 - stripped.length - 2);
627
641
  console.log(
628
- import_chalk.default.gray("\u2502 ") + import_chalk.default.bold.white(lineText) + " ".repeat(padding) + import_chalk.default.gray(" \u2502")
642
+ chalkHelper.gray("\u2502 ") + chalkHelper.bold.white(lineText) + " ".repeat(padding) + chalkHelper.gray(" \u2502")
629
643
  );
630
- console.log(import_chalk.default.gray("\u251C" + "\u2500".repeat(width - 2) + "\u2524"));
644
+ console.log(chalkHelper.gray("\u251C" + "\u2500".repeat(width - 2) + "\u2524"));
631
645
  }
632
646
  lines.forEach((line) => {
633
647
  const stripped = stripAnsi(line);
634
648
  const padding = Math.max(0, width - 4 - stripped.length);
635
- const finalLine = bgColor ? import_chalk.default.bgGray(line + " ".repeat(padding)) : line + " ".repeat(padding);
636
- console.log(import_chalk.default.gray("\u2502 ") + finalLine + import_chalk.default.gray(" \u2502"));
649
+ const finalLine = bgColor ? chalkHelper.bgGray(line + " ".repeat(padding)) : line + " ".repeat(padding);
650
+ console.log(chalkHelper.gray("\u2502 ") + finalLine + chalkHelper.gray(" \u2502"));
637
651
  });
638
- console.log(import_chalk.default.gray("\u2514" + "\u2500".repeat(width - 2) + "\u2518"));
652
+ console.log(chalkHelper.gray("\u2514" + "\u2500".repeat(width - 2) + "\u2518"));
639
653
  }
640
654
  function extractCodeFromToolInput(input) {
641
655
  if (typeof input === "object" && input !== null && "code" in input) {
@@ -774,7 +788,7 @@ ${noResultsMsg}`;
774
788
  const isLastServer = i === servers.length - 1;
775
789
  const serverPrefix = isLastServer ? "\u2514\u2500" : "\u251C\u2500";
776
790
  lines.push(
777
- `${serverPrefix} ${import_chalk.default.cyan(server)} (${serverTools.length} tools)`
791
+ `${serverPrefix} ${chalkHelper.cyan(server)} (${serverTools.length} tools)`
778
792
  );
779
793
  for (let j = 0; j < serverTools.length; j++) {
780
794
  const tool = serverTools[j];
@@ -806,7 +820,7 @@ ${noResultsMsg}`;
806
820
  wrappedLines.push(currentLine.trimEnd());
807
821
  }
808
822
  for (const descLine of wrappedLines) {
809
- lines.push(`${descriptionIndent}${import_chalk.default.dim(descLine)}`);
823
+ lines.push(`${descriptionIndent}${chalkHelper.dim(descLine)}`);
810
824
  }
811
825
  }
812
826
  }
@@ -833,7 +847,7 @@ function handleToolEnd(event) {
833
847
  const timeMs = execResult2.execution_time ? Math.round(execResult2.execution_time * 1e3) : 0;
834
848
  const timeStr = `${timeMs}ms`;
835
849
  const isError2 = execResult2.error !== null && execResult2.error !== void 0 && execResult2.error !== "";
836
- const statusText = isError2 ? import_chalk.default.red("error") : import_chalk.default.green("success");
850
+ const statusText = isError2 ? chalkHelper.red("error") : chalkHelper.green("success");
837
851
  const title2 = `${toolName} - ${statusText} - ${timeStr}`;
838
852
  if (execResult2.result !== null && execResult2.result !== void 0) {
839
853
  const resultStr = renderContent(execResult2.result);
@@ -846,7 +860,12 @@ function handleToolEnd(event) {
846
860
  printBox(execResult2.logs.join("\n"), `Logs`, void 0, false);
847
861
  }
848
862
  if (execResult2.error) {
849
- printBox(execResult2.error, import_chalk.default.red("Error"), void 0, false);
863
+ printBox(
864
+ execResult2.error,
865
+ chalkHelper.red("Error"),
866
+ void 0,
867
+ false
868
+ );
850
869
  }
851
870
  return;
852
871
  }
@@ -872,7 +891,7 @@ function handleToolEnd(event) {
872
891
  const contentWithMeta = actualContent;
873
892
  const meta = contentWithMeta.meta;
874
893
  const treeStr = formatSearchToolsAsTree(results, meta, query);
875
- const statusText = status === "success" ? import_chalk.default.green("Success") : import_chalk.default.red("Error");
894
+ const statusText = status === "success" ? chalk.green("Success") : chalk.red("Error");
876
895
  const title2 = `${statusText}: ${toolName} - Result`;
877
896
  printBox(treeStr, title2, void 0, false);
878
897
  return;
@@ -883,7 +902,7 @@ function handleToolEnd(event) {
883
902
  void 0,
884
903
  query
885
904
  );
886
- const statusText = status === "success" ? import_chalk.default.green("Success") : import_chalk.default.red("Error");
905
+ const statusText = status === "success" ? chalk.green("Success") : chalk.red("Error");
887
906
  const title2 = `${statusText}: ${toolName} - Result`;
888
907
  printBox(treeStr, title2, void 0, false);
889
908
  return;
@@ -902,7 +921,7 @@ function handleToolEnd(event) {
902
921
  }
903
922
  const contentStr = renderContent(displayContent);
904
923
  const language2 = typeof displayContent === "object" ? "json" : void 0;
905
- const statusLabel = status === "success" ? import_chalk.default.green("Success") : isError ? import_chalk.default.red("Error") : "Result";
924
+ const statusLabel = status === "success" ? chalkHelper.green("Success") : isError ? chalkHelper.red("Error") : "Result";
906
925
  const title = `${statusLabel}: ${toolName} - Result`;
907
926
  printBox(contentStr, title, language2, false);
908
927
  return;
@@ -920,7 +939,7 @@ function handleToolEnd(event) {
920
939
  printBox(execResult.logs.join("\n"), `Logs`, void 0, false);
921
940
  }
922
941
  if (execResult.error) {
923
- printBox(execResult.error, import_chalk.default.red("Error"), void 0, false);
942
+ printBox(execResult.error, chalkHelper.red("Error"), void 0, false);
924
943
  }
925
944
  return;
926
945
  }
@@ -960,14 +979,55 @@ async function* prettyStreamEvents(streamEventsGenerator) {
960
979
  }
961
980
  return finalResponse;
962
981
  }
963
- var import_chalk, import_cli_highlight, import_strip_ansi, TERMINAL_WIDTH;
982
+ var chalk, highlight, stripVTControlCharacters, displayPackagesWarned, isNode, TERMINAL_WIDTH, chalkHelper;
964
983
  var init_display = __esm({
965
984
  "src/agents/display.ts"() {
966
985
  "use strict";
967
- import_chalk = __toESM(require("chalk"), 1);
968
- import_cli_highlight = require("cli-highlight");
969
- import_strip_ansi = __toESM(require("strip-ansi"), 1);
986
+ chalk = null;
987
+ highlight = null;
988
+ stripVTControlCharacters = null;
989
+ displayPackagesWarned = false;
990
+ isNode = typeof process !== "undefined" && process.versions?.node;
991
+ (async () => {
992
+ if (isNode) {
993
+ try {
994
+ const utilModule = await import("util");
995
+ stripVTControlCharacters = utilModule.stripVTControlCharacters;
996
+ } catch {
997
+ }
998
+ }
999
+ try {
1000
+ const chalkModule = await import("chalk");
1001
+ chalk = chalkModule.default;
1002
+ } catch {
1003
+ }
1004
+ try {
1005
+ const cliHighlightModule = await import("cli-highlight");
1006
+ highlight = cliHighlightModule.highlight;
1007
+ } catch {
1008
+ }
1009
+ if (isNode && (!chalk || !highlight)) {
1010
+ if (!displayPackagesWarned) {
1011
+ displayPackagesWarned = true;
1012
+ console.warn(
1013
+ "\n\u2728 For enhanced console output with colors and syntax highlighting, install:\n\n npm install chalk cli-highlight\n # or\n pnpm add chalk cli-highlight\n"
1014
+ );
1015
+ }
1016
+ }
1017
+ })();
970
1018
  TERMINAL_WIDTH = process.stdout.columns || 120;
1019
+ chalkHelper = {
1020
+ gray: /* @__PURE__ */ __name((str) => chalk?.gray(str) ?? str, "gray"),
1021
+ bold: {
1022
+ white: /* @__PURE__ */ __name((str) => chalk?.bold?.white(str) ?? str, "white")
1023
+ },
1024
+ bgGray: /* @__PURE__ */ __name((str) => chalk?.bgGray(str) ?? str, "bgGray"),
1025
+ cyan: /* @__PURE__ */ __name((str) => chalk?.cyan(str) ?? str, "cyan"),
1026
+ dim: /* @__PURE__ */ __name((str) => chalk?.dim(str) ?? str, "dim"),
1027
+ red: /* @__PURE__ */ __name((str) => chalk?.red(str) ?? str, "red"),
1028
+ green: /* @__PURE__ */ __name((str) => chalk?.green(str) ?? str, "green")
1029
+ };
1030
+ __name(highlightCode, "highlightCode");
971
1031
  __name(stripAnsi, "stripAnsi");
972
1032
  __name(wrapAnsiLine, "wrapAnsiLine");
973
1033
  __name(printBox, "printBox");
@@ -1108,12 +1168,699 @@ var BaseAgent = class {
1108
1168
 
1109
1169
  // src/agents/mcp_agent.ts
1110
1170
  var import_langchain2 = require("langchain");
1111
- var import_zod_to_json_schema2 = require("zod-to-json-schema");
1171
+ var import_zod9 = require("zod");
1172
+
1173
+ // src/utils/json-schema-to-zod/JSONSchemaToZod.ts
1174
+ var import_zod = require("zod");
1175
+ var JSONSchemaToZod = class {
1176
+ static {
1177
+ __name(this, "JSONSchemaToZod");
1178
+ }
1179
+ /**
1180
+ * Converts a JSON schema to a Zod schema.
1181
+ *
1182
+ * @param {JSONSchema} schema - The JSON schema.
1183
+ * @returns {ZodSchema} - The Zod schema.
1184
+ */
1185
+ static convert(schema) {
1186
+ return this.parseSchema(schema);
1187
+ }
1188
+ /**
1189
+ * Checks if data matches a condition schema.
1190
+ *
1191
+ * @param {JSONValue} data - The data to check.
1192
+ * @param {JSONSchema} condition - The condition schema.
1193
+ * @returns {boolean} - Whether the data matches the condition.
1194
+ */
1195
+ static matchesCondition(data, condition) {
1196
+ if (!condition.properties) {
1197
+ return true;
1198
+ }
1199
+ if (typeof data !== "object" || data === null || Array.isArray(data)) {
1200
+ return false;
1201
+ }
1202
+ const objectData = data;
1203
+ for (const [key, propCondition] of Object.entries(condition.properties)) {
1204
+ if (!(key in objectData)) {
1205
+ if ("const" in propCondition) {
1206
+ return false;
1207
+ }
1208
+ continue;
1209
+ }
1210
+ const value = objectData[key];
1211
+ if ("const" in propCondition && value !== propCondition["const"]) {
1212
+ return false;
1213
+ }
1214
+ if ("minimum" in propCondition && typeof value === "number" && value < propCondition["minimum"]) {
1215
+ return false;
1216
+ }
1217
+ if ("maximum" in propCondition && typeof value === "number" && value > propCondition["maximum"]) {
1218
+ return false;
1219
+ }
1220
+ }
1221
+ return true;
1222
+ }
1223
+ /**
1224
+ * Validates data against a conditional schema and adds issues to context if validation fails.
1225
+ *
1226
+ * @param {JSONValue} data - The data to validate.
1227
+ * @param {JSONSchema} schema - The conditional schema.
1228
+ * @param {z.RefinementCtx} ctx - The Zod refinement context.
1229
+ */
1230
+ static validateConditionalSchema(data, schema, ctx) {
1231
+ this.validateRequiredProperties(data, schema, ctx);
1232
+ this.validatePropertyPatterns(data, schema, ctx);
1233
+ this.validateNestedConditions(data, schema, ctx);
1234
+ }
1235
+ /**
1236
+ * Validates that all required properties are present in the data.
1237
+ *
1238
+ * @param {JSONValue} data - The data to validate.
1239
+ * @param {JSONSchema} schema - The schema containing required properties.
1240
+ * @param {z.RefinementCtx} ctx - The Zod refinement context.
1241
+ */
1242
+ static validateRequiredProperties(data, schema, ctx) {
1243
+ if (!schema.required) {
1244
+ return;
1245
+ }
1246
+ if (typeof data !== "object" || data === null) {
1247
+ for (const requiredProp of schema.required) {
1248
+ ctx.addIssue({
1249
+ code: import_zod.z.ZodIssueCode.custom,
1250
+ message: `Required property '${requiredProp}' is missing`,
1251
+ path: [requiredProp]
1252
+ });
1253
+ }
1254
+ return;
1255
+ }
1256
+ for (const requiredProp of schema.required) {
1257
+ if (!(requiredProp in data)) {
1258
+ ctx.addIssue({
1259
+ code: import_zod.z.ZodIssueCode.custom,
1260
+ message: `Required property '${requiredProp}' is missing`,
1261
+ path: [requiredProp]
1262
+ });
1263
+ }
1264
+ }
1265
+ }
1266
+ /**
1267
+ * Validates property patterns for string properties.
1268
+ *
1269
+ * @param {JSONValue} data - The data to validate.
1270
+ * @param {JSONSchema} schema - The schema containing property patterns.
1271
+ * @param {z.RefinementCtx} ctx - The Zod refinement context.
1272
+ */
1273
+ static validatePropertyPatterns(data, schema, ctx) {
1274
+ if (!schema.properties) {
1275
+ return;
1276
+ }
1277
+ if (typeof data !== "object" || data === null) {
1278
+ return;
1279
+ }
1280
+ if (Array.isArray(data)) {
1281
+ return;
1282
+ }
1283
+ const objectData = data;
1284
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
1285
+ if (!(key in objectData)) {
1286
+ continue;
1287
+ }
1288
+ const value = objectData[key];
1289
+ if (propSchema["pattern"] && typeof value === "string") {
1290
+ const regex = new RegExp(propSchema["pattern"]);
1291
+ if (!regex.test(value)) {
1292
+ ctx.addIssue({
1293
+ code: import_zod.z.ZodIssueCode.custom,
1294
+ message: `String '${value}' does not match pattern '${propSchema["pattern"]}'`,
1295
+ path: [key]
1296
+ });
1297
+ }
1298
+ }
1299
+ }
1300
+ }
1301
+ /**
1302
+ * Validates nested if-then-else conditions.
1303
+ *
1304
+ * @param {JSONValue} data - The data to validate.
1305
+ * @param {JSONSchema} schema - The schema containing if-then-else conditions.
1306
+ * @param {z.RefinementCtx} ctx - The Zod refinement context.
1307
+ */
1308
+ static validateNestedConditions(data, schema, ctx) {
1309
+ if (!schema["if"] || !schema["then"]) {
1310
+ return;
1311
+ }
1312
+ const matchesIf = this.matchesCondition(data, schema["if"]);
1313
+ if (matchesIf) {
1314
+ this.validateConditionalSchema(data, schema["then"], ctx);
1315
+ } else if (schema["else"]) {
1316
+ this.validateConditionalSchema(data, schema["else"], ctx);
1317
+ }
1318
+ }
1319
+ /**
1320
+ * Parses a JSON schema and returns the corresponding Zod schema.
1321
+ * This is the main entry point for schema conversion.
1322
+ *
1323
+ * @param {JSONSchema} schema - The JSON schema.
1324
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1325
+ */
1326
+ static parseSchema(schema) {
1327
+ if (Array.isArray(schema.type)) {
1328
+ return this.handleTypeArray(schema);
1329
+ }
1330
+ if (schema.oneOf || schema.anyOf || schema.allOf) {
1331
+ return this.parseCombinator(schema);
1332
+ }
1333
+ if (schema["if"] && schema["then"]) {
1334
+ return this.parseObject(schema);
1335
+ }
1336
+ if (schema.properties && (!schema.type || schema.type === "object")) {
1337
+ return this.parseObject(schema);
1338
+ }
1339
+ return this.handleSingleType(schema);
1340
+ }
1341
+ /**
1342
+ * Handles schemas with an array of types.
1343
+ *
1344
+ * @param {JSONSchema} schema - The JSON schema with type array.
1345
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1346
+ */
1347
+ static handleTypeArray(schema) {
1348
+ if (!Array.isArray(schema.type)) {
1349
+ throw new Error("Expected schema.type to be an array");
1350
+ }
1351
+ if (schema.type.includes("null")) {
1352
+ return this.handleNullableType(schema);
1353
+ }
1354
+ return this.createUnionFromTypes(schema.type, schema);
1355
+ }
1356
+ /**
1357
+ * Handles nullable types by creating a nullable schema.
1358
+ *
1359
+ * @param {JSONSchema} schema - The JSON schema with nullable type.
1360
+ * @returns {ZodTypeAny} - The nullable Zod schema.
1361
+ */
1362
+ static handleNullableType(schema) {
1363
+ if (!Array.isArray(schema.type)) {
1364
+ throw new Error("Expected schema.type to be an array");
1365
+ }
1366
+ const nonNullSchema = { ...schema };
1367
+ nonNullSchema.type = schema.type.filter((t) => t !== "null");
1368
+ if (nonNullSchema.type.length === 1) {
1369
+ const singleTypeSchema = this.handleSingleType({
1370
+ ...schema,
1371
+ type: nonNullSchema.type[0]
1372
+ });
1373
+ return singleTypeSchema.nullable();
1374
+ }
1375
+ const unionSchema = this.parseSchema(nonNullSchema);
1376
+ return unionSchema.nullable();
1377
+ }
1378
+ /**
1379
+ * Creates a union type from an array of types.
1380
+ *
1381
+ * @param {string[]} types - Array of type strings.
1382
+ * @param {JSONSchema} baseSchema - The base schema to apply to each type.
1383
+ * @returns {ZodTypeAny} - The union Zod schema.
1384
+ */
1385
+ static createUnionFromTypes(types, baseSchema) {
1386
+ const schemas = types.map((type) => {
1387
+ const singleTypeSchema = { ...baseSchema, type };
1388
+ return this.parseSchema(singleTypeSchema);
1389
+ });
1390
+ return import_zod.z.union(schemas);
1391
+ }
1392
+ /**
1393
+ * Handles schemas with a single type.
1394
+ *
1395
+ * @param {JSONSchema} schema - The JSON schema with single type.
1396
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1397
+ */
1398
+ static handleSingleType(schema) {
1399
+ if (schema.type === void 0) {
1400
+ if (schema.oneOf || schema.anyOf || schema.allOf) {
1401
+ return this.parseCombinator(schema);
1402
+ }
1403
+ if (schema.properties) {
1404
+ return this.parseObject(schema);
1405
+ }
1406
+ return import_zod.z.any();
1407
+ }
1408
+ switch (schema.type) {
1409
+ case "string":
1410
+ return this.parseString(schema);
1411
+ case "number":
1412
+ case "integer":
1413
+ return this.parseNumberSchema(schema);
1414
+ case "boolean":
1415
+ return import_zod.z.boolean();
1416
+ case "array":
1417
+ return this.parseArray(schema);
1418
+ case "object":
1419
+ return this.parseObject(schema);
1420
+ default:
1421
+ throw new Error("Unsupported schema type");
1422
+ }
1423
+ }
1424
+ /**
1425
+ * Parses a number schema.
1426
+ *
1427
+ * @param {JSONSchema} schema - The JSON schema for a number.
1428
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1429
+ */
1430
+ static parseNumberSchema(schema) {
1431
+ const numberSchema = import_zod.z.number();
1432
+ let result = numberSchema;
1433
+ result = this.applyNumberBounds(numberSchema, schema);
1434
+ result = this.applyNumberMultipleOf(numberSchema, schema);
1435
+ result = this.applyNumberEnum(numberSchema, schema);
1436
+ result = this.applyIntegerConstraint(numberSchema, schema);
1437
+ return result;
1438
+ }
1439
+ /**
1440
+ * Applies bounds validation to a number schema.
1441
+ *
1442
+ * @param {z.ZodNumber} numberSchema - The base number schema.
1443
+ * @param {JSONSchema} schema - The JSON schema with bounds.
1444
+ * @returns {z.ZodNumber} - The updated schema with bounds validation.
1445
+ */
1446
+ static applyNumberBounds(numberSchema, schema) {
1447
+ let result = numberSchema;
1448
+ if (schema["minimum"] !== void 0) {
1449
+ result = schema["exclusiveMinimum"] ? result.gt(schema["minimum"]) : result.gte(schema["minimum"]);
1450
+ }
1451
+ if (schema["maximum"] !== void 0) {
1452
+ result = schema["exclusiveMaximum"] ? result.lt(schema["maximum"]) : result.lte(schema["maximum"]);
1453
+ }
1454
+ return result;
1455
+ }
1456
+ /**
1457
+ * Applies multipleOf validation to a number schema.
1458
+ *
1459
+ * @param {z.ZodNumber} numberSchema - The base number schema.
1460
+ * @param {JSONSchema} schema - The JSON schema with multipleOf.
1461
+ * @returns {z.ZodNumber} - The updated schema with multipleOf validation.
1462
+ */
1463
+ static applyNumberMultipleOf(numberSchema, schema) {
1464
+ if (schema["multipleOf"] === void 0) {
1465
+ return numberSchema;
1466
+ }
1467
+ return numberSchema.refine((val) => val % schema["multipleOf"] === 0, {
1468
+ message: `Number must be a multiple of ${schema["multipleOf"]}`
1469
+ });
1470
+ }
1471
+ /**
1472
+ * Applies enum validation to a number schema.
1473
+ *
1474
+ * @param {z.ZodNumber} numberSchema - The base number schema.
1475
+ * @param {JSONSchema} schema - The JSON schema with enum.
1476
+ * @returns {z.ZodNumber} - The updated schema with enum validation.
1477
+ */
1478
+ static applyNumberEnum(numberSchema, schema) {
1479
+ if (!schema.enum) {
1480
+ return numberSchema;
1481
+ }
1482
+ const numberEnums = schema.enum.filter(
1483
+ (val) => typeof val === "number"
1484
+ );
1485
+ if (numberEnums.length === 0) {
1486
+ return numberSchema;
1487
+ }
1488
+ return numberSchema.refine((val) => numberEnums.includes(val), {
1489
+ message: `Number must be one of: ${numberEnums.join(", ")}`
1490
+ });
1491
+ }
1492
+ /**
1493
+ * Applies integer constraint to a number schema if needed.
1494
+ *
1495
+ * @param {z.ZodNumber} numberSchema - The base number schema.
1496
+ * @param {JSONSchema} schema - The JSON schema.
1497
+ * @returns {z.ZodNumber} - The updated schema with integer validation if needed.
1498
+ */
1499
+ static applyIntegerConstraint(numberSchema, schema) {
1500
+ if (schema.type !== "integer") {
1501
+ return numberSchema;
1502
+ }
1503
+ return numberSchema.refine((val) => Number.isInteger(val), {
1504
+ message: "Number must be an integer"
1505
+ });
1506
+ }
1507
+ /**
1508
+ * Parses a string schema.
1509
+ *
1510
+ * @param {JSONSchema} schema - The JSON schema for a string.
1511
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1512
+ */
1513
+ static parseString(schema) {
1514
+ const stringSchema = import_zod.z.string();
1515
+ let result = stringSchema;
1516
+ if (schema.format) {
1517
+ return this.applyStringFormat(stringSchema, schema);
1518
+ } else {
1519
+ result = this.applyStringPattern(stringSchema, schema);
1520
+ result = this.applyStringLength(stringSchema, schema);
1521
+ result = this.applyStringEnum(stringSchema, schema);
1522
+ }
1523
+ return result;
1524
+ }
1525
+ /**
1526
+ * Applies format validation to a string schema.
1527
+ *
1528
+ * @param {z.ZodString} stringSchema - The base string schema.
1529
+ * @param {JSONSchema} schema - The JSON schema with format.
1530
+ * @returns {ZodTypeAny} - The updated schema with format validation.
1531
+ */
1532
+ static applyStringFormat(stringSchema, schema) {
1533
+ if (!schema.format) {
1534
+ return stringSchema;
1535
+ }
1536
+ switch (schema.format) {
1537
+ case "email":
1538
+ return stringSchema.email();
1539
+ case "date-time":
1540
+ return stringSchema.datetime();
1541
+ case "uri":
1542
+ return stringSchema.url();
1543
+ case "uuid":
1544
+ return stringSchema.uuid();
1545
+ case "date":
1546
+ return stringSchema.date();
1547
+ default:
1548
+ return stringSchema;
1549
+ }
1550
+ }
1551
+ /**
1552
+ * Applies pattern validation to a string schema.
1553
+ *
1554
+ * @param {z.ZodString} stringSchema - The base string schema.
1555
+ * @param {JSONSchema} schema - The JSON schema with pattern.
1556
+ * @returns {z.ZodString} - The updated schema with pattern validation.
1557
+ */
1558
+ static applyStringPattern(stringSchema, schema) {
1559
+ if (!schema["pattern"]) {
1560
+ return stringSchema;
1561
+ }
1562
+ const regex = new RegExp(schema["pattern"]);
1563
+ return stringSchema.regex(regex, {
1564
+ message: `String must match pattern: ${schema["pattern"]}`
1565
+ });
1566
+ }
1567
+ /**
1568
+ * Applies length constraints to a string schema.
1569
+ *
1570
+ * @param {z.ZodString} stringSchema - The base string schema.
1571
+ * @param {JSONSchema} schema - The JSON schema with length constraints.
1572
+ * @returns {z.ZodString} - The updated schema with length validation.
1573
+ */
1574
+ static applyStringLength(stringSchema, schema) {
1575
+ const result = stringSchema;
1576
+ if (schema["minLength"] !== void 0) {
1577
+ stringSchema = stringSchema.min(schema["minLength"]);
1578
+ }
1579
+ if (schema["maxLength"] !== void 0) {
1580
+ stringSchema = stringSchema.max(schema["maxLength"]);
1581
+ }
1582
+ return result;
1583
+ }
1584
+ /**
1585
+ * Applies enum validation to a string schema.
1586
+ *
1587
+ * @param {z.ZodString} stringSchema - The base string schema.
1588
+ * @param {JSONSchema} schema - The JSON schema with enum.
1589
+ * @returns {ZodTypeAny} - The updated schema with enum validation.
1590
+ */
1591
+ static applyStringEnum(stringSchema, schema) {
1592
+ if (!schema.enum) {
1593
+ return stringSchema;
1594
+ }
1595
+ return stringSchema.refine((val) => schema.enum?.includes(val), {
1596
+ message: `Value must be one of: ${schema.enum?.join(", ")}`
1597
+ });
1598
+ }
1599
+ /**
1600
+ * Parses a JSON schema of type array and returns the corresponding Zod schema.
1601
+ *
1602
+ * @param {JSONSchema} schema - The JSON schema.
1603
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1604
+ */
1605
+ static parseArray(schema) {
1606
+ if (Array.isArray(schema.items)) {
1607
+ const tupleSchemas = schema.items.map((item) => this.parseSchema(item));
1608
+ return import_zod.z.union(tupleSchemas);
1609
+ }
1610
+ const itemSchema = schema.items ? this.parseSchema(schema.items) : import_zod.z.any();
1611
+ const arraySchema = import_zod.z.array(itemSchema);
1612
+ let result = arraySchema;
1613
+ result = this.applyArrayConstraints(arraySchema, schema);
1614
+ return result;
1615
+ }
1616
+ /**
1617
+ * Applies constraints to an array schema.
1618
+ *
1619
+ * @param {z.ZodArray<any>} arraySchema - The base array schema.
1620
+ * @param {JSONSchema} schema - The JSON schema with array constraints.
1621
+ * @returns {z.ZodTypeAny} - The updated array schema with constraints.
1622
+ */
1623
+ static applyArrayConstraints(arraySchema, schema) {
1624
+ if (schema["minItems"] !== void 0) {
1625
+ arraySchema = arraySchema.min(schema["minItems"]);
1626
+ }
1627
+ if (schema["maxItems"] !== void 0) {
1628
+ arraySchema = arraySchema.max(schema["maxItems"]);
1629
+ }
1630
+ if (schema["uniqueItems"]) {
1631
+ return arraySchema.refine(
1632
+ (items) => new Set(items).size === items.length,
1633
+ { message: "Array items must be unique" }
1634
+ );
1635
+ }
1636
+ return arraySchema;
1637
+ }
1638
+ /**
1639
+ * Parses an object schema.
1640
+ *
1641
+ * @param {JSONSchema} schema - The JSON schema for an object.
1642
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1643
+ */
1644
+ static parseObject(schema) {
1645
+ if (schema["if"] && schema["then"]) {
1646
+ return this.parseConditional(schema);
1647
+ }
1648
+ const shape = {};
1649
+ this.processObjectProperties(schema, shape);
1650
+ return this.processAdditionalProperties(schema, import_zod.z.object(shape));
1651
+ }
1652
+ /**
1653
+ * Processes object properties and builds the shape object.
1654
+ *
1655
+ * @param {JSONSchema} schema - The JSON schema for an object.
1656
+ * @param {Record<string, ZodTypeAny>} shape - The shape object to populate.
1657
+ */
1658
+ static processObjectProperties(schema, shape) {
1659
+ const required = new Set(schema.required || []);
1660
+ if (!schema.properties) {
1661
+ return;
1662
+ }
1663
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
1664
+ const zodSchema = this.parseSchema(propSchema);
1665
+ shape[key] = required.has(key) ? zodSchema : zodSchema.optional();
1666
+ }
1667
+ }
1668
+ /**
1669
+ * Processes additionalProperties configuration.
1670
+ *
1671
+ * @param {JSONSchema} schema - The JSON schema for an object.
1672
+ * @param {z.ZodObject<any, any>} objectSchema - The Zod object schema.
1673
+ * @returns {z.ZodObject<any, any>} - The updated Zod object schema.
1674
+ */
1675
+ static processAdditionalProperties(schema, objectSchema) {
1676
+ if (schema.additionalProperties === true) {
1677
+ return objectSchema.passthrough();
1678
+ } else if (schema.additionalProperties && typeof schema.additionalProperties === "object") {
1679
+ const additionalPropSchema = this.parseSchema(
1680
+ schema.additionalProperties
1681
+ );
1682
+ return objectSchema.catchall(additionalPropSchema);
1683
+ } else {
1684
+ return objectSchema.strict();
1685
+ }
1686
+ }
1687
+ /**
1688
+ * Parses a conditional schema with if-then-else.
1689
+ *
1690
+ * @param {JSONSchema} schema - The JSON schema with conditional validation.
1691
+ * @returns {ZodTypeAny} - The conditional Zod schema.
1692
+ */
1693
+ static parseConditional(schema) {
1694
+ const zodObject = this.createBaseObjectSchema(schema);
1695
+ const ifCondition = schema["if"];
1696
+ const thenSchema = schema["then"];
1697
+ const elseSchema = schema["else"];
1698
+ return zodObject.superRefine((data, ctx) => {
1699
+ const dataWithDefaults = this.applyDefaultValues(
1700
+ data,
1701
+ schema
1702
+ );
1703
+ if (this.matchesCondition(dataWithDefaults, ifCondition)) {
1704
+ this.validateConditionalSchema(dataWithDefaults, thenSchema, ctx);
1705
+ } else if (elseSchema) {
1706
+ this.validateConditionalSchema(dataWithDefaults, elseSchema, ctx);
1707
+ }
1708
+ });
1709
+ }
1710
+ /**
1711
+ * Creates a base object schema from the given JSON schema.
1712
+ *
1713
+ * @param {JSONSchema} schema - The JSON schema.
1714
+ * @returns {z.ZodObject<any, any>} - The base Zod object schema.
1715
+ */
1716
+ static createBaseObjectSchema(schema) {
1717
+ const shape = {};
1718
+ const required = new Set(schema.required || []);
1719
+ for (const [key, value] of Object.entries(schema.properties || {})) {
1720
+ const zodSchema = this.parseSchema(value);
1721
+ shape[key] = required.has(key) ? zodSchema : zodSchema.optional();
1722
+ }
1723
+ const zodObject = import_zod.z.object(shape);
1724
+ return this.processAdditionalProperties(schema, zodObject);
1725
+ }
1726
+ /**
1727
+ * Applies default values from schema properties to data object.
1728
+ *
1729
+ * @param {JSONValue} data - The original data object.
1730
+ * @param {JSONSchema} schema - The schema with default values.
1731
+ * @returns {JSONValue} - The data object with defaults applied.
1732
+ */
1733
+ static applyDefaultValues(data, schema) {
1734
+ if (typeof data !== "object" || data === null) {
1735
+ return data;
1736
+ }
1737
+ if (Array.isArray(data)) {
1738
+ return data;
1739
+ }
1740
+ const objectData = data;
1741
+ const dataWithDefaults = { ...objectData };
1742
+ if (!schema.properties) {
1743
+ return dataWithDefaults;
1744
+ }
1745
+ for (const [key, propSchema] of Object.entries(schema.properties)) {
1746
+ if (!(key in dataWithDefaults) && "default" in propSchema) {
1747
+ dataWithDefaults[key] = propSchema["default"];
1748
+ }
1749
+ }
1750
+ return dataWithDefaults;
1751
+ }
1752
+ /**
1753
+ * Parses a schema with combinators (oneOf, anyOf, allOf).
1754
+ * Delegates to the appropriate combinator parser based on which combinator is present.
1755
+ *
1756
+ * @param {JSONSchema} schema - The JSON schema with combinators.
1757
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1758
+ */
1759
+ static parseCombinator(schema) {
1760
+ if (schema.oneOf) {
1761
+ return this.parseOneOf(schema.oneOf);
1762
+ }
1763
+ if (schema.anyOf) {
1764
+ return this.parseAnyOf(schema.anyOf);
1765
+ }
1766
+ if (schema.allOf) {
1767
+ return this.parseAllOf(schema.allOf);
1768
+ }
1769
+ throw new Error("Unsupported schema type");
1770
+ }
1771
+ /**
1772
+ * Parses a oneOf combinator schema.
1773
+ *
1774
+ * @param {JSONSchema[]} schemas - Array of JSON schemas in the oneOf.
1775
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1776
+ */
1777
+ static parseOneOf(schemas) {
1778
+ return this.createUnionFromSchemas(schemas);
1779
+ }
1780
+ /**
1781
+ * Parses an anyOf combinator schema.
1782
+ *
1783
+ * @param {JSONSchema[]} schemas - Array of JSON schemas in the anyOf.
1784
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1785
+ */
1786
+ static parseAnyOf(schemas) {
1787
+ return this.createUnionFromSchemas(schemas);
1788
+ }
1789
+ /**
1790
+ * Creates a union from an array of schemas, handling special cases.
1791
+ *
1792
+ * @param {JSONSchema[]} schemas - Array of JSON schemas to create a union from.
1793
+ * @returns {ZodTypeAny} - The union Zod schema.
1794
+ */
1795
+ static createUnionFromSchemas(schemas) {
1796
+ if (schemas.length === 0) {
1797
+ return import_zod.z.any();
1798
+ }
1799
+ if (schemas.length === 1) {
1800
+ return this.parseSchema(schemas[0]);
1801
+ }
1802
+ const zodSchemas = [];
1803
+ for (const subSchema of schemas) {
1804
+ if (subSchema.type === "null") {
1805
+ zodSchemas.push(import_zod.z.null());
1806
+ } else {
1807
+ zodSchemas.push(this.parseSchema(subSchema));
1808
+ }
1809
+ }
1810
+ if (zodSchemas.length >= 2) {
1811
+ return import_zod.z.union(zodSchemas);
1812
+ } else if (zodSchemas.length === 1) {
1813
+ return zodSchemas[0];
1814
+ }
1815
+ return import_zod.z.any();
1816
+ }
1817
+ /**
1818
+ * Parses an allOf combinator schema by merging all schemas.
1819
+ *
1820
+ * @param {JSONSchema[]} schemas - Array of JSON schemas in the allOf.
1821
+ * @returns {ZodTypeAny} - The ZodTypeAny schema.
1822
+ */
1823
+ static parseAllOf(schemas) {
1824
+ if (schemas.length === 0) {
1825
+ return import_zod.z.any();
1826
+ }
1827
+ if (schemas.length === 1) {
1828
+ return this.parseSchema(schemas[0]);
1829
+ }
1830
+ const mergedSchema = schemas.reduce(
1831
+ (acc, currentSchema) => this.mergeSchemas(acc, currentSchema)
1832
+ );
1833
+ return this.parseSchema(mergedSchema);
1834
+ }
1835
+ /**
1836
+ * Merges two JSON schemas together.
1837
+ *
1838
+ * @param {JSONSchema} baseSchema - The base JSON schema.
1839
+ * @param {JSONSchema} addSchema - The JSON schema to add.
1840
+ * @returns {JSONSchema} - The merged JSON schema
1841
+ */
1842
+ static mergeSchemas(baseSchema, addSchema) {
1843
+ const merged = { ...baseSchema, ...addSchema };
1844
+ if (baseSchema.properties && addSchema.properties) {
1845
+ const mergedProperties = {
1846
+ ...baseSchema.properties,
1847
+ ...addSchema.properties
1848
+ };
1849
+ merged.properties = mergedProperties;
1850
+ }
1851
+ if (baseSchema.required && addSchema.required) {
1852
+ const mergedRequired = [
1853
+ .../* @__PURE__ */ new Set([...baseSchema.required, ...addSchema.required])
1854
+ ];
1855
+ merged.required = mergedRequired;
1856
+ }
1857
+ return merged;
1858
+ }
1859
+ };
1112
1860
 
1113
1861
  // src/adapters/langchain_adapter.ts
1114
- var import_json_schema_to_zod = require("@dmitryrechkin/json-schema-to-zod");
1115
1862
  var import_tools = require("@langchain/core/tools");
1116
- var import_zod = require("zod");
1863
+ var import_zod2 = require("zod");
1117
1864
  init_logging();
1118
1865
 
1119
1866
  // src/adapters/base.ts
@@ -1233,10 +1980,10 @@ var BaseAdapter = class {
1233
1980
  // src/adapters/langchain_adapter.ts
1234
1981
  function schemaToZod(schema) {
1235
1982
  try {
1236
- return import_json_schema_to_zod.JSONSchemaToZod.convert(schema);
1983
+ return JSONSchemaToZod.convert(schema);
1237
1984
  } catch (err) {
1238
1985
  logger.warn(`Failed to convert JSON schema to Zod: ${err}`);
1239
- return import_zod.z.any();
1986
+ return import_zod2.z.any();
1240
1987
  }
1241
1988
  }
1242
1989
  __name(schemaToZod, "schemaToZod");
@@ -1254,7 +2001,7 @@ var LangChainAdapter = class extends BaseAdapter {
1254
2001
  if (this.disallowedTools.includes(mcpTool.name)) {
1255
2002
  return null;
1256
2003
  }
1257
- const argsSchema = mcpTool.inputSchema ? schemaToZod(mcpTool.inputSchema) : import_zod.z.object({}).optional();
2004
+ const argsSchema = mcpTool.inputSchema ? schemaToZod(mcpTool.inputSchema) : import_zod2.z.object({}).optional();
1258
2005
  const tool = new import_tools.DynamicStructuredTool({
1259
2006
  name: mcpTool.name ?? "NO NAME",
1260
2007
  description: mcpTool.description ?? "",
@@ -1284,11 +2031,10 @@ var LangChainAdapter = class extends BaseAdapter {
1284
2031
  init_logging();
1285
2032
 
1286
2033
  // src/managers/server_manager.ts
1287
- var import_lodash_es = require("lodash-es");
1288
2034
  init_logging();
1289
2035
 
1290
2036
  // src/managers/tools/acquire_active_mcp_server.ts
1291
- var import_zod2 = require("zod");
2037
+ var import_zod3 = require("zod");
1292
2038
 
1293
2039
  // src/managers/tools/base.ts
1294
2040
  var import_tools2 = require("@langchain/core/tools");
@@ -1313,7 +2059,7 @@ var MCPServerTool = class extends import_tools2.StructuredTool {
1313
2059
  };
1314
2060
 
1315
2061
  // src/managers/tools/acquire_active_mcp_server.ts
1316
- var PresentActiveServerSchema = import_zod2.z.object({});
2062
+ var PresentActiveServerSchema = import_zod3.z.object({});
1317
2063
  var AcquireActiveMCPServerTool = class extends MCPServerTool {
1318
2064
  static {
1319
2065
  __name(this, "AcquireActiveMCPServerTool");
@@ -1334,7 +2080,7 @@ var AcquireActiveMCPServerTool = class extends MCPServerTool {
1334
2080
 
1335
2081
  // src/managers/tools/add_server_from_config.ts
1336
2082
  var import_tools3 = require("@langchain/core/tools");
1337
- var import_zod3 = require("zod");
2083
+ var import_zod4 = require("zod");
1338
2084
  init_logging();
1339
2085
  var AddMCPServerFromConfigTool = class extends import_tools3.StructuredTool {
1340
2086
  static {
@@ -1342,9 +2088,9 @@ var AddMCPServerFromConfigTool = class extends import_tools3.StructuredTool {
1342
2088
  }
1343
2089
  name = "add_mcp_server_from_config";
1344
2090
  description = "Adds a new MCP server to the client from a configuration object and connects to it, making its tools available.";
1345
- schema = import_zod3.z.object({
1346
- serverName: import_zod3.z.string().describe("The name for the new MCP server."),
1347
- serverConfig: import_zod3.z.any().describe(
2091
+ schema = import_zod4.z.object({
2092
+ serverName: import_zod4.z.string().describe("The name for the new MCP server."),
2093
+ serverConfig: import_zod4.z.any().describe(
1348
2094
  'The configuration object for the server. This should not include the top-level "mcpServers" key.'
1349
2095
  )
1350
2096
  });
@@ -1386,10 +2132,10 @@ ${tools.map((t) => t.name).join("\n")}`;
1386
2132
  };
1387
2133
 
1388
2134
  // src/managers/tools/connect_mcp_server.ts
1389
- var import_zod4 = require("zod");
2135
+ var import_zod5 = require("zod");
1390
2136
  init_logging();
1391
- var ConnectMCPServerSchema = import_zod4.z.object({
1392
- serverName: import_zod4.z.string().describe("The name of the MCP server.")
2137
+ var ConnectMCPServerSchema = import_zod5.z.object({
2138
+ serverName: import_zod5.z.string().describe("The name of the MCP server.")
1393
2139
  });
1394
2140
  var ConnectMCPServerTool = class extends MCPServerTool {
1395
2141
  static {
@@ -1437,9 +2183,9 @@ var ConnectMCPServerTool = class extends MCPServerTool {
1437
2183
  };
1438
2184
 
1439
2185
  // src/managers/tools/list_mcp_servers.ts
1440
- var import_zod5 = require("zod");
2186
+ var import_zod6 = require("zod");
1441
2187
  init_logging();
1442
- var EnumerateServersSchema = import_zod5.z.object({});
2188
+ var EnumerateServersSchema = import_zod6.z.object({});
1443
2189
  var ListMCPServersTool = class extends MCPServerTool {
1444
2190
  static {
1445
2191
  __name(this, "ListMCPServersTool");
@@ -1476,8 +2222,8 @@ var ListMCPServersTool = class extends MCPServerTool {
1476
2222
  };
1477
2223
 
1478
2224
  // src/managers/tools/release_mcp_server_connection.ts
1479
- var import_zod6 = require("zod");
1480
- var ReleaseConnectionSchema = import_zod6.z.object({});
2225
+ var import_zod7 = require("zod");
2226
+ var ReleaseConnectionSchema = import_zod7.z.object({});
1481
2227
  var ReleaseMCPServerConnectionTool = class extends MCPServerTool {
1482
2228
  static {
1483
2229
  __name(this, "ReleaseMCPServerConnectionTool");
@@ -1499,6 +2245,28 @@ var ReleaseMCPServerConnectionTool = class extends MCPServerTool {
1499
2245
  };
1500
2246
 
1501
2247
  // src/managers/server_manager.ts
2248
+ function isEqual(a, b) {
2249
+ if (a === b) return true;
2250
+ if (a == null || b == null) return false;
2251
+ if (typeof a !== typeof b) return false;
2252
+ if (a instanceof Date && b instanceof Date) {
2253
+ return a.getTime() === b.getTime();
2254
+ }
2255
+ if (Array.isArray(a) && Array.isArray(b)) {
2256
+ if (a.length !== b.length) return false;
2257
+ return a.every((item, index) => isEqual(item, b[index]));
2258
+ }
2259
+ if (typeof a === "object" && typeof b === "object") {
2260
+ const keysA = Object.keys(a);
2261
+ const keysB = Object.keys(b);
2262
+ if (keysA.length !== keysB.length) return false;
2263
+ return keysA.every((key) => {
2264
+ return Object.prototype.hasOwnProperty.call(b, key) && isEqual(a[key], b[key]);
2265
+ });
2266
+ }
2267
+ return false;
2268
+ }
2269
+ __name(isEqual, "isEqual");
1502
2270
  var ServerManager = class {
1503
2271
  static {
1504
2272
  __name(this, "ServerManager");
@@ -1575,7 +2343,7 @@ var ServerManager = class {
1575
2343
  continue;
1576
2344
  }
1577
2345
  const cachedTools = this.serverTools[serverName];
1578
- const toolsChanged = !cachedTools || !(0, import_lodash_es.isEqual)(cachedTools, tools);
2346
+ const toolsChanged = !cachedTools || !isEqual(cachedTools, tools);
1579
2347
  if (toolsChanged) {
1580
2348
  this.serverTools[serverName] = tools;
1581
2349
  this.initializedServers[serverName] = true;
@@ -1637,14 +2405,14 @@ var ObservabilityManager = class {
1637
2405
  metadata;
1638
2406
  metadataProvider;
1639
2407
  tagsProvider;
1640
- constructor(config2 = {}) {
1641
- this.customCallbacks = config2.customCallbacks;
1642
- this.verbose = config2.verbose ?? false;
1643
- this.observe = config2.observe ?? true;
1644
- this.agentId = config2.agentId;
1645
- this.metadata = config2.metadata;
1646
- this.metadataProvider = config2.metadataProvider;
1647
- this.tagsProvider = config2.tagsProvider;
2408
+ constructor(config = {}) {
2409
+ this.customCallbacks = config.customCallbacks;
2410
+ this.verbose = config.verbose ?? false;
2411
+ this.observe = config.observe ?? true;
2412
+ this.agentId = config.agentId;
2413
+ this.metadata = config.metadata;
2414
+ this.metadataProvider = config.metadataProvider;
2415
+ this.tagsProvider = config.tagsProvider;
1648
2416
  }
1649
2417
  /**
1650
2418
  * Collect all available observability handlers from configured platforms.
@@ -1817,7 +2585,15 @@ var fs2 = __toESM(require("fs"), 1);
1817
2585
  var os = __toESM(require("os"), 1);
1818
2586
  var path2 = __toESM(require("path"), 1);
1819
2587
  var import_posthog_node = require("posthog-node");
1820
- var import_uuid = require("uuid");
2588
+
2589
+ // src/server/utils/runtime.ts
2590
+ var isDeno = typeof globalThis.Deno !== "undefined";
2591
+ function generateUUID() {
2592
+ return globalThis.crypto.randomUUID();
2593
+ }
2594
+ __name(generateUUID, "generateUUID");
2595
+
2596
+ // src/telemetry/telemetry.ts
1821
2597
  init_logging();
1822
2598
 
1823
2599
  // src/telemetry/events.ts
@@ -2081,7 +2857,7 @@ var Telemetry = class _Telemetry {
2081
2857
  if (isFirstTime) {
2082
2858
  logger.debug(`Creating user ID path: ${this.USER_ID_PATH}`);
2083
2859
  fs2.mkdirSync(path2.dirname(this.USER_ID_PATH), { recursive: true });
2084
- const newUserId = (0, import_uuid.v4)();
2860
+ const newUserId = generateUUID();
2085
2861
  fs2.writeFileSync(this.USER_ID_PATH, newUserId);
2086
2862
  this._currUserId = newUserId;
2087
2863
  logger.debug(`User ID path created: ${this.USER_ID_PATH}`);
@@ -2297,7 +3073,7 @@ Here are the tools *currently* available to you (this list includes server manag
2297
3073
  `;
2298
3074
 
2299
3075
  // src/agents/remote.ts
2300
- var import_zod_to_json_schema = require("zod-to-json-schema");
3076
+ var import_zod8 = require("zod");
2301
3077
  init_logging();
2302
3078
  var API_CHATS_ENDPOINT = "/api/v1/chats";
2303
3079
  var API_CHAT_EXECUTE_ENDPOINT = "/api/v1/chats/{chat_id}/execute";
@@ -2321,7 +3097,7 @@ var RemoteAgent = class {
2321
3097
  this.apiKey = apiKey;
2322
3098
  }
2323
3099
  pydanticToJsonSchema(schema) {
2324
- return (0, import_zod_to_json_schema.zodToJsonSchema)(schema);
3100
+ return (0, import_zod8.toJSONSchema)(schema);
2325
3101
  }
2326
3102
  parseStructuredResponse(responseData, outputSchema) {
2327
3103
  let resultData;
@@ -2923,24 +3699,24 @@ var MCPAgent = class {
2923
3699
  const serverConfigs = {};
2924
3700
  for (const serverName of serverNames) {
2925
3701
  try {
2926
- const config2 = this.client.getServerConfig(serverName);
2927
- if (config2) {
3702
+ const config = this.client.getServerConfig(serverName);
3703
+ if (config) {
2928
3704
  let serverType = "unknown";
2929
- if (config2.command) {
3705
+ if (config.command) {
2930
3706
  serverType = "command";
2931
- } else if (config2.url) {
3707
+ } else if (config.url) {
2932
3708
  serverType = "http";
2933
- } else if (config2.ws_url) {
3709
+ } else if (config.ws_url) {
2934
3710
  serverType = "websocket";
2935
3711
  }
2936
3712
  serverConfigs[serverName] = {
2937
3713
  type: serverType,
2938
3714
  // Include safe configuration details (avoid sensitive data)
2939
- has_args: !!config2.args,
2940
- has_env: !!config2.env,
2941
- has_headers: !!config2.headers,
2942
- url: config2.url || null,
2943
- command: config2.command || null
3715
+ has_args: !!config.args,
3716
+ has_env: !!config.env,
3717
+ has_headers: !!config.headers,
3718
+ url: config.url || null,
3719
+ command: config.command || null
2944
3720
  };
2945
3721
  }
2946
3722
  } catch (error) {
@@ -3756,7 +4532,7 @@ var MCPAgent = class {
3756
4532
  let structuredLlm = null;
3757
4533
  let schemaDescription = "";
3758
4534
  logger.debug(
3759
- `\u{1F504} Structured output requested, schema: ${JSON.stringify((0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema), null, 2)}`
4535
+ `\u{1F504} Structured output requested, schema: ${JSON.stringify((0, import_zod9.toJSONSchema)(outputSchema), null, 2)}`
3760
4536
  );
3761
4537
  if (llm && "withStructuredOutput" in llm && typeof llm.withStructuredOutput === "function") {
3762
4538
  structuredLlm = llm.withStructuredOutput(outputSchema);
@@ -3765,7 +4541,7 @@ var MCPAgent = class {
3765
4541
  } else {
3766
4542
  throw new Error("LLM is required for structured output");
3767
4543
  }
3768
- const jsonSchema = (0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema);
4544
+ const jsonSchema = (0, import_zod9.toJSONSchema)(outputSchema);
3769
4545
  const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
3770
4546
  schemaDescription = JSON.stringify(cleanSchema, null, 2);
3771
4547
  logger.info(`\u{1F504} Schema description: ${schemaDescription}`);
@@ -3910,7 +4686,7 @@ ${formatPrompt}`
3910
4686
  */
3911
4687
  _enhanceQueryWithSchema(query, outputSchema) {
3912
4688
  try {
3913
- const jsonSchema = (0, import_zod_to_json_schema2.zodToJsonSchema)(outputSchema);
4689
+ const jsonSchema = (0, import_zod9.toJSONSchema)(outputSchema);
3914
4690
  const { $schema, additionalProperties, ...cleanSchema } = jsonSchema;
3915
4691
  const schemaDescription = JSON.stringify(cleanSchema, null, 2);
3916
4692
  const enhancedQuery = `