feat: upgrade zod to v4 - #163
Conversation
|
The test case run error! @Rain120 |
|
@hustcc I'm working on fixing it. |
| "description": "Data for histogram chart, it should be an array of numbers, such as, [78, 88, 60, 100, 95].", | ||
| "type": "array", | ||
| "minItems": 1, | ||
| "prefixItems": [ |
There was a problem hiding this comment.
这个是啥?感觉现在有点担心这些 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) |
| .boolean() | ||
| .optional() | ||
| .default(false) | ||
| .prefault(false) |
| 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, |
| })); | ||
| function setupToolHandlers(server: McpServer): void { | ||
| for (const chart of getEnabledTools()) { | ||
| const { name, description, inputSchema } = chart?.tool || {}; |
There was a problem hiding this comment.
这里不需要 ?.吧?改成 foreach 是不是类型定制就没问题。
| 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')"); |
| b: z.string(), | ||
| c: z.boolean(), | ||
| }), | ||
| z.toJSONSchema( |
There was a problem hiding this comment.
charts 的 spec 文件,应该也需要改成 schema.shape,让生成的 json 文件,和最终在 mcp 中使用的保持一致性。
There was a problem hiding this comment.
现在在运行MCP server的时候会报错,看着像 mcp/sdk底层是v3,在解析v4的scheme时会报错,需要依赖mcp/sdk v4 发布之后再升级,modelcontextprotocol/typescript-sdk#869
There was a problem hiding this comment.
@Rain120 要么就参考https://github.com/hustcc/mcp-echarts/blob/main/src/tools/boxplot.ts 这里的写法,保证输出的 json schema 中没有奇奇怪怪的 key,甚至保证 json schema 不变。
There was a problem hiding this comment.
zod v4 support has been introduced in sdk 1.23.0: https://github.com/modelcontextprotocol/typescript-sdk/releases/tag/1.23.0
0186dcb to
375eb86
Compare
What I do 🎉🎉🎉