Commit 709cacb
feat: generate Zod schemas from TypeScript types using ts-to-zod library
This refactors the type generation approach to use the ts-to-zod library
for converting TypeScript types to Zod schemas, replacing the previous
manual schema generation.
Key changes:
- Add scripts/generate-schemas.ts using ts-to-zod as a library with:
- Custom pre-processing to inject SDK-specific features (Base64 validation,
description JSDoc tags, RELATED_TASK_META_KEY)
- Post-processing transforms for strict() mode, discriminatedUnions, enums
- AST-based schema post-processing with ts-morph for robust transformations
- Generate src/generated/sdk.types.ts (pre-processed TypeScript types)
- Generate src/generated/sdk.schemas.ts (Zod schemas with SDK conventions)
- Refactor src/types.ts to re-export most schemas from generated code
- Convert Request/Notification/Result from intersection to union types
for better type narrowing in switch statements
- Add union types: McpRequest, McpNotification, McpResult for type guards
- Fix test files for union type compatibility and new schema structures
- Add comprehensive schema comparison tests
The generated schemas maintain full compatibility with the existing API
while improving type safety and reducing manual maintenance burden.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>1 parent 67d79d4 commit 709cacb
File tree
29 files changed
+9474
-3549
lines changed- scripts
- src
- client
- examples
- client
- server
- generated
- server
- test
- client
- experimental/tasks/stores
- generated
- helpers
- integration-tests
- server
29 files changed
+9474
-3549
lines changedSome generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
| 136 | + | |
| 137 | + | |
135 | 138 | | |
136 | 139 | | |
137 | 140 | | |
| |||
0 commit comments