Skip to content

Commit e240d57

Browse files
committed
fix: update import paths and refine type definitions for Zod integration
1 parent 3899174 commit e240d57

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1491
-160
lines changed

packages/platform/platform-mcp/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"test:ci": "vitest run --coverage.thresholds.autoUpdate=true"
2424
},
2525
"dependencies": {
26-
"@modelcontextprotocol/sdk": "^1.25.1",
26+
"@modelcontextprotocol/sdk": ">=1.26.0",
2727
"tslib": "2.7.0",
2828
"uuid": "^11.0.2",
29-
"zod": "3.25.76"
29+
"zod": ">=4.3.6"
3030
},
3131
"devDependencies": {
3232
"@tsed/barrels": "workspace:*",

packages/platform/platform-mcp/src/decorators/prompt.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {DITest, inject, Injectable} from "@tsed/di";
22
import {Description, Title} from "@tsed/schema";
33

4-
import {Prompt} from "../..";
4+
import {Prompt} from "./prompt.js";
55

66
@Injectable()
77
export class TestPrompt {
@@ -22,7 +22,7 @@ describe("Prompt", () => {
2222
propertyKey: "prompt",
2323
token: TestPrompt,
2424
name: "prompt",
25-
title: "title",
25+
title: "Title",
2626
description: "Description",
2727
handler: expect.any(Function)
2828
});

packages/platform/platform-mcp/src/decorators/resource.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {DITest, inject, Injectable} from "@tsed/di";
22
import {ContentType, Description, Title} from "@tsed/schema";
33

4-
import {Resource} from "../..";
4+
import {Resource} from "./resource.js";
55

66
@Injectable()
77
export class TestResource {

packages/platform/platform-mcp/src/decorators/tool.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {DITest, inject, Injectable} from "@tsed/di";
22
import {CollectionOf, Description, Property, Returns} from "@tsed/schema";
33

4-
import {Tool} from "../..";
4+
import {Tool} from "./tool.js";
55

66
class Model {
77
@Property()

packages/platform/platform-mcp/src/fn/defineTool.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export function defineTool<Input, Output = undefined>(options: ToolProps<Input,
7474

7575
return {
7676
...opts,
77+
name: opts.name,
7778
inputSchema: toZod(isArrowFn(opts.inputSchema) ? opts.inputSchema() : opts.inputSchema),
7879
outputSchema: toZod(opts.outputSchema),
7980
async handler(args: Input, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) {

packages/platform/platform-mcp/src/services/PlatformMcpModule.spec.ts

Lines changed: 0 additions & 83 deletions
This file was deleted.

packages/platform/platform-mcp/src/services/PlatformMcpModule.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export class PlatformMcpModule implements OnRoutesInit {
1313
protected server = inject<McpServer>(MCP_SERVER);
1414

1515
$onRoutesInit() {
16-
if (this.settings?.enabled) {
16+
if (this.isEnabled()) {
1717
const path = this.settings?.path || "/mcp";
1818

1919
this.app.post(
@@ -52,6 +52,10 @@ export class PlatformMcpModule implements OnRoutesInit {
5252
await transport.close();
5353
}
5454
}
55+
56+
private isEnabled() {
57+
return this.settings?.enabled !== false;
58+
}
5559
}
5660

5761
injectable(PlatformMcpModule);
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
export type Serializable = {[key: string]: Serializable} | Serializable[] | string | number | boolean | null;
2+
3+
export type JsonSchema = JsonSchemaObject | boolean;
4+
export type JsonSchemaObject = {
5+
// left permissive by design
6+
type?: string | string[];
7+
8+
// object
9+
properties?: {[key: string]: JsonSchema};
10+
additionalProperties?: JsonSchema;
11+
unevaluatedProperties?: JsonSchema;
12+
patternProperties?: {[key: string]: JsonSchema};
13+
minProperties?: number;
14+
maxProperties?: number;
15+
required?: string[] | boolean;
16+
propertyNames?: JsonSchema;
17+
18+
// array
19+
items?: JsonSchema | JsonSchema[];
20+
additionalItems?: JsonSchema;
21+
minItems?: number;
22+
maxItems?: number;
23+
uniqueItems?: boolean;
24+
25+
// string
26+
minLength?: number;
27+
maxLength?: number;
28+
pattern?: string;
29+
format?: string;
30+
31+
// number
32+
minimum?: number;
33+
maximum?: number;
34+
exclusiveMinimum?: number | boolean;
35+
exclusiveMaximum?: number | boolean;
36+
multipleOf?: number;
37+
38+
// unions
39+
anyOf?: JsonSchema[];
40+
allOf?: JsonSchema[];
41+
oneOf?: JsonSchema[];
42+
43+
if?: JsonSchema;
44+
then?: JsonSchema;
45+
else?: JsonSchema;
46+
47+
// shared
48+
const?: Serializable;
49+
enum?: Serializable[];
50+
51+
errorMessage?: {[key: string]: string | undefined};
52+
} & {[key: string]: any};
53+
54+
export type ParserSelector = (schema: JsonSchemaObject, refs: Refs) => string;
55+
export type ParserOverride = (schema: JsonSchemaObject, refs: Refs) => string | void;
56+
57+
export type ZodVersion = 3 | 4;
58+
59+
export type Options = {
60+
name?: string;
61+
module?: "cjs" | "esm" | "none";
62+
withoutDefaults?: boolean;
63+
withoutDescribes?: boolean;
64+
withJsdocs?: boolean;
65+
parserOverride?: ParserOverride;
66+
depth?: number;
67+
type?: boolean | string;
68+
noImport?: boolean;
69+
zodVersion?: ZodVersion;
70+
};
71+
72+
export type Refs = Options & {
73+
path: (string | number)[];
74+
seen: Map<object | boolean, {n: number; r: string | undefined}>;
75+
};
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env node
2+
import {mkdirSync, writeFileSync} from "fs";
3+
import {dirname} from "path";
4+
5+
import {jsonSchemaToZod} from "./jsonSchemaToZod.js";
6+
import {JsonSchema, ZodVersion} from "./Types.js";
7+
import {parseArgs, parseOrReadJSON, readPipe} from "./utils/cliTools.js";
8+
9+
const params = {
10+
input: {
11+
shorthand: "i",
12+
value: "string",
13+
required: process.stdin.isTTY && "input is required when no JSON or file path is piped",
14+
description: "JSON or a source file path. Required if no data is piped."
15+
},
16+
output: {
17+
shorthand: "o",
18+
value: "string",
19+
description: "A file path to write to. If not supplied stdout will be used."
20+
},
21+
name: {
22+
shorthand: "n",
23+
value: "string",
24+
description: "The name of the schema in the output."
25+
},
26+
depth: {
27+
shorthand: "d",
28+
value: "number",
29+
description: "Maximum depth of recursion before falling back to z.any(). Defaults to 0."
30+
},
31+
module: {
32+
shorthand: "m",
33+
value: ["esm", "cjs", "none"],
34+
description: "Module syntax; 'esm', 'cjs' or 'none'. Defaults to 'esm'."
35+
},
36+
type: {
37+
shorthand: "t",
38+
value: "string",
39+
description: "The name of the (optional) inferred type export."
40+
},
41+
noImport: {
42+
shorthand: "ni",
43+
description: "Removes the `import { z } from 'zod';` or equivalent from the output."
44+
},
45+
withJsdocs: {
46+
shorthand: "wj",
47+
description: "Generate jsdocs off of the description property."
48+
},
49+
zodVersion: {
50+
shorthand: "zv",
51+
value: "number",
52+
description: "Target Zod version: 3 or 4. Defaults to 4."
53+
}
54+
} as const;
55+
56+
async function main() {
57+
const args = parseArgs(params, process.argv, true);
58+
const input = args.input || (await readPipe());
59+
const jsonSchema = parseOrReadJSON(input);
60+
const zodVersion = (args.zodVersion === 3 ? 3 : 4) as ZodVersion;
61+
const zodSchema = jsonSchemaToZod(jsonSchema as JsonSchema, {
62+
name: args.name,
63+
depth: args.depth,
64+
module: args.module || "esm",
65+
noImport: args.noImport,
66+
type: args.type,
67+
withJsdocs: args.withJsdocs,
68+
zodVersion
69+
});
70+
71+
if (args.output) {
72+
mkdirSync(dirname(args.output), {recursive: true});
73+
writeFileSync(args.output, zodSchema);
74+
} else {
75+
console.log(zodSchema);
76+
}
77+
}
78+
79+
void main();
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
26+
export default jsonSchemaToZod;

0 commit comments

Comments
 (0)