| 1 | import { zodToJsonSchemaOptions } from '@yikart/common' |
| 2 | import { describe, expect, it } from 'vitest' |
| 3 | import { z } from 'zod' |
| 4 | |
| 5 | describe('mcpToolsHandler', () => { |
| 6 | it('tool 参数 schema 中的 date 字段可以转换为 JSON Schema', () => { |
| 7 | const schema = z.object({ |
| 8 | commentTime: z.coerce.date().optional(), |
| 9 | publishTime: z.coerce.date().optional(), |
| 10 | time: z.tuple([z.coerce.date(), z.coerce.date()]).optional(), |
| 11 | }) |
| 12 | |
| 13 | const jsonSchema = z.toJSONSchema(schema, { |
| 14 | ...zodToJsonSchemaOptions, |
| 15 | io: 'input', |
| 16 | }) |
| 17 | |
| 18 | expect(jsonSchema).toMatchObject({ |
| 19 | type: 'object', |
| 20 | properties: { |
| 21 | commentTime: { |
| 22 | type: 'string', |
| 23 | format: 'date-time', |
| 24 | }, |
| 25 | publishTime: { |
| 26 | type: 'string', |
| 27 | format: 'date-time', |
| 28 | }, |
| 29 | time: { |
| 30 | type: 'array', |
| 31 | }, |
| 32 | }, |
| 33 | }) |
| 34 | }) |
| 35 | }) |
| 36 |