Skip to content

feat: upgrade zod to v4 #163

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

Rain120
Copy link

@Rain120 Rain120 commented Aug 4, 2025

What I do 🎉🎉🎉

  • upgrade zod to v4
  • upgrade mcp version, replace the old tool handler by new tool register
  • upgrade mcp inspector debug tool
  • remove zod-to-json-schema
  • remove the function file of zodToJsonSchema

@Rain120 Rain120 changed the title feat: migrate zod to v4 feat: upgrade zod to v4 Aug 4, 2025
@hustcc
Copy link
Member

hustcc commented Aug 4, 2025

The test case run error! @Rain120

@Rain120 Rain120 changed the title feat: upgrade zod to v4 WIP: upgrade zod to v4 Aug 4, 2025
@Rain120
Copy link
Author

Rain120 commented Aug 4, 2025

@hustcc I'm working on fixing it.

@Rain120 Rain120 changed the title WIP: upgrade zod to v4 feat: upgrade zod to v4 Aug 8, 2025
"type": "array",
"minItems": 1,
"prefixItems": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是啥?感觉现在有点担心这些 json schema 会有些 MCP client 不能识别。

.array(data)
.describe("Data for area chart, such as, [{ time: '2018', value: 99.9 }].")
.nonempty({ message: "Area chart data cannot be empty." }),
.tuple([data], data)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个是啥意思?

stack: z
.boolean()
.optional()
.default(false)
.prefault(false)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个 diff 的区别是啥?


// Area chart tool descriptor
const tool = {
name: "generate_area_chart",
description:
"Generate a area chart to show data trends under continuous independent variables and observe the overall data trend, such as, displacement = velocity (average or instantaneous) × time: s = v × t. If the x-axis is time (t) and the y-axis is velocity (v) at each moment, an area chart allows you to observe the trend of velocity over time and infer the distance traveled by the area's size.",
inputSchema: zodToJsonSchema(schema),
inputSchema: schema,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

}));
function setupToolHandlers(server: McpServer): void {
for (const chart of getEnabledTools()) {
const { name, description, inputSchema } = chart?.tool || {};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里不需要 ?.吧?改成 foreach 是不是类型定制就没问题。

@@ -9,16 +9,14 @@ describe("validator", () => {
expect(() => {
const schema = Charts[chartType].schema;
z.object(schema).safeParse(MindMapSchema);
}).toThrow("Invalid parameters: node's name '文字动画' should be unique.");
}).toThrow("Cannot read properties of undefined (reading 'traits')");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的感觉不太对,自定义检验没了。

b: z.string(),
c: z.boolean(),
}),
z.toJSONSchema(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

和 tool 使用一样,用 schema.shape?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

charts 的 spec 文件,应该也需要改成 schema.shape,让生成的 json 文件,和最终在 mcp 中使用的保持一致性。

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在在运行MCP server的时候会报错,看着像 mcp/sdk底层是v3,在解析v4的scheme时会报错,需要依赖mcp/sdk v4 发布之后再升级,modelcontextprotocol/typescript-sdk#869

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那这个 PR 再等等?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK,我关注一下mcp sdk的进度吧

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Rain120 要么就参考https://github.com/hustcc/mcp-echarts/blob/main/src/tools/boxplot.ts 这里的写法,保证输出的 json schema 中没有奇奇怪怪的 key,甚至保证 json schema 不变。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants