@tsed/platform-mcp 8.28.6 → 8.28.7

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 (86) hide show
  1. package/lib/esm/index.js +0 -26
  2. package/lib/esm/utils/toZod.js +1 -1
  3. package/lib/tsconfig.esm.tsbuildinfo +1 -1
  4. package/lib/types/fn/defineResource.d.ts +4 -4
  5. package/lib/types/index.d.ts +0 -26
  6. package/package.json +8 -7
  7. package/src/index.ts +0 -26
  8. package/src/utils/toZod.ts +1 -2
  9. package/lib/esm/utils/json-schema-to-zod/Types.js +0 -1
  10. package/lib/esm/utils/json-schema-to-zod/cli.js +0 -83
  11. package/lib/esm/utils/json-schema-to-zod/index.js +0 -25
  12. package/lib/esm/utils/json-schema-to-zod/jsonSchemaToZod.js +0 -52
  13. package/lib/esm/utils/json-schema-to-zod/parsers/parseAllOf.js +0 -43
  14. package/lib/esm/utils/json-schema-to-zod/parsers/parseAnyOf.js +0 -17
  15. package/lib/esm/utils/json-schema-to-zod/parsers/parseArray.js +0 -22
  16. package/lib/esm/utils/json-schema-to-zod/parsers/parseBoolean.js +0 -9
  17. package/lib/esm/utils/json-schema-to-zod/parsers/parseConst.js +0 -9
  18. package/lib/esm/utils/json-schema-to-zod/parsers/parseDefault.js +0 -9
  19. package/lib/esm/utils/json-schema-to-zod/parsers/parseEnum.js +0 -21
  20. package/lib/esm/utils/json-schema-to-zod/parsers/parseIfThenElse.js +0 -26
  21. package/lib/esm/utils/json-schema-to-zod/parsers/parseMultipleType.js +0 -10
  22. package/lib/esm/utils/json-schema-to-zod/parsers/parseNot.js +0 -13
  23. package/lib/esm/utils/json-schema-to-zod/parsers/parseNull.js +0 -9
  24. package/lib/esm/utils/json-schema-to-zod/parsers/parseNullable.js +0 -11
  25. package/lib/esm/utils/json-schema-to-zod/parsers/parseNumber.js +0 -52
  26. package/lib/esm/utils/json-schema-to-zod/parsers/parseObject.js +0 -177
  27. package/lib/esm/utils/json-schema-to-zod/parsers/parseOneOf.js +0 -40
  28. package/lib/esm/utils/json-schema-to-zod/parsers/parseSchema.js +0 -153
  29. package/lib/esm/utils/json-schema-to-zod/parsers/parseString.js +0 -63
  30. package/lib/esm/utils/json-schema-to-zod/utils/cliTools.js +0 -126
  31. package/lib/esm/utils/json-schema-to-zod/utils/half.js +0 -9
  32. package/lib/esm/utils/json-schema-to-zod/utils/jsdocs.js +0 -24
  33. package/lib/esm/utils/json-schema-to-zod/utils/omit.js +0 -12
  34. package/lib/esm/utils/json-schema-to-zod/utils/withMessage.js +0 -28
  35. package/lib/types/utils/json-schema-to-zod/Types.d.ts +0 -116
  36. package/lib/types/utils/json-schema-to-zod/cli.d.ts +0 -2
  37. package/lib/types/utils/json-schema-to-zod/index.d.ts +0 -25
  38. package/lib/types/utils/json-schema-to-zod/jsonSchemaToZod.d.ts +0 -11
  39. package/lib/types/utils/json-schema-to-zod/parsers/parseAllOf.d.ts +0 -10
  40. package/lib/types/utils/json-schema-to-zod/parsers/parseAnyOf.d.ts +0 -10
  41. package/lib/types/utils/json-schema-to-zod/parsers/parseArray.d.ts +0 -10
  42. package/lib/types/utils/json-schema-to-zod/parsers/parseBoolean.d.ts +0 -10
  43. package/lib/types/utils/json-schema-to-zod/parsers/parseConst.d.ts +0 -10
  44. package/lib/types/utils/json-schema-to-zod/parsers/parseDefault.d.ts +0 -8
  45. package/lib/types/utils/json-schema-to-zod/parsers/parseEnum.d.ts +0 -10
  46. package/lib/types/utils/json-schema-to-zod/parsers/parseIfThenElse.d.ts +0 -12
  47. package/lib/types/utils/json-schema-to-zod/parsers/parseMultipleType.d.ts +0 -10
  48. package/lib/types/utils/json-schema-to-zod/parsers/parseNot.d.ts +0 -10
  49. package/lib/types/utils/json-schema-to-zod/parsers/parseNull.d.ts +0 -10
  50. package/lib/types/utils/json-schema-to-zod/parsers/parseNullable.d.ts +0 -10
  51. package/lib/types/utils/json-schema-to-zod/parsers/parseNumber.d.ts +0 -10
  52. package/lib/types/utils/json-schema-to-zod/parsers/parseObject.d.ts +0 -10
  53. package/lib/types/utils/json-schema-to-zod/parsers/parseOneOf.d.ts +0 -10
  54. package/lib/types/utils/json-schema-to-zod/parsers/parseSchema.d.ts +0 -61
  55. package/lib/types/utils/json-schema-to-zod/parsers/parseString.d.ts +0 -10
  56. package/lib/types/utils/json-schema-to-zod/utils/cliTools.d.ts +0 -67
  57. package/lib/types/utils/json-schema-to-zod/utils/half.d.ts +0 -7
  58. package/lib/types/utils/json-schema-to-zod/utils/jsdocs.d.ts +0 -15
  59. package/lib/types/utils/json-schema-to-zod/utils/omit.d.ts +0 -7
  60. package/lib/types/utils/json-schema-to-zod/utils/withMessage.d.ts +0 -19
  61. package/src/utils/json-schema-to-zod/Types.ts +0 -123
  62. package/src/utils/json-schema-to-zod/cli.ts +0 -88
  63. package/src/utils/json-schema-to-zod/index.ts +0 -26
  64. package/src/utils/json-schema-to-zod/jsonSchemaToZod.ts +0 -60
  65. package/src/utils/json-schema-to-zod/parsers/parseAllOf.ts +0 -50
  66. package/src/utils/json-schema-to-zod/parsers/parseAnyOf.ts +0 -19
  67. package/src/utils/json-schema-to-zod/parsers/parseArray.ts +0 -28
  68. package/src/utils/json-schema-to-zod/parsers/parseBoolean.ts +0 -11
  69. package/src/utils/json-schema-to-zod/parsers/parseConst.ts +0 -11
  70. package/src/utils/json-schema-to-zod/parsers/parseDefault.ts +0 -11
  71. package/src/utils/json-schema-to-zod/parsers/parseEnum.ts +0 -20
  72. package/src/utils/json-schema-to-zod/parsers/parseIfThenElse.ts +0 -35
  73. package/src/utils/json-schema-to-zod/parsers/parseMultipleType.ts +0 -12
  74. package/src/utils/json-schema-to-zod/parsers/parseNot.ts +0 -15
  75. package/src/utils/json-schema-to-zod/parsers/parseNull.ts +0 -11
  76. package/src/utils/json-schema-to-zod/parsers/parseNullable.ts +0 -13
  77. package/src/utils/json-schema-to-zod/parsers/parseNumber.ts +0 -56
  78. package/src/utils/json-schema-to-zod/parsers/parseObject.ts +0 -220
  79. package/src/utils/json-schema-to-zod/parsers/parseOneOf.ts +0 -44
  80. package/src/utils/json-schema-to-zod/parsers/parseSchema.ts +0 -190
  81. package/src/utils/json-schema-to-zod/parsers/parseString.ts +0 -73
  82. package/src/utils/json-schema-to-zod/utils/cliTools.ts +0 -189
  83. package/src/utils/json-schema-to-zod/utils/half.ts +0 -9
  84. package/src/utils/json-schema-to-zod/utils/jsdocs.ts +0 -29
  85. package/src/utils/json-schema-to-zod/utils/omit.ts +0 -14
  86. package/src/utils/json-schema-to-zod/utils/withMessage.ts +0 -42
@@ -32,10 +32,10 @@ export type ResourceProps = FnResourceReadProps | FnResourceTemplateProps | Clas
32
32
  declare function mapOptions(options: ResourceProps): {
33
33
  name: string | undefined;
34
34
  handler: ReadResourceCallback;
35
- description?: string | undefined;
36
35
  _meta?: {
37
36
  [x: string]: unknown;
38
37
  } | undefined;
38
+ description?: string | undefined;
39
39
  annotations?: {
40
40
  audience?: ("user" | "assistant")[] | undefined;
41
41
  priority?: number | undefined;
@@ -54,10 +54,10 @@ declare function mapOptions(options: ResourceProps): {
54
54
  } | {
55
55
  name: string | undefined;
56
56
  handler: ReadResourceCallback;
57
- description?: string | undefined;
58
57
  _meta?: {
59
58
  [x: string]: unknown;
60
59
  } | undefined;
60
+ description?: string | undefined;
61
61
  annotations?: {
62
62
  audience?: ("user" | "assistant")[] | undefined;
63
63
  priority?: number | undefined;
@@ -76,10 +76,10 @@ declare function mapOptions(options: ResourceProps): {
76
76
  } | {
77
77
  name: string | undefined;
78
78
  handler: ReadResourceCallback;
79
- description?: string | undefined;
80
79
  _meta?: {
81
80
  [x: string]: unknown;
82
81
  } | undefined;
82
+ description?: string | undefined;
83
83
  annotations?: {
84
84
  audience?: ("user" | "assistant")[] | undefined;
85
85
  priority?: number | undefined;
@@ -100,10 +100,10 @@ declare function mapOptions(options: ResourceProps): {
100
100
  } | {
101
101
  name: string | undefined;
102
102
  handler: ReadResourceCallback;
103
- description?: string | undefined;
104
103
  _meta?: {
105
104
  [x: string]: unknown;
106
105
  } | undefined;
106
+ description?: string | undefined;
107
107
  annotations?: {
108
108
  audience?: ("user" | "assistant")[] | undefined;
109
109
  priority?: number | undefined;
@@ -11,30 +11,4 @@ export * from "./fn/defineTool.js";
11
11
  export * from "./interfaces/PlatformMcpSettings.js";
12
12
  export * from "./services/McpServerFactory.js";
13
13
  export * from "./services/PlatformMcpModule.js";
14
- export * from "./utils/json-schema-to-zod/cli.js";
15
- export * from "./utils/json-schema-to-zod/index.js";
16
- export * from "./utils/json-schema-to-zod/jsonSchemaToZod.js";
17
- export * from "./utils/json-schema-to-zod/parsers/parseAllOf.js";
18
- export * from "./utils/json-schema-to-zod/parsers/parseAnyOf.js";
19
- export * from "./utils/json-schema-to-zod/parsers/parseArray.js";
20
- export * from "./utils/json-schema-to-zod/parsers/parseBoolean.js";
21
- export * from "./utils/json-schema-to-zod/parsers/parseConst.js";
22
- export * from "./utils/json-schema-to-zod/parsers/parseDefault.js";
23
- export * from "./utils/json-schema-to-zod/parsers/parseEnum.js";
24
- export * from "./utils/json-schema-to-zod/parsers/parseIfThenElse.js";
25
- export * from "./utils/json-schema-to-zod/parsers/parseMultipleType.js";
26
- export * from "./utils/json-schema-to-zod/parsers/parseNot.js";
27
- export * from "./utils/json-schema-to-zod/parsers/parseNull.js";
28
- export * from "./utils/json-schema-to-zod/parsers/parseNullable.js";
29
- export * from "./utils/json-schema-to-zod/parsers/parseNumber.js";
30
- export * from "./utils/json-schema-to-zod/parsers/parseObject.js";
31
- export * from "./utils/json-schema-to-zod/parsers/parseOneOf.js";
32
- export * from "./utils/json-schema-to-zod/parsers/parseSchema.js";
33
- export * from "./utils/json-schema-to-zod/parsers/parseString.js";
34
- export * from "./utils/json-schema-to-zod/Types.js";
35
- export * from "./utils/json-schema-to-zod/utils/cliTools.js";
36
- export * from "./utils/json-schema-to-zod/utils/half.js";
37
- export * from "./utils/json-schema-to-zod/utils/jsdocs.js";
38
- export * from "./utils/json-schema-to-zod/utils/omit.js";
39
- export * from "./utils/json-schema-to-zod/utils/withMessage.js";
40
14
  export * from "./utils/toZod.js";
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@tsed/platform-mcp",
3
3
  "description": "Model Context Protocol integration for Ts.ED HTTP adapters.",
4
4
  "type": "module",
5
- "version": "8.28.6",
5
+ "version": "8.28.7",
6
6
  "source": "./src/index.ts",
7
7
  "main": "./lib/esm/index.js",
8
8
  "module": "./lib/esm/index.js",
@@ -26,17 +26,18 @@
26
26
  "dependencies": {
27
27
  "@modelcontextprotocol/sdk": ">=1.29.0",
28
28
  "change-case": ">=5.4.4",
29
+ "json-schema-to-zod": ">=2.8.1",
29
30
  "tslib": ">=2.7.0",
30
31
  "uuid": ">=11.0.2",
31
32
  "zod": ">=4.0.0"
32
33
  },
33
34
  "devDependencies": {
34
- "@tsed/barrels": "8.28.6",
35
- "@tsed/core": "8.28.6",
36
- "@tsed/di": "8.28.6",
37
- "@tsed/platform-http": "8.28.6",
38
- "@tsed/schema": "8.28.6",
39
- "@tsed/typescript": "8.28.6",
35
+ "@tsed/barrels": "8.28.7",
36
+ "@tsed/core": "8.28.7",
37
+ "@tsed/di": "8.28.7",
38
+ "@tsed/platform-http": "8.28.7",
39
+ "@tsed/schema": "8.28.7",
40
+ "@tsed/typescript": "8.28.7",
40
41
  "eslint": "9.12.0",
41
42
  "typescript": "6.0.2",
42
43
  "vitest": "4.1.4"
package/src/index.ts CHANGED
@@ -11,30 +11,4 @@ export * from "./fn/defineTool.js";
11
11
  export * from "./interfaces/PlatformMcpSettings.js";
12
12
  export * from "./services/McpServerFactory.js";
13
13
  export * from "./services/PlatformMcpModule.js";
14
- export * from "./utils/json-schema-to-zod/cli.js";
15
- export * from "./utils/json-schema-to-zod/index.js";
16
- export * from "./utils/json-schema-to-zod/jsonSchemaToZod.js";
17
- export * from "./utils/json-schema-to-zod/parsers/parseAllOf.js";
18
- export * from "./utils/json-schema-to-zod/parsers/parseAnyOf.js";
19
- export * from "./utils/json-schema-to-zod/parsers/parseArray.js";
20
- export * from "./utils/json-schema-to-zod/parsers/parseBoolean.js";
21
- export * from "./utils/json-schema-to-zod/parsers/parseConst.js";
22
- export * from "./utils/json-schema-to-zod/parsers/parseDefault.js";
23
- export * from "./utils/json-schema-to-zod/parsers/parseEnum.js";
24
- export * from "./utils/json-schema-to-zod/parsers/parseIfThenElse.js";
25
- export * from "./utils/json-schema-to-zod/parsers/parseMultipleType.js";
26
- export * from "./utils/json-schema-to-zod/parsers/parseNot.js";
27
- export * from "./utils/json-schema-to-zod/parsers/parseNull.js";
28
- export * from "./utils/json-schema-to-zod/parsers/parseNullable.js";
29
- export * from "./utils/json-schema-to-zod/parsers/parseNumber.js";
30
- export * from "./utils/json-schema-to-zod/parsers/parseObject.js";
31
- export * from "./utils/json-schema-to-zod/parsers/parseOneOf.js";
32
- export * from "./utils/json-schema-to-zod/parsers/parseSchema.js";
33
- export * from "./utils/json-schema-to-zod/parsers/parseString.js";
34
- export * from "./utils/json-schema-to-zod/Types.js";
35
- export * from "./utils/json-schema-to-zod/utils/cliTools.js";
36
- export * from "./utils/json-schema-to-zod/utils/half.js";
37
- export * from "./utils/json-schema-to-zod/utils/jsdocs.js";
38
- export * from "./utils/json-schema-to-zod/utils/omit.js";
39
- export * from "./utils/json-schema-to-zod/utils/withMessage.js";
40
14
  export * from "./utils/toZod.js";
@@ -1,8 +1,7 @@
1
1
  import {JsonSchema} from "@tsed/schema";
2
+ import {jsonSchemaToZod} from "json-schema-to-zod";
2
3
  import {z, type ZodObject} from "zod";
3
4
 
4
- import {jsonSchemaToZod} from "./json-schema-to-zod/index.js";
5
-
6
5
  function transform(schema: JsonSchema): ZodObject {
7
6
  return eval(`(z) => ${jsonSchemaToZod(schema.toJSON(), {zodVersion: 4})}`)(z);
8
7
  }
@@ -1 +0,0 @@
1
- export {};
@@ -1,83 +0,0 @@
1
- #!/usr/bin/env node
2
- import { mkdirSync, writeFileSync } from "fs";
3
- import { dirname } from "path";
4
- import { fileURLToPath } from "url";
5
- import { jsonSchemaToZod } from "./jsonSchemaToZod.js";
6
- import { parseArgs, parseOrReadJSON, readPipe } from "./utils/cliTools.js";
7
- const params = {
8
- input: {
9
- shorthand: "i",
10
- value: "string",
11
- required: process.stdin.isTTY && "input is required when no JSON or file path is piped",
12
- description: "JSON or a source file path. Required if no data is piped."
13
- },
14
- output: {
15
- shorthand: "o",
16
- value: "string",
17
- description: "A file path to write to. If not supplied stdout will be used."
18
- },
19
- name: {
20
- shorthand: "n",
21
- value: "string",
22
- description: "The name of the schema in the output."
23
- },
24
- depth: {
25
- shorthand: "d",
26
- value: "number",
27
- description: "Maximum depth of recursion before falling back to z.any(). Defaults to 0."
28
- },
29
- module: {
30
- shorthand: "m",
31
- value: ["esm", "cjs", "none"],
32
- description: "Module syntax; 'esm', 'cjs' or 'none'. Defaults to 'esm'."
33
- },
34
- type: {
35
- shorthand: "t",
36
- value: "string",
37
- description: "The name of the (optional) inferred type export."
38
- },
39
- noImport: {
40
- shorthand: "ni",
41
- description: "Removes the `import { z } from 'zod';` or equivalent from the output."
42
- },
43
- withJsdocs: {
44
- shorthand: "wj",
45
- description: "Generate jsdocs off of the description property."
46
- },
47
- zodVersion: {
48
- shorthand: "zv",
49
- value: "number",
50
- description: "Target Zod version: 3 or 4. Defaults to 4."
51
- }
52
- };
53
- /**
54
- * Entry point for the `json-schema-to-zod` CLI that converts JSON Schema files into Zod source code.
55
- *
56
- * @module platform/mcp
57
- * @since 8.17.0
58
- */
59
- async function main() {
60
- const args = parseArgs(params, process.argv, true);
61
- const input = args.input || (await readPipe());
62
- const jsonSchema = parseOrReadJSON(input);
63
- const zodVersion = (args.zodVersion === 3 ? 3 : 4);
64
- const zodSchema = jsonSchemaToZod(jsonSchema, {
65
- name: args.name,
66
- depth: args.depth,
67
- module: args.module || "esm",
68
- noImport: args.noImport,
69
- type: args.type,
70
- withJsdocs: args.withJsdocs,
71
- zodVersion
72
- });
73
- if (args.output) {
74
- mkdirSync(dirname(args.output), { recursive: true });
75
- writeFileSync(args.output, zodSchema);
76
- }
77
- else {
78
- console.log(zodSchema);
79
- }
80
- }
81
- if (process.argv[1] && fileURLToPath(import.meta.url) === process.argv[1]) {
82
- void main();
83
- }
@@ -1,25 +0,0 @@
1
- export * from "./jsonSchemaToZod.js";
2
- export * from "./parsers/parseAllOf.js";
3
- export * from "./parsers/parseAnyOf.js";
4
- export * from "./parsers/parseArray.js";
5
- export * from "./parsers/parseBoolean.js";
6
- export * from "./parsers/parseConst.js";
7
- export * from "./parsers/parseDefault.js";
8
- export * from "./parsers/parseEnum.js";
9
- export * from "./parsers/parseIfThenElse.js";
10
- export * from "./parsers/parseMultipleType.js";
11
- export * from "./parsers/parseNot.js";
12
- export * from "./parsers/parseNull.js";
13
- export * from "./parsers/parseNullable.js";
14
- export * from "./parsers/parseNumber.js";
15
- export * from "./parsers/parseObject.js";
16
- export * from "./parsers/parseOneOf.js";
17
- export * from "./parsers/parseSchema.js";
18
- export * from "./parsers/parseString.js";
19
- export * from "./Types.js";
20
- export * from "./utils/half.js";
21
- export * from "./utils/jsdocs.js";
22
- export * from "./utils/omit.js";
23
- export * from "./utils/withMessage.js";
24
- import { jsonSchemaToZod } from "./jsonSchemaToZod.js";
25
- export default jsonSchemaToZod;
@@ -1,52 +0,0 @@
1
- import { parseSchema } from "./parsers/parseSchema.js";
2
- import { expandJsdocs } from "./utils/jsdocs.js";
3
- /**
4
- * Generates Zod code from a JSON Schema, optionally targeting specific module systems and versions.
5
- *
6
- * @param schema JSON Schema definition to translate.
7
- * @param options Generation options such as module format, naming, and version targets.
8
- * @returns A string of executable JavaScript/TypeScript that constructs an equivalent Zod schema.
9
- * @module platform/mcp
10
- * @since 8.17.0
11
- */
12
- export const jsonSchemaToZod = (schema, { module, name, type, noImport, zodVersion = 4, ...rest } = {}) => {
13
- if (type && (!name || module !== "esm")) {
14
- throw new Error("Option `type` requires `name` to be set and `module` to be `esm`");
15
- }
16
- let result = parseSchema(schema, {
17
- module,
18
- name,
19
- path: [],
20
- seen: new Map(),
21
- zodVersion,
22
- ...rest
23
- });
24
- const jsdocs = rest.withJsdocs && typeof schema !== "boolean" && schema.description ? expandJsdocs(schema.description) : "";
25
- if (module === "cjs") {
26
- result = `${jsdocs}module.exports = ${name ? `{ ${JSON.stringify(name)}: ${result} }` : result}
27
- `;
28
- if (!noImport) {
29
- result = `${jsdocs}const { z } = require("zod")
30
-
31
- ${result}`;
32
- }
33
- }
34
- else if (module === "esm") {
35
- result = `${jsdocs}export ${name ? `const ${name} =` : `default`} ${result}
36
- `;
37
- if (!noImport) {
38
- result = `import { z } from "zod"
39
-
40
- ${result}`;
41
- }
42
- }
43
- else if (name) {
44
- result = `${jsdocs}const ${name} = ${result}`;
45
- }
46
- if (type && name) {
47
- let typeName = typeof type === "string" ? type : `${name[0].toUpperCase()}${name.substring(1)}`;
48
- result += `export type ${typeName} = z.infer<typeof ${name}>
49
- `;
50
- }
51
- return result;
52
- };
@@ -1,43 +0,0 @@
1
- import { half } from "../utils/half.js";
2
- import { parseSchema } from "./parseSchema.js";
3
- const originalIndex = Symbol("Original index");
4
- const ensureOriginalIndex = (arr) => {
5
- let newArr = [];
6
- for (let i = 0; i < arr.length; i++) {
7
- const item = arr[i];
8
- if (typeof item === "boolean") {
9
- newArr.push(item ? { [originalIndex]: i } : { [originalIndex]: i, not: {} });
10
- }
11
- else if (originalIndex in item) {
12
- return arr;
13
- }
14
- else {
15
- newArr.push({ ...item, [originalIndex]: i });
16
- }
17
- }
18
- return newArr;
19
- };
20
- /**
21
- * Parses an `allOf` schema by intersecting all child schemas, preserving evaluation order for accurate metadata.
22
- *
23
- * @module platform/mcp
24
- * @since 8.17.0
25
- */
26
- export function parseAllOf(schema, refs) {
27
- if (schema.allOf.length === 0) {
28
- return "z.never()";
29
- }
30
- else if (schema.allOf.length === 1) {
31
- const item = schema.allOf[0];
32
- return parseSchema(item, {
33
- ...refs,
34
- path: [...refs.path, "allOf", item[originalIndex]]
35
- });
36
- }
37
- else {
38
- const [left, right] = half(ensureOriginalIndex(schema.allOf));
39
- return `z.intersection(${parseAllOf({ allOf: left }, refs)}, ${parseAllOf({
40
- allOf: right
41
- }, refs)})`;
42
- }
43
- }
@@ -1,17 +0,0 @@
1
- import { parseSchema } from "./parseSchema.js";
2
- /**
3
- * Parses an `anyOf` node into a Zod union across all nested schemas.
4
- *
5
- * @module platform/mcp
6
- * @since 8.17.0
7
- */
8
- export const parseAnyOf = (schema, refs) => {
9
- return schema.anyOf.length
10
- ? schema.anyOf.length === 1
11
- ? parseSchema(schema.anyOf[0], {
12
- ...refs,
13
- path: [...refs.path, "anyOf", 0]
14
- })
15
- : `z.union([${schema.anyOf.map((schema, i) => parseSchema(schema, { ...refs, path: [...refs.path, "anyOf", i] })).join(", ")}])`
16
- : `z.any()`;
17
- };
@@ -1,22 +0,0 @@
1
- import { withMessage } from "../utils/withMessage.js";
2
- import { parseSchema } from "./parseSchema.js";
3
- /**
4
- * Parses array schemas into the appropriate tuple or array expressions with validation hints.
5
- *
6
- * @module platform/mcp
7
- * @since 8.17.0
8
- */
9
- export const parseArray = (schema, refs) => {
10
- if (Array.isArray(schema.items)) {
11
- return `z.tuple([${schema.items.map((v, i) => parseSchema(v, { ...refs, path: [...refs.path, "items", i] }))}])`;
12
- }
13
- let r = !schema.items
14
- ? "z.array(z.any())"
15
- : `z.array(${parseSchema(schema.items, {
16
- ...refs,
17
- path: [...refs.path, "items"]
18
- })})`;
19
- r += withMessage(schema, "minItems", ({ json }) => [`.min(${json}`, ", ", ")"]);
20
- r += withMessage(schema, "maxItems", ({ json }) => [`.max(${json}`, ", ", ")"]);
21
- return r;
22
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * Parses boolean schemas into `z.boolean()`.
3
- *
4
- * @module platform/mcp
5
- * @since 8.17.0
6
- */
7
- export const parseBoolean = (_schema) => {
8
- return "z.boolean()";
9
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * Parses constant schemas into `z.literal` expressions.
3
- *
4
- * @module platform/mcp
5
- * @since 8.17.0
6
- */
7
- export const parseConst = (schema) => {
8
- return `z.literal(${JSON.stringify(schema.const)})`;
9
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * Fallback parser that maps unknown structures to `z.any()`.
3
- *
4
- * @module platform/mcp
5
- * @since 8.17.0
6
- */
7
- export const parseDefault = (_schema) => {
8
- return "z.any()";
9
- };
@@ -1,21 +0,0 @@
1
- /**
2
- * Parses enum schemas into either `z.enum` or unions of literals depending on value types.
3
- *
4
- * @module platform/mcp
5
- * @since 8.17.0
6
- */
7
- export const parseEnum = (schema) => {
8
- if (schema.enum.length === 0) {
9
- return "z.never()";
10
- }
11
- else if (schema.enum.length === 1) {
12
- // union does not work when there is only one element
13
- return `z.literal(${JSON.stringify(schema.enum[0])})`;
14
- }
15
- else if (schema.enum.every((x) => typeof x === "string")) {
16
- return `z.enum([${schema.enum.map((x) => JSON.stringify(x))}])`;
17
- }
18
- else {
19
- return `z.union([${schema.enum.map((x) => `z.literal(${JSON.stringify(x)})`).join(", ")}])`;
20
- }
21
- };
@@ -1,26 +0,0 @@
1
- import { parseSchema } from "./parseSchema.js";
2
- /**
3
- * Parses conditional schemas by generating union refinements that evaluate `if/then/else` logic at runtime.
4
- *
5
- * @module platform/mcp
6
- * @since 8.17.0
7
- */
8
- export const parseIfThenElse = (schema, refs) => {
9
- const $if = parseSchema(schema.if, { ...refs, path: [...refs.path, "if"] });
10
- const $then = parseSchema(schema.then, {
11
- ...refs,
12
- path: [...refs.path, "then"]
13
- });
14
- const $else = parseSchema(schema.else, {
15
- ...refs,
16
- path: [...refs.path, "else"]
17
- });
18
- return `z.union([${$then}, ${$else}]).superRefine((value,ctx) => {
19
- const result = ${$if}.safeParse(value).success
20
- ? ${$then}.safeParse(value)
21
- : ${$else}.safeParse(value);
22
- if (!result.success) {
23
- result.error.errors.forEach((error) => ctx.addIssue(error))
24
- }
25
- })`;
26
- };
@@ -1,10 +0,0 @@
1
- import { parseSchema } from "./parseSchema.js";
2
- /**
3
- * Parses schemas whose `type` keyword is an array, creating a union of each primitive variant.
4
- *
5
- * @module platform/mcp
6
- * @since 8.17.0
7
- */
8
- export const parseMultipleType = (schema, refs) => {
9
- return `z.union([${schema.type.map((type) => parseSchema({ ...schema, type }, { ...refs, withoutDefaults: true })).join(", ")}])`;
10
- };
@@ -1,13 +0,0 @@
1
- import { parseSchema } from "./parseSchema.js";
2
- /**
3
- * Parses the `not` keyword into a refinement that fails when the nested schema succeeds.
4
- *
5
- * @module platform/mcp
6
- * @since 8.17.0
7
- */
8
- export const parseNot = (schema, refs) => {
9
- return `z.any().refine((value) => !${parseSchema(schema.not, {
10
- ...refs,
11
- path: [...refs.path, "not"]
12
- })}.safeParse(value).success, "Invalid input: Should NOT be valid against schema")`;
13
- };
@@ -1,9 +0,0 @@
1
- /**
2
- * Parses `type: null` nodes into `z.null()`.
3
- *
4
- * @module platform/mcp
5
- * @since 8.17.0
6
- */
7
- export const parseNull = (_schema) => {
8
- return "z.null()";
9
- };
@@ -1,11 +0,0 @@
1
- import { omit } from "../utils/omit.js";
2
- import { parseSchema } from "./parseSchema.js";
3
- /**
4
- * Handles OpenAPI-style `nullable` keywords by delegating to the underlying schema and marking it nullable.
5
- *
6
- * @module platform/mcp
7
- * @since 8.17.0
8
- */
9
- export const parseNullable = (schema, refs) => {
10
- return `${parseSchema(omit(schema, "nullable"), refs, true)}.nullable()`;
11
- };
@@ -1,52 +0,0 @@
1
- import { withMessage } from "../utils/withMessage.js";
2
- /**
3
- * Parses numeric schemas, emitting integer formats and range constraints as chained Zod modifiers.
4
- *
5
- * @module platform/mcp
6
- * @since 8.17.0
7
- */
8
- export const parseNumber = (schema) => {
9
- let r = "z.number()";
10
- if (schema.type === "integer") {
11
- r += withMessage(schema, "type", () => [".int(", ")"]);
12
- }
13
- else {
14
- r += withMessage(schema, "format", ({ value }) => {
15
- if (value === "int64") {
16
- return [".int(", ")"];
17
- }
18
- });
19
- }
20
- r += withMessage(schema, "multipleOf", ({ value, json }) => {
21
- if (value === 1) {
22
- if (r.startsWith("z.number().int(")) {
23
- return;
24
- }
25
- return [".int(", ")"];
26
- }
27
- return [`.multipleOf(${json}`, ", ", ")"];
28
- });
29
- if (typeof schema.minimum === "number") {
30
- if (schema.exclusiveMinimum === true) {
31
- r += withMessage(schema, "minimum", ({ json }) => [`.gt(${json}`, ", ", ")"]);
32
- }
33
- else {
34
- r += withMessage(schema, "minimum", ({ json }) => [`.gte(${json}`, ", ", ")"]);
35
- }
36
- }
37
- else if (typeof schema.exclusiveMinimum === "number") {
38
- r += withMessage(schema, "exclusiveMinimum", ({ json }) => [`.gt(${json}`, ", ", ")"]);
39
- }
40
- if (typeof schema.maximum === "number") {
41
- if (schema.exclusiveMaximum === true) {
42
- r += withMessage(schema, "maximum", ({ json }) => [`.lt(${json}`, ", ", ")"]);
43
- }
44
- else {
45
- r += withMessage(schema, "maximum", ({ json }) => [`.lte(${json}`, ", ", ")"]);
46
- }
47
- }
48
- else if (typeof schema.exclusiveMaximum === "number") {
49
- r += withMessage(schema, "exclusiveMaximum", ({ json }) => [`.lt(${json}`, ", ", ")"]);
50
- }
51
- return r;
52
- };