@mastra/mcp 0.4.0-alpha.8 → 0.4.0

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.cjs CHANGED
@@ -10,6 +10,35 @@ var protocol_js = require('@modelcontextprotocol/sdk/shared/protocol.js');
10
10
  var types_js = require('@modelcontextprotocol/sdk/types.js');
11
11
  var exitHook = require('exit-hook');
12
12
  var uuid = require('uuid');
13
+ var core = require('@mastra/core');
14
+ var index_js$1 = require('@modelcontextprotocol/sdk/server/index.js');
15
+ var sse_js$1 = require('@modelcontextprotocol/sdk/server/sse.js');
16
+ var stdio_js$1 = require('@modelcontextprotocol/sdk/server/stdio.js');
17
+ var fs = require('fs');
18
+ var os = require('os');
19
+ var path = require('path');
20
+
21
+ function _interopNamespace(e) {
22
+ if (e && e.__esModule) return e;
23
+ var n = Object.create(null);
24
+ if (e) {
25
+ Object.keys(e).forEach(function (k) {
26
+ if (k !== 'default') {
27
+ var d = Object.getOwnPropertyDescriptor(e, k);
28
+ Object.defineProperty(n, k, d.get ? d : {
29
+ enumerable: true,
30
+ get: function () { return e[k]; }
31
+ });
32
+ }
33
+ });
34
+ }
35
+ n.default = e;
36
+ return Object.freeze(n);
37
+ }
38
+
39
+ var fs__namespace = /*#__PURE__*/_interopNamespace(fs);
40
+ var os__namespace = /*#__PURE__*/_interopNamespace(os);
41
+ var path__namespace = /*#__PURE__*/_interopNamespace(path);
13
42
 
14
43
  // src/client.ts
15
44
 
@@ -366,8 +395,8 @@ function getErrorMap() {
366
395
  return overrideErrorMap;
367
396
  }
368
397
  var makeIssue = (params) => {
369
- const { data, path, errorMaps, issueData } = params;
370
- const fullPath = [...path, ...issueData.path || []];
398
+ const { data, path: path2, errorMaps, issueData } = params;
399
+ const fullPath = [...path2, ...issueData.path || []];
371
400
  const fullIssue = {
372
401
  ...issueData,
373
402
  path: fullPath
@@ -489,11 +518,11 @@ var errorUtil;
489
518
  var _ZodEnum_cache;
490
519
  var _ZodNativeEnum_cache;
491
520
  var ParseInputLazyPath = class {
492
- constructor(parent, value, path, key) {
521
+ constructor(parent, value, path2, key) {
493
522
  this._cachedPath = [];
494
523
  this.parent = parent;
495
524
  this.data = value;
496
- this._path = path;
525
+ this._path = path2;
497
526
  this._key = key;
498
527
  }
499
528
  get path() {
@@ -4107,7 +4136,7 @@ var MastraMCPClient = class extends base.MastraBase {
4107
4136
  this.timeout = timeout;
4108
4137
  this.logHandler = server.logger;
4109
4138
  this.enableServerLogs = server.enableServerLogs ?? true;
4110
- const { logger, enableServerLogs, ...serverConfig } = server;
4139
+ const { logger: logger3, enableServerLogs, ...serverConfig } = server;
4111
4140
  if (`url` in serverConfig) {
4112
4141
  this.transport = new sse_js.SSEClientTransport(serverConfig.url, {
4113
4142
  requestInit: serverConfig.requestInit,
@@ -4354,5 +4383,2125 @@ To fix this you have three different options:
4354
4383
  }
4355
4384
  };
4356
4385
 
4386
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseAnyOf.js
4387
+ var parseAnyOf = (schema, refs) => {
4388
+ return schema.anyOf.length ? schema.anyOf.length === 1 ? parseSchema(schema.anyOf[0], {
4389
+ ...refs,
4390
+ path: [...refs.path, "anyOf", 0]
4391
+ }) : `z.union([${schema.anyOf.map((schema2, i) => parseSchema(schema2, { ...refs, path: [...refs.path, "anyOf", i] })).join(", ")}])` : `z.any()`;
4392
+ };
4393
+
4394
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseBoolean.js
4395
+ var parseBoolean = (_schema) => {
4396
+ return "z.boolean()";
4397
+ };
4398
+
4399
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseDefault.js
4400
+ var parseDefault = (_schema) => {
4401
+ return "z.any()";
4402
+ };
4403
+
4404
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseMultipleType.js
4405
+ var parseMultipleType = (schema, refs) => {
4406
+ return `z.union([${schema.type.map((type) => parseSchema({ ...schema, type }, refs)).join(", ")}])`;
4407
+ };
4408
+
4409
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNot.js
4410
+ var parseNot = (schema, refs) => {
4411
+ return `z.any().refine((value) => !${parseSchema(schema.not, {
4412
+ ...refs,
4413
+ path: [...refs.path, "not"]
4414
+ })}.safeParse(value).success, "Invalid input: Should NOT be valid against schema")`;
4415
+ };
4416
+
4417
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNull.js
4418
+ var parseNull = (_schema) => {
4419
+ return "z.null()";
4420
+ };
4421
+
4422
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/utils/half.js
4423
+ var half = (arr) => {
4424
+ return [arr.slice(0, arr.length / 2), arr.slice(arr.length / 2)];
4425
+ };
4426
+
4427
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseAllOf.js
4428
+ var originalIndex = Symbol("Original index");
4429
+ var ensureOriginalIndex = (arr) => {
4430
+ let newArr = [];
4431
+ for (let i = 0; i < arr.length; i++) {
4432
+ const item = arr[i];
4433
+ if (typeof item === "boolean") {
4434
+ newArr.push(item ? { [originalIndex]: i } : { [originalIndex]: i, not: {} });
4435
+ } else if (originalIndex in item) {
4436
+ return arr;
4437
+ } else {
4438
+ newArr.push({ ...item, [originalIndex]: i });
4439
+ }
4440
+ }
4441
+ return newArr;
4442
+ };
4443
+ function parseAllOf(schema, refs) {
4444
+ if (schema.allOf.length === 0) {
4445
+ return "z.never()";
4446
+ } else if (schema.allOf.length === 1) {
4447
+ const item = schema.allOf[0];
4448
+ return parseSchema(item, {
4449
+ ...refs,
4450
+ path: [...refs.path, "allOf", item[originalIndex]]
4451
+ });
4452
+ } else {
4453
+ const [left, right] = half(ensureOriginalIndex(schema.allOf));
4454
+ return `z.intersection(${parseAllOf({ allOf: left }, refs)}, ${parseAllOf({
4455
+ allOf: right
4456
+ }, refs)})`;
4457
+ }
4458
+ }
4459
+
4460
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/utils/withMessage.js
4461
+ function withMessage(schema, key, get) {
4462
+ const value = schema[key];
4463
+ let r = "";
4464
+ if (value !== void 0) {
4465
+ const got = get({ value, json: JSON.stringify(value) });
4466
+ if (got) {
4467
+ const opener = got[0];
4468
+ const prefix = got.length === 3 ? got[1] : "";
4469
+ const closer = got.length === 3 ? got[2] : got[1];
4470
+ r += opener;
4471
+ if (schema.errorMessage?.[key] !== void 0) {
4472
+ r += prefix + JSON.stringify(schema.errorMessage[key]);
4473
+ }
4474
+ r += closer;
4475
+ }
4476
+ }
4477
+ return r;
4478
+ }
4479
+
4480
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseArray.js
4481
+ var parseArray = (schema, refs) => {
4482
+ if (Array.isArray(schema.items)) {
4483
+ return `z.tuple([${schema.items.map((v, i) => parseSchema(v, { ...refs, path: [...refs.path, "items", i] }))}])`;
4484
+ }
4485
+ let r = !schema.items ? "z.array(z.any())" : `z.array(${parseSchema(schema.items, {
4486
+ ...refs,
4487
+ path: [...refs.path, "items"]
4488
+ })})`;
4489
+ r += withMessage(schema, "minItems", ({ json }) => [
4490
+ `.min(${json}`,
4491
+ ", ",
4492
+ ")"
4493
+ ]);
4494
+ r += withMessage(schema, "maxItems", ({ json }) => [
4495
+ `.max(${json}`,
4496
+ ", ",
4497
+ ")"
4498
+ ]);
4499
+ return r;
4500
+ };
4501
+
4502
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseConst.js
4503
+ var parseConst = (schema) => {
4504
+ return `z.literal(${JSON.stringify(schema.const)})`;
4505
+ };
4506
+
4507
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseEnum.js
4508
+ var parseEnum = (schema) => {
4509
+ if (schema.enum.length === 0) {
4510
+ return "z.never()";
4511
+ } else if (schema.enum.length === 1) {
4512
+ return `z.literal(${JSON.stringify(schema.enum[0])})`;
4513
+ } else if (schema.enum.every((x) => typeof x === "string")) {
4514
+ return `z.enum([${schema.enum.map((x) => JSON.stringify(x))}])`;
4515
+ } else {
4516
+ return `z.union([${schema.enum.map((x) => `z.literal(${JSON.stringify(x)})`).join(", ")}])`;
4517
+ }
4518
+ };
4519
+
4520
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseIfThenElse.js
4521
+ var parseIfThenElse = (schema, refs) => {
4522
+ const $if = parseSchema(schema.if, { ...refs, path: [...refs.path, "if"] });
4523
+ const $then = parseSchema(schema.then, {
4524
+ ...refs,
4525
+ path: [...refs.path, "then"]
4526
+ });
4527
+ const $else = parseSchema(schema.else, {
4528
+ ...refs,
4529
+ path: [...refs.path, "else"]
4530
+ });
4531
+ return `z.union([${$then}, ${$else}]).superRefine((value,ctx) => {
4532
+ const result = ${$if}.safeParse(value).success
4533
+ ? ${$then}.safeParse(value)
4534
+ : ${$else}.safeParse(value);
4535
+ if (!result.success) {
4536
+ result.error.errors.forEach((error) => ctx.addIssue(error))
4537
+ }
4538
+ })`;
4539
+ };
4540
+
4541
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNumber.js
4542
+ var parseNumber = (schema) => {
4543
+ let r = "z.number()";
4544
+ if (schema.type === "integer") {
4545
+ r += withMessage(schema, "type", () => [".int(", ")"]);
4546
+ } else {
4547
+ r += withMessage(schema, "format", ({ value }) => {
4548
+ if (value === "int64") {
4549
+ return [".int(", ")"];
4550
+ }
4551
+ });
4552
+ }
4553
+ r += withMessage(schema, "multipleOf", ({ value, json }) => {
4554
+ if (value === 1) {
4555
+ if (r.startsWith("z.number().int(")) {
4556
+ return;
4557
+ }
4558
+ return [".int(", ")"];
4559
+ }
4560
+ return [`.multipleOf(${json}`, ", ", ")"];
4561
+ });
4562
+ if (typeof schema.minimum === "number") {
4563
+ if (schema.exclusiveMinimum === true) {
4564
+ r += withMessage(schema, "minimum", ({ json }) => [
4565
+ `.gt(${json}`,
4566
+ ", ",
4567
+ ")"
4568
+ ]);
4569
+ } else {
4570
+ r += withMessage(schema, "minimum", ({ json }) => [
4571
+ `.gte(${json}`,
4572
+ ", ",
4573
+ ")"
4574
+ ]);
4575
+ }
4576
+ } else if (typeof schema.exclusiveMinimum === "number") {
4577
+ r += withMessage(schema, "exclusiveMinimum", ({ json }) => [
4578
+ `.gt(${json}`,
4579
+ ", ",
4580
+ ")"
4581
+ ]);
4582
+ }
4583
+ if (typeof schema.maximum === "number") {
4584
+ if (schema.exclusiveMaximum === true) {
4585
+ r += withMessage(schema, "maximum", ({ json }) => [
4586
+ `.lt(${json}`,
4587
+ ", ",
4588
+ ")"
4589
+ ]);
4590
+ } else {
4591
+ r += withMessage(schema, "maximum", ({ json }) => [
4592
+ `.lte(${json}`,
4593
+ ", ",
4594
+ ")"
4595
+ ]);
4596
+ }
4597
+ } else if (typeof schema.exclusiveMaximum === "number") {
4598
+ r += withMessage(schema, "exclusiveMaximum", ({ json }) => [
4599
+ `.lt(${json}`,
4600
+ ", ",
4601
+ ")"
4602
+ ]);
4603
+ }
4604
+ return r;
4605
+ };
4606
+
4607
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseOneOf.js
4608
+ var parseOneOf = (schema, refs) => {
4609
+ return schema.oneOf.length ? schema.oneOf.length === 1 ? parseSchema(schema.oneOf[0], {
4610
+ ...refs,
4611
+ path: [...refs.path, "oneOf", 0]
4612
+ }) : `z.any().superRefine((x, ctx) => {
4613
+ const schemas = [${schema.oneOf.map((schema2, i) => parseSchema(schema2, {
4614
+ ...refs,
4615
+ path: [...refs.path, "oneOf", i]
4616
+ })).join(", ")}];
4617
+ const errors = schemas.reduce<z.ZodError[]>(
4618
+ (errors, schema) =>
4619
+ ((result) =>
4620
+ result.error ? [...errors, result.error] : errors)(
4621
+ schema.safeParse(x),
4622
+ ),
4623
+ [],
4624
+ );
4625
+ if (schemas.length - errors.length !== 1) {
4626
+ ctx.addIssue({
4627
+ path: ctx.path,
4628
+ code: "invalid_union",
4629
+ unionErrors: errors,
4630
+ message: "Invalid input: Should pass single schema",
4631
+ });
4632
+ }
4633
+ })` : "z.any()";
4634
+ };
4635
+
4636
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/utils/jsdocs.js
4637
+ var expandJsdocs = (jsdocs) => {
4638
+ const lines = jsdocs.split("\n");
4639
+ const result = lines.length === 1 ? lines[0] : `
4640
+ ${lines.map((x) => `* ${x}`).join("\n")}
4641
+ `;
4642
+ return `/**${result}*/
4643
+ `;
4644
+ };
4645
+ var addJsdocs = (schema, parsed) => {
4646
+ const description = schema.description;
4647
+ if (!description) {
4648
+ return parsed;
4649
+ }
4650
+ return `
4651
+ ${expandJsdocs(description)}${parsed}`;
4652
+ };
4653
+
4654
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseObject.js
4655
+ function parseObject(objectSchema, refs) {
4656
+ let properties = void 0;
4657
+ if (objectSchema.properties) {
4658
+ if (!Object.keys(objectSchema.properties).length) {
4659
+ properties = "z.object({})";
4660
+ } else {
4661
+ properties = "z.object({ ";
4662
+ properties += Object.keys(objectSchema.properties).map((key) => {
4663
+ const propSchema = objectSchema.properties[key];
4664
+ let result = `${JSON.stringify(key)}: ${parseSchema(propSchema, {
4665
+ ...refs,
4666
+ path: [...refs.path, "properties", key]
4667
+ })}`;
4668
+ if (refs.withJsdocs && typeof propSchema === "object") {
4669
+ result = addJsdocs(propSchema, result);
4670
+ }
4671
+ const hasDefault = typeof propSchema === "object" && propSchema.default !== void 0;
4672
+ const required = Array.isArray(objectSchema.required) ? objectSchema.required.includes(key) : typeof propSchema === "object" && propSchema.required === true;
4673
+ const optional = !hasDefault && !required;
4674
+ return optional ? `${result}.optional()` : result;
4675
+ }).join(", ");
4676
+ properties += " })";
4677
+ }
4678
+ }
4679
+ const additionalProperties = objectSchema.additionalProperties !== void 0 ? parseSchema(objectSchema.additionalProperties, {
4680
+ ...refs,
4681
+ path: [...refs.path, "additionalProperties"]
4682
+ }) : void 0;
4683
+ let patternProperties = void 0;
4684
+ if (objectSchema.patternProperties) {
4685
+ const parsedPatternProperties = Object.fromEntries(Object.entries(objectSchema.patternProperties).map(([key, value]) => {
4686
+ return [
4687
+ key,
4688
+ parseSchema(value, {
4689
+ ...refs,
4690
+ path: [...refs.path, "patternProperties", key]
4691
+ })
4692
+ ];
4693
+ }, {}));
4694
+ patternProperties = "";
4695
+ if (properties) {
4696
+ if (additionalProperties) {
4697
+ patternProperties += `.catchall(z.union([${[
4698
+ ...Object.values(parsedPatternProperties),
4699
+ additionalProperties
4700
+ ].join(", ")}]))`;
4701
+ } else if (Object.keys(parsedPatternProperties).length > 1) {
4702
+ patternProperties += `.catchall(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
4703
+ } else {
4704
+ patternProperties += `.catchall(${Object.values(parsedPatternProperties)})`;
4705
+ }
4706
+ } else {
4707
+ if (additionalProperties) {
4708
+ patternProperties += `z.record(z.union([${[
4709
+ ...Object.values(parsedPatternProperties),
4710
+ additionalProperties
4711
+ ].join(", ")}]))`;
4712
+ } else if (Object.keys(parsedPatternProperties).length > 1) {
4713
+ patternProperties += `z.record(z.union([${Object.values(parsedPatternProperties).join(", ")}]))`;
4714
+ } else {
4715
+ patternProperties += `z.record(${Object.values(parsedPatternProperties)})`;
4716
+ }
4717
+ }
4718
+ patternProperties += ".superRefine((value, ctx) => {\n";
4719
+ patternProperties += "for (const key in value) {\n";
4720
+ if (additionalProperties) {
4721
+ if (objectSchema.properties) {
4722
+ patternProperties += `let evaluated = [${Object.keys(objectSchema.properties).map((key) => JSON.stringify(key)).join(", ")}].includes(key)
4723
+ `;
4724
+ } else {
4725
+ patternProperties += `let evaluated = false
4726
+ `;
4727
+ }
4728
+ }
4729
+ for (const key in objectSchema.patternProperties) {
4730
+ patternProperties += "if (key.match(new RegExp(" + JSON.stringify(key) + "))) {\n";
4731
+ if (additionalProperties) {
4732
+ patternProperties += "evaluated = true\n";
4733
+ }
4734
+ patternProperties += "const result = " + parsedPatternProperties[key] + ".safeParse(value[key])\n";
4735
+ patternProperties += "if (!result.success) {\n";
4736
+ patternProperties += `ctx.addIssue({
4737
+ path: [...ctx.path, key],
4738
+ code: 'custom',
4739
+ message: \`Invalid input: Key matching regex /\${key}/ must match schema\`,
4740
+ params: {
4741
+ issues: result.error.issues
4742
+ }
4743
+ })
4744
+ `;
4745
+ patternProperties += "}\n";
4746
+ patternProperties += "}\n";
4747
+ }
4748
+ if (additionalProperties) {
4749
+ patternProperties += "if (!evaluated) {\n";
4750
+ patternProperties += "const result = " + additionalProperties + ".safeParse(value[key])\n";
4751
+ patternProperties += "if (!result.success) {\n";
4752
+ patternProperties += `ctx.addIssue({
4753
+ path: [...ctx.path, key],
4754
+ code: 'custom',
4755
+ message: \`Invalid input: must match catchall schema\`,
4756
+ params: {
4757
+ issues: result.error.issues
4758
+ }
4759
+ })
4760
+ `;
4761
+ patternProperties += "}\n";
4762
+ patternProperties += "}\n";
4763
+ }
4764
+ patternProperties += "}\n";
4765
+ patternProperties += "})";
4766
+ }
4767
+ let output = properties ? patternProperties ? properties + patternProperties : additionalProperties ? additionalProperties === "z.never()" ? properties + ".strict()" : properties + `.catchall(${additionalProperties})` : properties : patternProperties ? patternProperties : additionalProperties ? `z.record(${additionalProperties})` : "z.record(z.any())";
4768
+ if (its.an.anyOf(objectSchema)) {
4769
+ output += `.and(${parseAnyOf({
4770
+ anyOf: objectSchema.anyOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
4771
+ }, refs)})`;
4772
+ }
4773
+ if (its.a.oneOf(objectSchema)) {
4774
+ output += `.and(${parseOneOf({
4775
+ oneOf: objectSchema.oneOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
4776
+ }, refs)})`;
4777
+ }
4778
+ if (its.an.allOf(objectSchema)) {
4779
+ output += `.and(${parseAllOf({
4780
+ allOf: objectSchema.allOf.map((x) => typeof x === "object" && !x.type && (x.properties || x.additionalProperties || x.patternProperties) ? { ...x, type: "object" } : x)
4781
+ }, refs)})`;
4782
+ }
4783
+ return output;
4784
+ }
4785
+
4786
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseString.js
4787
+ var parseString = (schema) => {
4788
+ let r = "z.string()";
4789
+ r += withMessage(schema, "format", ({ value }) => {
4790
+ switch (value) {
4791
+ case "email":
4792
+ return [".email(", ")"];
4793
+ case "ip":
4794
+ return [".ip(", ")"];
4795
+ case "ipv4":
4796
+ return ['.ip({ version: "v4"', ", message: ", " })"];
4797
+ case "ipv6":
4798
+ return ['.ip({ version: "v6"', ", message: ", " })"];
4799
+ case "uri":
4800
+ return [".url(", ")"];
4801
+ case "uuid":
4802
+ return [".uuid(", ")"];
4803
+ case "date-time":
4804
+ return [".datetime({ offset: true", ", message: ", " })"];
4805
+ case "time":
4806
+ return [".time(", ")"];
4807
+ case "date":
4808
+ return [".date(", ")"];
4809
+ case "binary":
4810
+ return [".base64(", ")"];
4811
+ case "duration":
4812
+ return [".duration(", ")"];
4813
+ }
4814
+ });
4815
+ r += withMessage(schema, "pattern", ({ json }) => [
4816
+ `.regex(new RegExp(${json})`,
4817
+ ", ",
4818
+ ")"
4819
+ ]);
4820
+ r += withMessage(schema, "minLength", ({ json }) => [
4821
+ `.min(${json}`,
4822
+ ", ",
4823
+ ")"
4824
+ ]);
4825
+ r += withMessage(schema, "maxLength", ({ json }) => [
4826
+ `.max(${json}`,
4827
+ ", ",
4828
+ ")"
4829
+ ]);
4830
+ r += withMessage(schema, "contentEncoding", ({ value }) => {
4831
+ if (value === "base64") {
4832
+ return [".base64(", ")"];
4833
+ }
4834
+ });
4835
+ const contentMediaType = withMessage(schema, "contentMediaType", ({ value }) => {
4836
+ if (value === "application/json") {
4837
+ return [
4838
+ '.transform((str, ctx) => { try { return JSON.parse(str); } catch (err) { ctx.addIssue({ code: "custom", message: "Invalid JSON" }); }}',
4839
+ ", ",
4840
+ ")"
4841
+ ];
4842
+ }
4843
+ });
4844
+ if (contentMediaType != "") {
4845
+ r += contentMediaType;
4846
+ r += withMessage(schema, "contentSchema", ({ value }) => {
4847
+ if (value && value instanceof Object) {
4848
+ return [
4849
+ `.pipe(${parseSchema(value)}`,
4850
+ ", ",
4851
+ ")"
4852
+ ];
4853
+ }
4854
+ });
4855
+ }
4856
+ return r;
4857
+ };
4858
+
4859
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/utils/omit.js
4860
+ var omit = (obj, ...keys) => Object.keys(obj).reduce((acc, key) => {
4861
+ if (!keys.includes(key)) {
4862
+ acc[key] = obj[key];
4863
+ }
4864
+ return acc;
4865
+ }, {});
4866
+
4867
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseNullable.js
4868
+ var parseNullable = (schema, refs) => {
4869
+ return `${parseSchema(omit(schema, "nullable"), refs, true)}.nullable()`;
4870
+ };
4871
+
4872
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/parsers/parseSchema.js
4873
+ var parseSchema = (schema, refs = { seen: /* @__PURE__ */ new Map(), path: [] }, blockMeta) => {
4874
+ if (typeof schema !== "object")
4875
+ return schema ? "z.any()" : "z.never()";
4876
+ if (refs.parserOverride) {
4877
+ const custom2 = refs.parserOverride(schema, refs);
4878
+ if (typeof custom2 === "string") {
4879
+ return custom2;
4880
+ }
4881
+ }
4882
+ let seen = refs.seen.get(schema);
4883
+ if (seen) {
4884
+ if (seen.r !== void 0) {
4885
+ return seen.r;
4886
+ }
4887
+ if (refs.depth === void 0 || seen.n >= refs.depth) {
4888
+ return "z.any()";
4889
+ }
4890
+ seen.n += 1;
4891
+ } else {
4892
+ seen = { r: void 0, n: 0 };
4893
+ refs.seen.set(schema, seen);
4894
+ }
4895
+ let parsed = selectParser(schema, refs);
4896
+ if (!blockMeta) {
4897
+ if (!refs.withoutDescribes) {
4898
+ parsed = addDescribes(schema, parsed);
4899
+ }
4900
+ if (!refs.withoutDefaults) {
4901
+ parsed = addDefaults(schema, parsed);
4902
+ }
4903
+ parsed = addAnnotations(schema, parsed);
4904
+ }
4905
+ seen.r = parsed;
4906
+ return parsed;
4907
+ };
4908
+ var addDescribes = (schema, parsed) => {
4909
+ if (schema.description) {
4910
+ parsed += `.describe(${JSON.stringify(schema.description)})`;
4911
+ }
4912
+ return parsed;
4913
+ };
4914
+ var addDefaults = (schema, parsed) => {
4915
+ if (schema.default !== void 0) {
4916
+ parsed += `.default(${JSON.stringify(schema.default)})`;
4917
+ }
4918
+ return parsed;
4919
+ };
4920
+ var addAnnotations = (schema, parsed) => {
4921
+ if (schema.readOnly) {
4922
+ parsed += ".readonly()";
4923
+ }
4924
+ return parsed;
4925
+ };
4926
+ var selectParser = (schema, refs) => {
4927
+ if (its.a.nullable(schema)) {
4928
+ return parseNullable(schema, refs);
4929
+ } else if (its.an.object(schema)) {
4930
+ return parseObject(schema, refs);
4931
+ } else if (its.an.array(schema)) {
4932
+ return parseArray(schema, refs);
4933
+ } else if (its.an.anyOf(schema)) {
4934
+ return parseAnyOf(schema, refs);
4935
+ } else if (its.an.allOf(schema)) {
4936
+ return parseAllOf(schema, refs);
4937
+ } else if (its.a.oneOf(schema)) {
4938
+ return parseOneOf(schema, refs);
4939
+ } else if (its.a.not(schema)) {
4940
+ return parseNot(schema, refs);
4941
+ } else if (its.an.enum(schema)) {
4942
+ return parseEnum(schema);
4943
+ } else if (its.a.const(schema)) {
4944
+ return parseConst(schema);
4945
+ } else if (its.a.multipleType(schema)) {
4946
+ return parseMultipleType(schema, refs);
4947
+ } else if (its.a.primitive(schema, "string")) {
4948
+ return parseString(schema);
4949
+ } else if (its.a.primitive(schema, "number") || its.a.primitive(schema, "integer")) {
4950
+ return parseNumber(schema);
4951
+ } else if (its.a.primitive(schema, "boolean")) {
4952
+ return parseBoolean();
4953
+ } else if (its.a.primitive(schema, "null")) {
4954
+ return parseNull();
4955
+ } else if (its.a.conditional(schema)) {
4956
+ return parseIfThenElse(schema, refs);
4957
+ } else {
4958
+ return parseDefault();
4959
+ }
4960
+ };
4961
+ var its = {
4962
+ an: {
4963
+ object: (x) => x.type === "object",
4964
+ array: (x) => x.type === "array",
4965
+ anyOf: (x) => x.anyOf !== void 0,
4966
+ allOf: (x) => x.allOf !== void 0,
4967
+ enum: (x) => x.enum !== void 0
4968
+ },
4969
+ a: {
4970
+ nullable: (x) => x.nullable === true,
4971
+ multipleType: (x) => Array.isArray(x.type),
4972
+ not: (x) => x.not !== void 0,
4973
+ const: (x) => x.const !== void 0,
4974
+ primitive: (x, p) => x.type === p,
4975
+ conditional: (x) => Boolean("if" in x && x.if && "then" in x && "else" in x && x.then && x.else),
4976
+ oneOf: (x) => x.oneOf !== void 0
4977
+ }
4978
+ };
4979
+
4980
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/jsonSchemaToZod.js
4981
+ var jsonSchemaToZod = (schema, { module, name, type, noImport, ...rest } = {}) => {
4982
+ if (type && (!name || module !== "esm")) {
4983
+ throw new Error("Option `type` requires `name` to be set and `module` to be `esm`");
4984
+ }
4985
+ let result = parseSchema(schema, {
4986
+ module,
4987
+ name,
4988
+ path: [],
4989
+ seen: /* @__PURE__ */ new Map(),
4990
+ ...rest
4991
+ });
4992
+ const jsdocs = rest.withJsdocs && typeof schema !== "boolean" && schema.description ? expandJsdocs(schema.description) : "";
4993
+ if (module === "cjs") {
4994
+ result = `${jsdocs}module.exports = ${name ? `{ ${JSON.stringify(name)}: ${result} }` : result}
4995
+ `;
4996
+ if (!noImport) {
4997
+ result = `${jsdocs}const { z } = require("zod")
4998
+
4999
+ ${result}`;
5000
+ }
5001
+ } else if (module === "esm") {
5002
+ result = `${jsdocs}export ${name ? `const ${name} =` : `default`} ${result}
5003
+ `;
5004
+ if (!noImport) {
5005
+ result = `import { z } from "zod"
5006
+
5007
+ ${result}`;
5008
+ }
5009
+ } else if (name) {
5010
+ result = `${jsdocs}const ${name} = ${result}`;
5011
+ }
5012
+ if (type && name) {
5013
+ let typeName = typeof type === "string" ? type : `${name[0].toUpperCase()}${name.substring(1)}`;
5014
+ result += `export type ${typeName} = z.infer<typeof ${name}>
5015
+ `;
5016
+ }
5017
+ return result;
5018
+ };
5019
+
5020
+ // ../../node_modules/.pnpm/json-schema-to-zod@2.6.0/node_modules/json-schema-to-zod/dist/esm/index.js
5021
+ var esm_default = jsonSchemaToZod;
5022
+
5023
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/Options.js
5024
+ var ignoreOverride = Symbol("Let zodToJsonSchema decide on which parser to use");
5025
+ var defaultOptions = {
5026
+ name: void 0,
5027
+ $refStrategy: "root",
5028
+ basePath: ["#"],
5029
+ effectStrategy: "input",
5030
+ pipeStrategy: "all",
5031
+ dateStrategy: "format:date-time",
5032
+ mapStrategy: "entries",
5033
+ removeAdditionalStrategy: "passthrough",
5034
+ allowedAdditionalProperties: true,
5035
+ rejectedAdditionalProperties: false,
5036
+ definitionPath: "definitions",
5037
+ target: "jsonSchema7",
5038
+ strictUnions: false,
5039
+ definitions: {},
5040
+ errorMessages: false,
5041
+ markdownDescription: false,
5042
+ patternStrategy: "escape",
5043
+ applyRegexFlags: false,
5044
+ emailStrategy: "format:email",
5045
+ base64Strategy: "contentEncoding:base64",
5046
+ nameStrategy: "ref"
5047
+ };
5048
+ var getDefaultOptions = (options) => ({
5049
+ ...defaultOptions,
5050
+ ...options
5051
+ });
5052
+
5053
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/Refs.js
5054
+ var getRefs = (options) => {
5055
+ const _options = getDefaultOptions(options);
5056
+ const currentPath = _options.name !== void 0 ? [..._options.basePath, _options.definitionPath, _options.name] : _options.basePath;
5057
+ return {
5058
+ ..._options,
5059
+ currentPath,
5060
+ propertyPath: void 0,
5061
+ seen: new Map(Object.entries(_options.definitions).map(([name, def]) => [
5062
+ def._def,
5063
+ {
5064
+ def: def._def,
5065
+ path: [..._options.basePath, _options.definitionPath, name],
5066
+ // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now.
5067
+ jsonSchema: void 0
5068
+ }
5069
+ ]))
5070
+ };
5071
+ };
5072
+
5073
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/errorMessages.js
5074
+ function addErrorMessage(res, key, errorMessage, refs) {
5075
+ if (!refs?.errorMessages)
5076
+ return;
5077
+ if (errorMessage) {
5078
+ res.errorMessage = {
5079
+ ...res.errorMessage,
5080
+ [key]: errorMessage
5081
+ };
5082
+ }
5083
+ }
5084
+ function setResponseValueAndErrors(res, key, value, errorMessage, refs) {
5085
+ res[key] = value;
5086
+ addErrorMessage(res, key, errorMessage, refs);
5087
+ }
5088
+
5089
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/any.js
5090
+ function parseAnyDef() {
5091
+ return {};
5092
+ }
5093
+
5094
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/array.js
5095
+ function parseArrayDef(def, refs) {
5096
+ const res = {
5097
+ type: "array"
5098
+ };
5099
+ if (def.type?._def && def.type?._def?.typeName !== ZodFirstPartyTypeKind.ZodAny) {
5100
+ res.items = parseDef(def.type._def, {
5101
+ ...refs,
5102
+ currentPath: [...refs.currentPath, "items"]
5103
+ });
5104
+ }
5105
+ if (def.minLength) {
5106
+ setResponseValueAndErrors(res, "minItems", def.minLength.value, def.minLength.message, refs);
5107
+ }
5108
+ if (def.maxLength) {
5109
+ setResponseValueAndErrors(res, "maxItems", def.maxLength.value, def.maxLength.message, refs);
5110
+ }
5111
+ if (def.exactLength) {
5112
+ setResponseValueAndErrors(res, "minItems", def.exactLength.value, def.exactLength.message, refs);
5113
+ setResponseValueAndErrors(res, "maxItems", def.exactLength.value, def.exactLength.message, refs);
5114
+ }
5115
+ return res;
5116
+ }
5117
+
5118
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js
5119
+ function parseBigintDef(def, refs) {
5120
+ const res = {
5121
+ type: "integer",
5122
+ format: "int64"
5123
+ };
5124
+ if (!def.checks)
5125
+ return res;
5126
+ for (const check of def.checks) {
5127
+ switch (check.kind) {
5128
+ case "min":
5129
+ if (refs.target === "jsonSchema7") {
5130
+ if (check.inclusive) {
5131
+ setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
5132
+ } else {
5133
+ setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
5134
+ }
5135
+ } else {
5136
+ if (!check.inclusive) {
5137
+ res.exclusiveMinimum = true;
5138
+ }
5139
+ setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
5140
+ }
5141
+ break;
5142
+ case "max":
5143
+ if (refs.target === "jsonSchema7") {
5144
+ if (check.inclusive) {
5145
+ setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
5146
+ } else {
5147
+ setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
5148
+ }
5149
+ } else {
5150
+ if (!check.inclusive) {
5151
+ res.exclusiveMaximum = true;
5152
+ }
5153
+ setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
5154
+ }
5155
+ break;
5156
+ case "multipleOf":
5157
+ setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
5158
+ break;
5159
+ }
5160
+ }
5161
+ return res;
5162
+ }
5163
+
5164
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js
5165
+ function parseBooleanDef() {
5166
+ return {
5167
+ type: "boolean"
5168
+ };
5169
+ }
5170
+
5171
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js
5172
+ function parseBrandedDef(_def, refs) {
5173
+ return parseDef(_def.type._def, refs);
5174
+ }
5175
+
5176
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js
5177
+ var parseCatchDef = (def, refs) => {
5178
+ return parseDef(def.innerType._def, refs);
5179
+ };
5180
+
5181
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/date.js
5182
+ function parseDateDef(def, refs, overrideDateStrategy) {
5183
+ const strategy = overrideDateStrategy ?? refs.dateStrategy;
5184
+ if (Array.isArray(strategy)) {
5185
+ return {
5186
+ anyOf: strategy.map((item, i) => parseDateDef(def, refs, item))
5187
+ };
5188
+ }
5189
+ switch (strategy) {
5190
+ case "string":
5191
+ case "format:date-time":
5192
+ return {
5193
+ type: "string",
5194
+ format: "date-time"
5195
+ };
5196
+ case "format:date":
5197
+ return {
5198
+ type: "string",
5199
+ format: "date"
5200
+ };
5201
+ case "integer":
5202
+ return integerDateParser(def, refs);
5203
+ }
5204
+ }
5205
+ var integerDateParser = (def, refs) => {
5206
+ const res = {
5207
+ type: "integer",
5208
+ format: "unix-time"
5209
+ };
5210
+ if (refs.target === "openApi3") {
5211
+ return res;
5212
+ }
5213
+ for (const check of def.checks) {
5214
+ switch (check.kind) {
5215
+ case "min":
5216
+ setResponseValueAndErrors(
5217
+ res,
5218
+ "minimum",
5219
+ check.value,
5220
+ // This is in milliseconds
5221
+ check.message,
5222
+ refs
5223
+ );
5224
+ break;
5225
+ case "max":
5226
+ setResponseValueAndErrors(
5227
+ res,
5228
+ "maximum",
5229
+ check.value,
5230
+ // This is in milliseconds
5231
+ check.message,
5232
+ refs
5233
+ );
5234
+ break;
5235
+ }
5236
+ }
5237
+ return res;
5238
+ };
5239
+
5240
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/default.js
5241
+ function parseDefaultDef(_def, refs) {
5242
+ return {
5243
+ ...parseDef(_def.innerType._def, refs),
5244
+ default: _def.defaultValue()
5245
+ };
5246
+ }
5247
+
5248
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js
5249
+ function parseEffectsDef(_def, refs) {
5250
+ return refs.effectStrategy === "input" ? parseDef(_def.schema._def, refs) : {};
5251
+ }
5252
+
5253
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js
5254
+ function parseEnumDef(def) {
5255
+ return {
5256
+ type: "string",
5257
+ enum: Array.from(def.values)
5258
+ };
5259
+ }
5260
+
5261
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js
5262
+ var isJsonSchema7AllOfType = (type) => {
5263
+ if ("type" in type && type.type === "string")
5264
+ return false;
5265
+ return "allOf" in type;
5266
+ };
5267
+ function parseIntersectionDef(def, refs) {
5268
+ const allOf = [
5269
+ parseDef(def.left._def, {
5270
+ ...refs,
5271
+ currentPath: [...refs.currentPath, "allOf", "0"]
5272
+ }),
5273
+ parseDef(def.right._def, {
5274
+ ...refs,
5275
+ currentPath: [...refs.currentPath, "allOf", "1"]
5276
+ })
5277
+ ].filter((x) => !!x);
5278
+ let unevaluatedProperties = refs.target === "jsonSchema2019-09" ? { unevaluatedProperties: false } : void 0;
5279
+ const mergedAllOf = [];
5280
+ allOf.forEach((schema) => {
5281
+ if (isJsonSchema7AllOfType(schema)) {
5282
+ mergedAllOf.push(...schema.allOf);
5283
+ if (schema.unevaluatedProperties === void 0) {
5284
+ unevaluatedProperties = void 0;
5285
+ }
5286
+ } else {
5287
+ let nestedSchema = schema;
5288
+ if ("additionalProperties" in schema && schema.additionalProperties === false) {
5289
+ const { additionalProperties, ...rest } = schema;
5290
+ nestedSchema = rest;
5291
+ } else {
5292
+ unevaluatedProperties = void 0;
5293
+ }
5294
+ mergedAllOf.push(nestedSchema);
5295
+ }
5296
+ });
5297
+ return mergedAllOf.length ? {
5298
+ allOf: mergedAllOf,
5299
+ ...unevaluatedProperties
5300
+ } : void 0;
5301
+ }
5302
+
5303
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js
5304
+ function parseLiteralDef(def, refs) {
5305
+ const parsedType = typeof def.value;
5306
+ if (parsedType !== "bigint" && parsedType !== "number" && parsedType !== "boolean" && parsedType !== "string") {
5307
+ return {
5308
+ type: Array.isArray(def.value) ? "array" : "object"
5309
+ };
5310
+ }
5311
+ if (refs.target === "openApi3") {
5312
+ return {
5313
+ type: parsedType === "bigint" ? "integer" : parsedType,
5314
+ enum: [def.value]
5315
+ };
5316
+ }
5317
+ return {
5318
+ type: parsedType === "bigint" ? "integer" : parsedType,
5319
+ const: def.value
5320
+ };
5321
+ }
5322
+
5323
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/string.js
5324
+ var emojiRegex2 = void 0;
5325
+ var zodPatterns = {
5326
+ /**
5327
+ * `c` was changed to `[cC]` to replicate /i flag
5328
+ */
5329
+ cuid: /^[cC][^\s-]{8,}$/,
5330
+ cuid2: /^[0-9a-z]+$/,
5331
+ ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/,
5332
+ /**
5333
+ * `a-z` was added to replicate /i flag
5334
+ */
5335
+ email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/,
5336
+ /**
5337
+ * Constructed a valid Unicode RegExp
5338
+ *
5339
+ * Lazily instantiate since this type of regex isn't supported
5340
+ * in all envs (e.g. React Native).
5341
+ *
5342
+ * See:
5343
+ * https://github.com/colinhacks/zod/issues/2433
5344
+ * Fix in Zod:
5345
+ * https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b
5346
+ */
5347
+ emoji: () => {
5348
+ if (emojiRegex2 === void 0) {
5349
+ emojiRegex2 = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u");
5350
+ }
5351
+ return emojiRegex2;
5352
+ },
5353
+ /**
5354
+ * Unused
5355
+ */
5356
+ uuid: /^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/,
5357
+ /**
5358
+ * Unused
5359
+ */
5360
+ ipv4: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,
5361
+ ipv4Cidr: /^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,
5362
+ /**
5363
+ * Unused
5364
+ */
5365
+ ipv6: /^(([a-f0-9]{1,4}:){7}|::([a-f0-9]{1,4}:){0,6}|([a-f0-9]{1,4}:){1}:([a-f0-9]{1,4}:){0,5}|([a-f0-9]{1,4}:){2}:([a-f0-9]{1,4}:){0,4}|([a-f0-9]{1,4}:){3}:([a-f0-9]{1,4}:){0,3}|([a-f0-9]{1,4}:){4}:([a-f0-9]{1,4}:){0,2}|([a-f0-9]{1,4}:){5}:([a-f0-9]{1,4}:){0,1})([a-f0-9]{1,4}|(((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2}))\.){3}((25[0-5])|(2[0-4][0-9])|(1[0-9]{2})|([0-9]{1,2})))$/,
5366
+ ipv6Cidr: /^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,
5367
+ base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,
5368
+ base64url: /^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,
5369
+ nanoid: /^[a-zA-Z0-9_-]{21}$/,
5370
+ jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
5371
+ };
5372
+ function parseStringDef(def, refs) {
5373
+ const res = {
5374
+ type: "string"
5375
+ };
5376
+ if (def.checks) {
5377
+ for (const check of def.checks) {
5378
+ switch (check.kind) {
5379
+ case "min":
5380
+ setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
5381
+ break;
5382
+ case "max":
5383
+ setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
5384
+ break;
5385
+ case "email":
5386
+ switch (refs.emailStrategy) {
5387
+ case "format:email":
5388
+ addFormat(res, "email", check.message, refs);
5389
+ break;
5390
+ case "format:idn-email":
5391
+ addFormat(res, "idn-email", check.message, refs);
5392
+ break;
5393
+ case "pattern:zod":
5394
+ addPattern(res, zodPatterns.email, check.message, refs);
5395
+ break;
5396
+ }
5397
+ break;
5398
+ case "url":
5399
+ addFormat(res, "uri", check.message, refs);
5400
+ break;
5401
+ case "uuid":
5402
+ addFormat(res, "uuid", check.message, refs);
5403
+ break;
5404
+ case "regex":
5405
+ addPattern(res, check.regex, check.message, refs);
5406
+ break;
5407
+ case "cuid":
5408
+ addPattern(res, zodPatterns.cuid, check.message, refs);
5409
+ break;
5410
+ case "cuid2":
5411
+ addPattern(res, zodPatterns.cuid2, check.message, refs);
5412
+ break;
5413
+ case "startsWith":
5414
+ addPattern(res, RegExp(`^${escapeLiteralCheckValue(check.value, refs)}`), check.message, refs);
5415
+ break;
5416
+ case "endsWith":
5417
+ addPattern(res, RegExp(`${escapeLiteralCheckValue(check.value, refs)}$`), check.message, refs);
5418
+ break;
5419
+ case "datetime":
5420
+ addFormat(res, "date-time", check.message, refs);
5421
+ break;
5422
+ case "date":
5423
+ addFormat(res, "date", check.message, refs);
5424
+ break;
5425
+ case "time":
5426
+ addFormat(res, "time", check.message, refs);
5427
+ break;
5428
+ case "duration":
5429
+ addFormat(res, "duration", check.message, refs);
5430
+ break;
5431
+ case "length":
5432
+ setResponseValueAndErrors(res, "minLength", typeof res.minLength === "number" ? Math.max(res.minLength, check.value) : check.value, check.message, refs);
5433
+ setResponseValueAndErrors(res, "maxLength", typeof res.maxLength === "number" ? Math.min(res.maxLength, check.value) : check.value, check.message, refs);
5434
+ break;
5435
+ case "includes": {
5436
+ addPattern(res, RegExp(escapeLiteralCheckValue(check.value, refs)), check.message, refs);
5437
+ break;
5438
+ }
5439
+ case "ip": {
5440
+ if (check.version !== "v6") {
5441
+ addFormat(res, "ipv4", check.message, refs);
5442
+ }
5443
+ if (check.version !== "v4") {
5444
+ addFormat(res, "ipv6", check.message, refs);
5445
+ }
5446
+ break;
5447
+ }
5448
+ case "base64url":
5449
+ addPattern(res, zodPatterns.base64url, check.message, refs);
5450
+ break;
5451
+ case "jwt":
5452
+ addPattern(res, zodPatterns.jwt, check.message, refs);
5453
+ break;
5454
+ case "cidr": {
5455
+ if (check.version !== "v6") {
5456
+ addPattern(res, zodPatterns.ipv4Cidr, check.message, refs);
5457
+ }
5458
+ if (check.version !== "v4") {
5459
+ addPattern(res, zodPatterns.ipv6Cidr, check.message, refs);
5460
+ }
5461
+ break;
5462
+ }
5463
+ case "emoji":
5464
+ addPattern(res, zodPatterns.emoji(), check.message, refs);
5465
+ break;
5466
+ case "ulid": {
5467
+ addPattern(res, zodPatterns.ulid, check.message, refs);
5468
+ break;
5469
+ }
5470
+ case "base64": {
5471
+ switch (refs.base64Strategy) {
5472
+ case "format:binary": {
5473
+ addFormat(res, "binary", check.message, refs);
5474
+ break;
5475
+ }
5476
+ case "contentEncoding:base64": {
5477
+ setResponseValueAndErrors(res, "contentEncoding", "base64", check.message, refs);
5478
+ break;
5479
+ }
5480
+ case "pattern:zod": {
5481
+ addPattern(res, zodPatterns.base64, check.message, refs);
5482
+ break;
5483
+ }
5484
+ }
5485
+ break;
5486
+ }
5487
+ case "nanoid": {
5488
+ addPattern(res, zodPatterns.nanoid, check.message, refs);
5489
+ }
5490
+ }
5491
+ }
5492
+ }
5493
+ return res;
5494
+ }
5495
+ function escapeLiteralCheckValue(literal, refs) {
5496
+ return refs.patternStrategy === "escape" ? escapeNonAlphaNumeric(literal) : literal;
5497
+ }
5498
+ var ALPHA_NUMERIC = new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
5499
+ function escapeNonAlphaNumeric(source) {
5500
+ let result = "";
5501
+ for (let i = 0; i < source.length; i++) {
5502
+ if (!ALPHA_NUMERIC.has(source[i])) {
5503
+ result += "\\";
5504
+ }
5505
+ result += source[i];
5506
+ }
5507
+ return result;
5508
+ }
5509
+ function addFormat(schema, value, message, refs) {
5510
+ if (schema.format || schema.anyOf?.some((x) => x.format)) {
5511
+ if (!schema.anyOf) {
5512
+ schema.anyOf = [];
5513
+ }
5514
+ if (schema.format) {
5515
+ schema.anyOf.push({
5516
+ format: schema.format,
5517
+ ...schema.errorMessage && refs.errorMessages && {
5518
+ errorMessage: { format: schema.errorMessage.format }
5519
+ }
5520
+ });
5521
+ delete schema.format;
5522
+ if (schema.errorMessage) {
5523
+ delete schema.errorMessage.format;
5524
+ if (Object.keys(schema.errorMessage).length === 0) {
5525
+ delete schema.errorMessage;
5526
+ }
5527
+ }
5528
+ }
5529
+ schema.anyOf.push({
5530
+ format: value,
5531
+ ...message && refs.errorMessages && { errorMessage: { format: message } }
5532
+ });
5533
+ } else {
5534
+ setResponseValueAndErrors(schema, "format", value, message, refs);
5535
+ }
5536
+ }
5537
+ function addPattern(schema, regex, message, refs) {
5538
+ if (schema.pattern || schema.allOf?.some((x) => x.pattern)) {
5539
+ if (!schema.allOf) {
5540
+ schema.allOf = [];
5541
+ }
5542
+ if (schema.pattern) {
5543
+ schema.allOf.push({
5544
+ pattern: schema.pattern,
5545
+ ...schema.errorMessage && refs.errorMessages && {
5546
+ errorMessage: { pattern: schema.errorMessage.pattern }
5547
+ }
5548
+ });
5549
+ delete schema.pattern;
5550
+ if (schema.errorMessage) {
5551
+ delete schema.errorMessage.pattern;
5552
+ if (Object.keys(schema.errorMessage).length === 0) {
5553
+ delete schema.errorMessage;
5554
+ }
5555
+ }
5556
+ }
5557
+ schema.allOf.push({
5558
+ pattern: stringifyRegExpWithFlags(regex, refs),
5559
+ ...message && refs.errorMessages && { errorMessage: { pattern: message } }
5560
+ });
5561
+ } else {
5562
+ setResponseValueAndErrors(schema, "pattern", stringifyRegExpWithFlags(regex, refs), message, refs);
5563
+ }
5564
+ }
5565
+ function stringifyRegExpWithFlags(regex, refs) {
5566
+ if (!refs.applyRegexFlags || !regex.flags) {
5567
+ return regex.source;
5568
+ }
5569
+ const flags = {
5570
+ i: regex.flags.includes("i"),
5571
+ m: regex.flags.includes("m"),
5572
+ s: regex.flags.includes("s")
5573
+ // `.` matches newlines
5574
+ };
5575
+ const source = flags.i ? regex.source.toLowerCase() : regex.source;
5576
+ let pattern = "";
5577
+ let isEscaped = false;
5578
+ let inCharGroup = false;
5579
+ let inCharRange = false;
5580
+ for (let i = 0; i < source.length; i++) {
5581
+ if (isEscaped) {
5582
+ pattern += source[i];
5583
+ isEscaped = false;
5584
+ continue;
5585
+ }
5586
+ if (flags.i) {
5587
+ if (inCharGroup) {
5588
+ if (source[i].match(/[a-z]/)) {
5589
+ if (inCharRange) {
5590
+ pattern += source[i];
5591
+ pattern += `${source[i - 2]}-${source[i]}`.toUpperCase();
5592
+ inCharRange = false;
5593
+ } else if (source[i + 1] === "-" && source[i + 2]?.match(/[a-z]/)) {
5594
+ pattern += source[i];
5595
+ inCharRange = true;
5596
+ } else {
5597
+ pattern += `${source[i]}${source[i].toUpperCase()}`;
5598
+ }
5599
+ continue;
5600
+ }
5601
+ } else if (source[i].match(/[a-z]/)) {
5602
+ pattern += `[${source[i]}${source[i].toUpperCase()}]`;
5603
+ continue;
5604
+ }
5605
+ }
5606
+ if (flags.m) {
5607
+ if (source[i] === "^") {
5608
+ pattern += `(^|(?<=[\r
5609
+ ]))`;
5610
+ continue;
5611
+ } else if (source[i] === "$") {
5612
+ pattern += `($|(?=[\r
5613
+ ]))`;
5614
+ continue;
5615
+ }
5616
+ }
5617
+ if (flags.s && source[i] === ".") {
5618
+ pattern += inCharGroup ? `${source[i]}\r
5619
+ ` : `[${source[i]}\r
5620
+ ]`;
5621
+ continue;
5622
+ }
5623
+ pattern += source[i];
5624
+ if (source[i] === "\\") {
5625
+ isEscaped = true;
5626
+ } else if (inCharGroup && source[i] === "]") {
5627
+ inCharGroup = false;
5628
+ } else if (!inCharGroup && source[i] === "[") {
5629
+ inCharGroup = true;
5630
+ }
5631
+ }
5632
+ return pattern;
5633
+ }
5634
+
5635
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/record.js
5636
+ function parseRecordDef(def, refs) {
5637
+ if (refs.target === "openAi") {
5638
+ console.warn("Warning: OpenAI may not support records in schemas! Try an array of key-value pairs instead.");
5639
+ }
5640
+ if (refs.target === "openApi3" && def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
5641
+ return {
5642
+ type: "object",
5643
+ required: def.keyType._def.values,
5644
+ properties: def.keyType._def.values.reduce((acc, key) => ({
5645
+ ...acc,
5646
+ [key]: parseDef(def.valueType._def, {
5647
+ ...refs,
5648
+ currentPath: [...refs.currentPath, "properties", key]
5649
+ }) ?? {}
5650
+ }), {}),
5651
+ additionalProperties: refs.rejectedAdditionalProperties
5652
+ };
5653
+ }
5654
+ const schema = {
5655
+ type: "object",
5656
+ additionalProperties: parseDef(def.valueType._def, {
5657
+ ...refs,
5658
+ currentPath: [...refs.currentPath, "additionalProperties"]
5659
+ }) ?? refs.allowedAdditionalProperties
5660
+ };
5661
+ if (refs.target === "openApi3") {
5662
+ return schema;
5663
+ }
5664
+ if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.checks?.length) {
5665
+ const { type, ...keyType } = parseStringDef(def.keyType._def, refs);
5666
+ return {
5667
+ ...schema,
5668
+ propertyNames: keyType
5669
+ };
5670
+ } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodEnum) {
5671
+ return {
5672
+ ...schema,
5673
+ propertyNames: {
5674
+ enum: def.keyType._def.values
5675
+ }
5676
+ };
5677
+ } else if (def.keyType?._def.typeName === ZodFirstPartyTypeKind.ZodBranded && def.keyType._def.type._def.typeName === ZodFirstPartyTypeKind.ZodString && def.keyType._def.type._def.checks?.length) {
5678
+ const { type, ...keyType } = parseBrandedDef(def.keyType._def, refs);
5679
+ return {
5680
+ ...schema,
5681
+ propertyNames: keyType
5682
+ };
5683
+ }
5684
+ return schema;
5685
+ }
5686
+
5687
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/map.js
5688
+ function parseMapDef(def, refs) {
5689
+ if (refs.mapStrategy === "record") {
5690
+ return parseRecordDef(def, refs);
5691
+ }
5692
+ const keys = parseDef(def.keyType._def, {
5693
+ ...refs,
5694
+ currentPath: [...refs.currentPath, "items", "items", "0"]
5695
+ }) || {};
5696
+ const values = parseDef(def.valueType._def, {
5697
+ ...refs,
5698
+ currentPath: [...refs.currentPath, "items", "items", "1"]
5699
+ }) || {};
5700
+ return {
5701
+ type: "array",
5702
+ maxItems: 125,
5703
+ items: {
5704
+ type: "array",
5705
+ items: [keys, values],
5706
+ minItems: 2,
5707
+ maxItems: 2
5708
+ }
5709
+ };
5710
+ }
5711
+
5712
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js
5713
+ function parseNativeEnumDef(def) {
5714
+ const object = def.values;
5715
+ const actualKeys = Object.keys(def.values).filter((key) => {
5716
+ return typeof object[object[key]] !== "number";
5717
+ });
5718
+ const actualValues = actualKeys.map((key) => object[key]);
5719
+ const parsedTypes = Array.from(new Set(actualValues.map((values) => typeof values)));
5720
+ return {
5721
+ type: parsedTypes.length === 1 ? parsedTypes[0] === "string" ? "string" : "number" : ["string", "number"],
5722
+ enum: actualValues
5723
+ };
5724
+ }
5725
+
5726
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/never.js
5727
+ function parseNeverDef() {
5728
+ return {
5729
+ not: {}
5730
+ };
5731
+ }
5732
+
5733
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/null.js
5734
+ function parseNullDef(refs) {
5735
+ return refs.target === "openApi3" ? {
5736
+ enum: ["null"],
5737
+ nullable: true
5738
+ } : {
5739
+ type: "null"
5740
+ };
5741
+ }
5742
+
5743
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/union.js
5744
+ var primitiveMappings = {
5745
+ ZodString: "string",
5746
+ ZodNumber: "number",
5747
+ ZodBigInt: "integer",
5748
+ ZodBoolean: "boolean",
5749
+ ZodNull: "null"
5750
+ };
5751
+ function parseUnionDef(def, refs) {
5752
+ if (refs.target === "openApi3")
5753
+ return asAnyOf(def, refs);
5754
+ const options = def.options instanceof Map ? Array.from(def.options.values()) : def.options;
5755
+ if (options.every((x) => x._def.typeName in primitiveMappings && (!x._def.checks || !x._def.checks.length))) {
5756
+ const types = options.reduce((types2, x) => {
5757
+ const type = primitiveMappings[x._def.typeName];
5758
+ return type && !types2.includes(type) ? [...types2, type] : types2;
5759
+ }, []);
5760
+ return {
5761
+ type: types.length > 1 ? types : types[0]
5762
+ };
5763
+ } else if (options.every((x) => x._def.typeName === "ZodLiteral" && !x.description)) {
5764
+ const types = options.reduce((acc, x) => {
5765
+ const type = typeof x._def.value;
5766
+ switch (type) {
5767
+ case "string":
5768
+ case "number":
5769
+ case "boolean":
5770
+ return [...acc, type];
5771
+ case "bigint":
5772
+ return [...acc, "integer"];
5773
+ case "object":
5774
+ if (x._def.value === null)
5775
+ return [...acc, "null"];
5776
+ case "symbol":
5777
+ case "undefined":
5778
+ case "function":
5779
+ default:
5780
+ return acc;
5781
+ }
5782
+ }, []);
5783
+ if (types.length === options.length) {
5784
+ const uniqueTypes = types.filter((x, i, a) => a.indexOf(x) === i);
5785
+ return {
5786
+ type: uniqueTypes.length > 1 ? uniqueTypes : uniqueTypes[0],
5787
+ enum: options.reduce((acc, x) => {
5788
+ return acc.includes(x._def.value) ? acc : [...acc, x._def.value];
5789
+ }, [])
5790
+ };
5791
+ }
5792
+ } else if (options.every((x) => x._def.typeName === "ZodEnum")) {
5793
+ return {
5794
+ type: "string",
5795
+ enum: options.reduce((acc, x) => [
5796
+ ...acc,
5797
+ ...x._def.values.filter((x2) => !acc.includes(x2))
5798
+ ], [])
5799
+ };
5800
+ }
5801
+ return asAnyOf(def, refs);
5802
+ }
5803
+ var asAnyOf = (def, refs) => {
5804
+ const anyOf = (def.options instanceof Map ? Array.from(def.options.values()) : def.options).map((x, i) => parseDef(x._def, {
5805
+ ...refs,
5806
+ currentPath: [...refs.currentPath, "anyOf", `${i}`]
5807
+ })).filter((x) => !!x && (!refs.strictUnions || typeof x === "object" && Object.keys(x).length > 0));
5808
+ return anyOf.length ? { anyOf } : void 0;
5809
+ };
5810
+
5811
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js
5812
+ function parseNullableDef(def, refs) {
5813
+ if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(def.innerType._def.typeName) && (!def.innerType._def.checks || !def.innerType._def.checks.length)) {
5814
+ if (refs.target === "openApi3") {
5815
+ return {
5816
+ type: primitiveMappings[def.innerType._def.typeName],
5817
+ nullable: true
5818
+ };
5819
+ }
5820
+ return {
5821
+ type: [
5822
+ primitiveMappings[def.innerType._def.typeName],
5823
+ "null"
5824
+ ]
5825
+ };
5826
+ }
5827
+ if (refs.target === "openApi3") {
5828
+ const base2 = parseDef(def.innerType._def, {
5829
+ ...refs,
5830
+ currentPath: [...refs.currentPath]
5831
+ });
5832
+ if (base2 && "$ref" in base2)
5833
+ return { allOf: [base2], nullable: true };
5834
+ return base2 && { ...base2, nullable: true };
5835
+ }
5836
+ const base = parseDef(def.innerType._def, {
5837
+ ...refs,
5838
+ currentPath: [...refs.currentPath, "anyOf", "0"]
5839
+ });
5840
+ return base && { anyOf: [base, { type: "null" }] };
5841
+ }
5842
+
5843
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/number.js
5844
+ function parseNumberDef(def, refs) {
5845
+ const res = {
5846
+ type: "number"
5847
+ };
5848
+ if (!def.checks)
5849
+ return res;
5850
+ for (const check of def.checks) {
5851
+ switch (check.kind) {
5852
+ case "int":
5853
+ res.type = "integer";
5854
+ addErrorMessage(res, "type", check.message, refs);
5855
+ break;
5856
+ case "min":
5857
+ if (refs.target === "jsonSchema7") {
5858
+ if (check.inclusive) {
5859
+ setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
5860
+ } else {
5861
+ setResponseValueAndErrors(res, "exclusiveMinimum", check.value, check.message, refs);
5862
+ }
5863
+ } else {
5864
+ if (!check.inclusive) {
5865
+ res.exclusiveMinimum = true;
5866
+ }
5867
+ setResponseValueAndErrors(res, "minimum", check.value, check.message, refs);
5868
+ }
5869
+ break;
5870
+ case "max":
5871
+ if (refs.target === "jsonSchema7") {
5872
+ if (check.inclusive) {
5873
+ setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
5874
+ } else {
5875
+ setResponseValueAndErrors(res, "exclusiveMaximum", check.value, check.message, refs);
5876
+ }
5877
+ } else {
5878
+ if (!check.inclusive) {
5879
+ res.exclusiveMaximum = true;
5880
+ }
5881
+ setResponseValueAndErrors(res, "maximum", check.value, check.message, refs);
5882
+ }
5883
+ break;
5884
+ case "multipleOf":
5885
+ setResponseValueAndErrors(res, "multipleOf", check.value, check.message, refs);
5886
+ break;
5887
+ }
5888
+ }
5889
+ return res;
5890
+ }
5891
+
5892
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/object.js
5893
+ function parseObjectDef(def, refs) {
5894
+ const forceOptionalIntoNullable = refs.target === "openAi";
5895
+ const result = {
5896
+ type: "object",
5897
+ properties: {}
5898
+ };
5899
+ const required = [];
5900
+ const shape = def.shape();
5901
+ for (const propName in shape) {
5902
+ let propDef = shape[propName];
5903
+ if (propDef === void 0 || propDef._def === void 0) {
5904
+ continue;
5905
+ }
5906
+ let propOptional = safeIsOptional(propDef);
5907
+ if (propOptional && forceOptionalIntoNullable) {
5908
+ if (propDef instanceof ZodOptional) {
5909
+ propDef = propDef._def.innerType;
5910
+ }
5911
+ if (!propDef.isNullable()) {
5912
+ propDef = propDef.nullable();
5913
+ }
5914
+ propOptional = false;
5915
+ }
5916
+ const parsedDef = parseDef(propDef._def, {
5917
+ ...refs,
5918
+ currentPath: [...refs.currentPath, "properties", propName],
5919
+ propertyPath: [...refs.currentPath, "properties", propName]
5920
+ });
5921
+ if (parsedDef === void 0) {
5922
+ continue;
5923
+ }
5924
+ result.properties[propName] = parsedDef;
5925
+ if (!propOptional) {
5926
+ required.push(propName);
5927
+ }
5928
+ }
5929
+ if (required.length) {
5930
+ result.required = required;
5931
+ }
5932
+ const additionalProperties = decideAdditionalProperties(def, refs);
5933
+ if (additionalProperties !== void 0) {
5934
+ result.additionalProperties = additionalProperties;
5935
+ }
5936
+ return result;
5937
+ }
5938
+ function decideAdditionalProperties(def, refs) {
5939
+ if (def.catchall._def.typeName !== "ZodNever") {
5940
+ return parseDef(def.catchall._def, {
5941
+ ...refs,
5942
+ currentPath: [...refs.currentPath, "additionalProperties"]
5943
+ });
5944
+ }
5945
+ switch (def.unknownKeys) {
5946
+ case "passthrough":
5947
+ return refs.allowedAdditionalProperties;
5948
+ case "strict":
5949
+ return refs.rejectedAdditionalProperties;
5950
+ case "strip":
5951
+ return refs.removeAdditionalStrategy === "strict" ? refs.allowedAdditionalProperties : refs.rejectedAdditionalProperties;
5952
+ }
5953
+ }
5954
+ function safeIsOptional(schema) {
5955
+ try {
5956
+ return schema.isOptional();
5957
+ } catch {
5958
+ return true;
5959
+ }
5960
+ }
5961
+
5962
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js
5963
+ var parseOptionalDef = (def, refs) => {
5964
+ if (refs.currentPath.toString() === refs.propertyPath?.toString()) {
5965
+ return parseDef(def.innerType._def, refs);
5966
+ }
5967
+ const innerSchema = parseDef(def.innerType._def, {
5968
+ ...refs,
5969
+ currentPath: [...refs.currentPath, "anyOf", "1"]
5970
+ });
5971
+ return innerSchema ? {
5972
+ anyOf: [
5973
+ {
5974
+ not: {}
5975
+ },
5976
+ innerSchema
5977
+ ]
5978
+ } : {};
5979
+ };
5980
+
5981
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js
5982
+ var parsePipelineDef = (def, refs) => {
5983
+ if (refs.pipeStrategy === "input") {
5984
+ return parseDef(def.in._def, refs);
5985
+ } else if (refs.pipeStrategy === "output") {
5986
+ return parseDef(def.out._def, refs);
5987
+ }
5988
+ const a = parseDef(def.in._def, {
5989
+ ...refs,
5990
+ currentPath: [...refs.currentPath, "allOf", "0"]
5991
+ });
5992
+ const b = parseDef(def.out._def, {
5993
+ ...refs,
5994
+ currentPath: [...refs.currentPath, "allOf", a ? "1" : "0"]
5995
+ });
5996
+ return {
5997
+ allOf: [a, b].filter((x) => x !== void 0)
5998
+ };
5999
+ };
6000
+
6001
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js
6002
+ function parsePromiseDef(def, refs) {
6003
+ return parseDef(def.type._def, refs);
6004
+ }
6005
+
6006
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/set.js
6007
+ function parseSetDef(def, refs) {
6008
+ const items = parseDef(def.valueType._def, {
6009
+ ...refs,
6010
+ currentPath: [...refs.currentPath, "items"]
6011
+ });
6012
+ const schema = {
6013
+ type: "array",
6014
+ uniqueItems: true,
6015
+ items
6016
+ };
6017
+ if (def.minSize) {
6018
+ setResponseValueAndErrors(schema, "minItems", def.minSize.value, def.minSize.message, refs);
6019
+ }
6020
+ if (def.maxSize) {
6021
+ setResponseValueAndErrors(schema, "maxItems", def.maxSize.value, def.maxSize.message, refs);
6022
+ }
6023
+ return schema;
6024
+ }
6025
+
6026
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js
6027
+ function parseTupleDef(def, refs) {
6028
+ if (def.rest) {
6029
+ return {
6030
+ type: "array",
6031
+ minItems: def.items.length,
6032
+ items: def.items.map((x, i) => parseDef(x._def, {
6033
+ ...refs,
6034
+ currentPath: [...refs.currentPath, "items", `${i}`]
6035
+ })).reduce((acc, x) => x === void 0 ? acc : [...acc, x], []),
6036
+ additionalItems: parseDef(def.rest._def, {
6037
+ ...refs,
6038
+ currentPath: [...refs.currentPath, "additionalItems"]
6039
+ })
6040
+ };
6041
+ } else {
6042
+ return {
6043
+ type: "array",
6044
+ minItems: def.items.length,
6045
+ maxItems: def.items.length,
6046
+ items: def.items.map((x, i) => parseDef(x._def, {
6047
+ ...refs,
6048
+ currentPath: [...refs.currentPath, "items", `${i}`]
6049
+ })).reduce((acc, x) => x === void 0 ? acc : [...acc, x], [])
6050
+ };
6051
+ }
6052
+ }
6053
+
6054
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js
6055
+ function parseUndefinedDef() {
6056
+ return {
6057
+ not: {}
6058
+ };
6059
+ }
6060
+
6061
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js
6062
+ function parseUnknownDef() {
6063
+ return {};
6064
+ }
6065
+
6066
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js
6067
+ var parseReadonlyDef = (def, refs) => {
6068
+ return parseDef(def.innerType._def, refs);
6069
+ };
6070
+
6071
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/selectParser.js
6072
+ var selectParser2 = (def, typeName, refs) => {
6073
+ switch (typeName) {
6074
+ case ZodFirstPartyTypeKind.ZodString:
6075
+ return parseStringDef(def, refs);
6076
+ case ZodFirstPartyTypeKind.ZodNumber:
6077
+ return parseNumberDef(def, refs);
6078
+ case ZodFirstPartyTypeKind.ZodObject:
6079
+ return parseObjectDef(def, refs);
6080
+ case ZodFirstPartyTypeKind.ZodBigInt:
6081
+ return parseBigintDef(def, refs);
6082
+ case ZodFirstPartyTypeKind.ZodBoolean:
6083
+ return parseBooleanDef();
6084
+ case ZodFirstPartyTypeKind.ZodDate:
6085
+ return parseDateDef(def, refs);
6086
+ case ZodFirstPartyTypeKind.ZodUndefined:
6087
+ return parseUndefinedDef();
6088
+ case ZodFirstPartyTypeKind.ZodNull:
6089
+ return parseNullDef(refs);
6090
+ case ZodFirstPartyTypeKind.ZodArray:
6091
+ return parseArrayDef(def, refs);
6092
+ case ZodFirstPartyTypeKind.ZodUnion:
6093
+ case ZodFirstPartyTypeKind.ZodDiscriminatedUnion:
6094
+ return parseUnionDef(def, refs);
6095
+ case ZodFirstPartyTypeKind.ZodIntersection:
6096
+ return parseIntersectionDef(def, refs);
6097
+ case ZodFirstPartyTypeKind.ZodTuple:
6098
+ return parseTupleDef(def, refs);
6099
+ case ZodFirstPartyTypeKind.ZodRecord:
6100
+ return parseRecordDef(def, refs);
6101
+ case ZodFirstPartyTypeKind.ZodLiteral:
6102
+ return parseLiteralDef(def, refs);
6103
+ case ZodFirstPartyTypeKind.ZodEnum:
6104
+ return parseEnumDef(def);
6105
+ case ZodFirstPartyTypeKind.ZodNativeEnum:
6106
+ return parseNativeEnumDef(def);
6107
+ case ZodFirstPartyTypeKind.ZodNullable:
6108
+ return parseNullableDef(def, refs);
6109
+ case ZodFirstPartyTypeKind.ZodOptional:
6110
+ return parseOptionalDef(def, refs);
6111
+ case ZodFirstPartyTypeKind.ZodMap:
6112
+ return parseMapDef(def, refs);
6113
+ case ZodFirstPartyTypeKind.ZodSet:
6114
+ return parseSetDef(def, refs);
6115
+ case ZodFirstPartyTypeKind.ZodLazy:
6116
+ return () => def.getter()._def;
6117
+ case ZodFirstPartyTypeKind.ZodPromise:
6118
+ return parsePromiseDef(def, refs);
6119
+ case ZodFirstPartyTypeKind.ZodNaN:
6120
+ case ZodFirstPartyTypeKind.ZodNever:
6121
+ return parseNeverDef();
6122
+ case ZodFirstPartyTypeKind.ZodEffects:
6123
+ return parseEffectsDef(def, refs);
6124
+ case ZodFirstPartyTypeKind.ZodAny:
6125
+ return parseAnyDef();
6126
+ case ZodFirstPartyTypeKind.ZodUnknown:
6127
+ return parseUnknownDef();
6128
+ case ZodFirstPartyTypeKind.ZodDefault:
6129
+ return parseDefaultDef(def, refs);
6130
+ case ZodFirstPartyTypeKind.ZodBranded:
6131
+ return parseBrandedDef(def, refs);
6132
+ case ZodFirstPartyTypeKind.ZodReadonly:
6133
+ return parseReadonlyDef(def, refs);
6134
+ case ZodFirstPartyTypeKind.ZodCatch:
6135
+ return parseCatchDef(def, refs);
6136
+ case ZodFirstPartyTypeKind.ZodPipeline:
6137
+ return parsePipelineDef(def, refs);
6138
+ case ZodFirstPartyTypeKind.ZodFunction:
6139
+ case ZodFirstPartyTypeKind.ZodVoid:
6140
+ case ZodFirstPartyTypeKind.ZodSymbol:
6141
+ return void 0;
6142
+ default:
6143
+ return /* @__PURE__ */ ((_) => void 0)();
6144
+ }
6145
+ };
6146
+
6147
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/parseDef.js
6148
+ function parseDef(def, refs, forceResolution = false) {
6149
+ const seenItem = refs.seen.get(def);
6150
+ if (refs.override) {
6151
+ const overrideResult = refs.override?.(def, refs, seenItem, forceResolution);
6152
+ if (overrideResult !== ignoreOverride) {
6153
+ return overrideResult;
6154
+ }
6155
+ }
6156
+ if (seenItem && !forceResolution) {
6157
+ const seenSchema = get$ref(seenItem, refs);
6158
+ if (seenSchema !== void 0) {
6159
+ return seenSchema;
6160
+ }
6161
+ }
6162
+ const newItem = { def, path: refs.currentPath, jsonSchema: void 0 };
6163
+ refs.seen.set(def, newItem);
6164
+ const jsonSchemaOrGetter = selectParser2(def, def.typeName, refs);
6165
+ const jsonSchema = typeof jsonSchemaOrGetter === "function" ? parseDef(jsonSchemaOrGetter(), refs) : jsonSchemaOrGetter;
6166
+ if (jsonSchema) {
6167
+ addMeta(def, refs, jsonSchema);
6168
+ }
6169
+ if (refs.postProcess) {
6170
+ const postProcessResult = refs.postProcess(jsonSchema, def, refs);
6171
+ newItem.jsonSchema = jsonSchema;
6172
+ return postProcessResult;
6173
+ }
6174
+ newItem.jsonSchema = jsonSchema;
6175
+ return jsonSchema;
6176
+ }
6177
+ var get$ref = (item, refs) => {
6178
+ switch (refs.$refStrategy) {
6179
+ case "root":
6180
+ return { $ref: item.path.join("/") };
6181
+ case "relative":
6182
+ return { $ref: getRelativePath(refs.currentPath, item.path) };
6183
+ case "none":
6184
+ case "seen": {
6185
+ if (item.path.length < refs.currentPath.length && item.path.every((value, index) => refs.currentPath[index] === value)) {
6186
+ console.warn(`Recursive reference detected at ${refs.currentPath.join("/")}! Defaulting to any`);
6187
+ return {};
6188
+ }
6189
+ return refs.$refStrategy === "seen" ? {} : void 0;
6190
+ }
6191
+ }
6192
+ };
6193
+ var getRelativePath = (pathA, pathB) => {
6194
+ let i = 0;
6195
+ for (; i < pathA.length && i < pathB.length; i++) {
6196
+ if (pathA[i] !== pathB[i])
6197
+ break;
6198
+ }
6199
+ return [(pathA.length - i).toString(), ...pathB.slice(i)].join("/");
6200
+ };
6201
+ var addMeta = (def, refs, jsonSchema) => {
6202
+ if (def.description) {
6203
+ jsonSchema.description = def.description;
6204
+ if (refs.markdownDescription) {
6205
+ jsonSchema.markdownDescription = def.description;
6206
+ }
6207
+ }
6208
+ return jsonSchema;
6209
+ };
6210
+
6211
+ // ../../node_modules/.pnpm/zod-to-json-schema@3.24.5_zod@3.24.3/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js
6212
+ var zodToJsonSchema = (schema, options) => {
6213
+ const refs = getRefs(options);
6214
+ const definitions = void 0;
6215
+ const name = options?.name;
6216
+ const main = parseDef(schema._def, refs , false) ?? {};
6217
+ const combined = name === void 0 ? definitions ? {
6218
+ ...main,
6219
+ [refs.definitionPath]: definitions
6220
+ } : main : {
6221
+ $ref: [
6222
+ ...refs.$refStrategy === "relative" ? [] : refs.basePath,
6223
+ refs.definitionPath,
6224
+ name
6225
+ ].join("/"),
6226
+ [refs.definitionPath]: {
6227
+ ...definitions,
6228
+ [name]: main
6229
+ }
6230
+ };
6231
+ if (refs.target === "jsonSchema7") {
6232
+ combined.$schema = "http://json-schema.org/draft-07/schema#";
6233
+ } else if (refs.target === "jsonSchema2019-09" || refs.target === "openAi") {
6234
+ combined.$schema = "https://json-schema.org/draft/2019-09/schema#";
6235
+ }
6236
+ if (refs.target === "openAi" && ("anyOf" in combined || "oneOf" in combined || "allOf" in combined || "type" in combined && Array.isArray(combined.type))) {
6237
+ console.warn("Warning: OpenAI may not support schemas with unions as roots! Try wrapping it in an object property.");
6238
+ }
6239
+ return combined;
6240
+ };
6241
+ var writeErrorLog = (message, data) => {
6242
+ const now = /* @__PURE__ */ new Date();
6243
+ const timestamp = now.toISOString();
6244
+ const hourTimestamp = timestamp.slice(0, 13);
6245
+ const logMessage = {
6246
+ timestamp,
6247
+ message,
6248
+ ...data ? typeof data === "object" ? data : { data } : {}
6249
+ };
6250
+ try {
6251
+ const cacheDir = path__namespace.join(os__namespace.homedir(), ".cache", "mastra", "mcp-docs-server-logs");
6252
+ fs__namespace.mkdirSync(cacheDir, { recursive: true });
6253
+ const logFile = path__namespace.join(cacheDir, `${hourTimestamp}.log`);
6254
+ fs__namespace.appendFileSync(logFile, JSON.stringify(logMessage) + "\n", "utf8");
6255
+ } catch (err) {
6256
+ console.error("Failed to write to log file:", err);
6257
+ }
6258
+ };
6259
+ function createLogger(server) {
6260
+ const sendLog = async (level, message, data) => {
6261
+ return;
6262
+ };
6263
+ return {
6264
+ info: async (message, data) => {
6265
+ console.error(message, data ? data : "");
6266
+ await sendLog();
6267
+ },
6268
+ warning: async (message, data) => {
6269
+ console.error(message, data ? data : "");
6270
+ await sendLog();
6271
+ },
6272
+ error: async (message, error) => {
6273
+ const errorData = error instanceof Error ? {
6274
+ message: error.message,
6275
+ stack: error.stack,
6276
+ name: error.name
6277
+ } : error;
6278
+ writeErrorLog(message, errorData);
6279
+ console.error(message, errorData ? errorData : "");
6280
+ await sendLog();
6281
+ },
6282
+ debug: async (message, data) => {
6283
+ if (process.env.DEBUG || process.env.NODE_ENV === "development") {
6284
+ console.error(message, data ? data : "");
6285
+ await sendLog();
6286
+ }
6287
+ }
6288
+ };
6289
+ }
6290
+
6291
+ // src/server.ts
6292
+ var logger2 = createLogger();
6293
+ var MCPServer = class {
6294
+ server;
6295
+ convertedTools;
6296
+ stdioTransport;
6297
+ sseTransport;
6298
+ /**
6299
+ * Get the current stdio transport.
6300
+ */
6301
+ getStdioTransport() {
6302
+ return this.stdioTransport;
6303
+ }
6304
+ /**
6305
+ * Get the current SSE transport.
6306
+ */
6307
+ getSseTransport() {
6308
+ return this.sseTransport;
6309
+ }
6310
+ /**
6311
+ * Get a read-only view of the registered tools (for testing/introspection).
6312
+ */
6313
+ tools() {
6314
+ return this.convertedTools;
6315
+ }
6316
+ /**
6317
+ * Construct a new MCPServer instance.
6318
+ * @param opts.name - Server name
6319
+ * @param opts.version - Server version
6320
+ * @param opts.tools - Tool definitions to register
6321
+ */
6322
+ constructor({ name, version, tools }) {
6323
+ this.server = new index_js$1.Server({ name, version }, { capabilities: { tools: {}, logging: { enabled: true } } });
6324
+ this.convertedTools = this.convertTools(tools);
6325
+ void logger2.info(
6326
+ `Initialized MCPServer '${name}' v${version} with tools: ${Object.keys(this.convertedTools).join(", ")}`
6327
+ );
6328
+ this.registerListToolsHandler();
6329
+ this.registerCallToolHandler();
6330
+ }
6331
+ /**
6332
+ * Convert and validate all provided tools, logging registration status.
6333
+ * @param tools Tool definitions
6334
+ * @returns Converted tools registry
6335
+ */
6336
+ convertTools(tools) {
6337
+ const convertedTools = {};
6338
+ for (const toolName of Object.keys(tools)) {
6339
+ let inputSchema;
6340
+ let zodSchema;
6341
+ const toolInstance = tools[toolName];
6342
+ if (!toolInstance) {
6343
+ void logger2.warning(`Tool instance for '${toolName}' is undefined. Skipping.`);
6344
+ continue;
6345
+ }
6346
+ if (typeof toolInstance.execute !== "function") {
6347
+ void logger2.warning(`Tool '${toolName}' does not have a valid execute function. Skipping.`);
6348
+ continue;
6349
+ }
6350
+ if (core.isVercelTool(toolInstance)) {
6351
+ if (core.isZodType(toolInstance.parameters)) {
6352
+ zodSchema = toolInstance.parameters;
6353
+ inputSchema = zodToJsonSchema(zodSchema);
6354
+ } else if (typeof toolInstance.parameters === "object") {
6355
+ zodSchema = core.resolveSerializedZodOutput(esm_default(toolInstance.parameters));
6356
+ inputSchema = toolInstance.parameters;
6357
+ } else {
6358
+ zodSchema = z.object({});
6359
+ inputSchema = zodToJsonSchema(zodSchema);
6360
+ }
6361
+ } else {
6362
+ zodSchema = toolInstance?.inputSchema ?? z.object({});
6363
+ inputSchema = zodToJsonSchema(zodSchema);
6364
+ }
6365
+ const execute = async (args, execOptions) => {
6366
+ if (core.isVercelTool(toolInstance)) {
6367
+ return await toolInstance.execute?.(args, execOptions) ?? void 0;
6368
+ }
6369
+ return await toolInstance.execute?.({ context: args }, execOptions) ?? void 0;
6370
+ };
6371
+ convertedTools[toolName] = {
6372
+ name: toolName,
6373
+ description: toolInstance?.description,
6374
+ inputSchema,
6375
+ zodSchema,
6376
+ execute
6377
+ };
6378
+ void logger2.info(`Registered tool: '${toolName}' [${toolInstance?.description || "No description"}]`);
6379
+ }
6380
+ void logger2.info(`Total tools registered: ${Object.keys(convertedTools).length}`);
6381
+ return convertedTools;
6382
+ }
6383
+ /**
6384
+ * Register the ListTools handler for listing all available tools.
6385
+ */
6386
+ registerListToolsHandler() {
6387
+ this.server.setRequestHandler(types_js.ListToolsRequestSchema, async () => {
6388
+ await logger2.debug("Handling ListTools request");
6389
+ return {
6390
+ tools: Object.values(this.convertedTools).map((tool) => ({
6391
+ name: tool.name,
6392
+ description: tool.description,
6393
+ inputSchema: tool.inputSchema
6394
+ }))
6395
+ };
6396
+ });
6397
+ }
6398
+ /**
6399
+ * Register the CallTool handler for executing a tool by name.
6400
+ */
6401
+ registerCallToolHandler() {
6402
+ this.server.setRequestHandler(types_js.CallToolRequestSchema, async (request) => {
6403
+ const startTime = Date.now();
6404
+ try {
6405
+ const tool = this.convertedTools[request.params.name];
6406
+ if (!tool) {
6407
+ await logger2.warning(`CallTool: Unknown tool '${request.params.name}' requested.`);
6408
+ return {
6409
+ content: [{ type: "text", text: `Unknown tool: ${request.params.name}` }],
6410
+ isError: true
6411
+ };
6412
+ }
6413
+ await logger2.debug(`CallTool: Invoking '${request.params.name}' with arguments:`, request.params.arguments);
6414
+ const args = tool.zodSchema.parse(request.params.arguments ?? {});
6415
+ const result = await tool.execute(args, request.params);
6416
+ const duration = Date.now() - startTime;
6417
+ await logger2.info(`Tool '${request.params.name}' executed successfully in ${duration}ms.`);
6418
+ return {
6419
+ content: [
6420
+ {
6421
+ type: "text",
6422
+ text: JSON.stringify(result)
6423
+ }
6424
+ ],
6425
+ isError: false
6426
+ };
6427
+ } catch (error) {
6428
+ const duration = Date.now() - startTime;
6429
+ if (error instanceof z.ZodError) {
6430
+ await logger2.warning("Invalid tool arguments", {
6431
+ tool: request.params.name,
6432
+ errors: error.errors,
6433
+ duration: `${duration}ms`
6434
+ });
6435
+ return {
6436
+ content: [
6437
+ {
6438
+ type: "text",
6439
+ text: `Invalid arguments: ${error.errors.map((e) => `${e.path.join(".")}: ${e.message}`).join(", ")}`
6440
+ }
6441
+ ],
6442
+ isError: true
6443
+ };
6444
+ }
6445
+ await logger2.error(`Tool execution failed: ${request.params.name}`, error);
6446
+ return {
6447
+ content: [{ type: "text", text: `Error: ${error instanceof Error ? error.message : String(error)}` }],
6448
+ isError: true
6449
+ };
6450
+ }
6451
+ });
6452
+ }
6453
+ /**
6454
+ * Start the MCP server using stdio transport (for Windsurf integration).
6455
+ */
6456
+ async startStdio() {
6457
+ this.stdioTransport = new stdio_js$1.StdioServerTransport();
6458
+ await this.server.connect(this.stdioTransport);
6459
+ await logger2.info("Started MCP Server (stdio)");
6460
+ }
6461
+ /**
6462
+ * Handles MCP-over-SSE protocol for user-provided HTTP servers.
6463
+ * Call this from your HTTP server for both the SSE and message endpoints.
6464
+ *
6465
+ * @param url Parsed URL of the incoming request
6466
+ * @param ssePath Path for establishing the SSE connection (e.g. '/sse')
6467
+ * @param messagePath Path for POSTing client messages (e.g. '/message')
6468
+ * @param req Incoming HTTP request
6469
+ * @param res HTTP response (must support .write/.end)
6470
+ */
6471
+ async startSSE({
6472
+ url,
6473
+ ssePath,
6474
+ messagePath,
6475
+ req,
6476
+ res
6477
+ }) {
6478
+ if (url.pathname === ssePath) {
6479
+ await logger2.debug("Received SSE connection");
6480
+ this.sseTransport = new sse_js$1.SSEServerTransport(messagePath, res);
6481
+ await this.server.connect(this.sseTransport);
6482
+ this.server.onclose = async () => {
6483
+ await this.server.close();
6484
+ this.sseTransport = void 0;
6485
+ };
6486
+ res.on("close", () => {
6487
+ this.sseTransport = void 0;
6488
+ });
6489
+ } else if (url.pathname === messagePath) {
6490
+ await logger2.debug("Received message");
6491
+ if (!this.sseTransport) {
6492
+ res.writeHead(503);
6493
+ res.end("SSE connection not established");
6494
+ return;
6495
+ }
6496
+ await this.sseTransport.handlePostMessage(req, res);
6497
+ } else {
6498
+ await logger2.debug("Unknown path:", url.pathname);
6499
+ res.writeHead(404);
6500
+ res.end();
6501
+ }
6502
+ }
6503
+ };
6504
+
4357
6505
  exports.MCPConfiguration = MCPConfiguration;
6506
+ exports.MCPServer = MCPServer;
4358
6507
  exports.MastraMCPClient = MastraMCPClient;