Skip to content

Commit b093040

Browse files
ochafikclaude
andcommitted
feat: add library-based ts-to-zod schema generation
Add auto-generated Zod schemas from spec.types.ts using ts-to-zod as a library, with post-processing for SDK compatibility. ## What's New - `src/generated/spec.schemas.ts` - 145 auto-generated Zod schemas - `src/generated/index.ts` - Public API with explicit exports - `test/generated/spec.schemas.compare.test.ts` - 97 tests verifying equivalence - `scripts/generate-schemas.ts` - Library-based generator with post-processing ## Post-Processing The generator applies several transformations for SDK compatibility: 1. **Zod v4 import** - `"zod"` → `"zod/v4"` 2. **Index signatures** - `z.record().and(z.object())` → `z.looseObject()` 3. **typeof expressions** - `jsonrpc: z.any()` → `z.literal("2.0")` 4. **SDK hierarchy** - Notifications/Requests extend `NotificationSchema`/`RequestSchema` instead of `JSONRPCNotificationSchema`/`JSONRPCRequestSchema` ## Usage ```typescript // Generated schemas (drop-in compatible with types.ts) import { ProgressTokenSchema } from '@modelcontextprotocol/sdk/generated'; // Or continue using production schemas import { ProgressTokenSchema } from '@modelcontextprotocol/sdk/types.js'; ``` ## Design Decisions **Why types.ts is unchanged:** - Some manual schemas have refinements (`.int()`) not in generated schemas - 10 SDK-specific schemas not in spec (CompatibilityCallToolResultSchema, etc.) - Type guards (isJSONRPCRequest, etc.) remain manual - Full refactor to thin re-export layer is future work **Explicit exports in generated/index.ts:** - Each schema and type listed by name for legibility - Grouped by category (primitives, resources, tools, etc.) - No `export *` to avoid accidental internal exports 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 67d79d4 commit b093040

File tree

7 files changed

+5296
-15
lines changed

7 files changed

+5296
-15
lines changed

0 commit comments

Comments
 (0)