-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat!: drop Zod v3 support #1460
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
Conversation
|
e95b6e3 to
697d5d1
Compare
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
404d54f to
9c1b7a3
Compare
258d6f2 to
466d704
Compare
fc2a605 to
95beccd
Compare
BREAKING CHANGE: This SDK now requires Zod v4.0 or later. - Remove all Zod v3 imports, types, and runtime detection - Simplify `SchemaOutput<S>` to use direct indexed access `S['_zod']['output']` - Remove `zod-to-json-schema` dependency (z4-mini has built-in JSON schema support) - Add closure-based handlers for prompts and tools to eliminate runtime type casts - Simplify `executeToolHandler` and `handleAutomaticTaskPolling` - Remove v3 test blocks from integration tests
- Remove ZodOptional import from 'zod' in mcp.ts, use new unwrapOptional helper - Add unwrapOptional() function to zodCompat.ts for v4 optional handling - Update isZodSchemaInstance() to only check for v4's _zod property - Remove outdated v3/v4 comments - Simplify test files: remove describe.each(zodTestMatrix) pattern - Tests now import z directly from 'zod/v4' - Clean up zodTestMatrix.ts (no longer needed)
- Consolidate task store validation in createToolExecutor (remove duplication) - Add @deprecated JSDoc to legacy completable exports (McpZodTypeKind, CompletableDef, unwrapCompletable)
Remove unused legacy exports: - unwrapCompletable function - McpZodTypeKind enum - CompletableDef interface
- Remove unused getLiteralValue() function - Remove v3 fallback .parse check in normalizeObjectSchema() - Remove unused value property from ZodV4Internal interface
- Remove ZodV4Internal interface (no longer accessing _zod.def) - Use public .type property instead of _zod.def.type - Use public .shape property instead of _zod.def.shape - Use public .unwrap() method instead of _zod.def.innerType - Simplify safeParse/safeParseAsync to use native schema methods
- Replace zodCompat.ts and zodJsonSchemaCompat.ts with simplified schema.ts
- Use native Zod v4 APIs: z.safeParse, z.safeParseAsync, z.toJSONSchema
- Remove raw shape support - all schemas must now use z.object({...})
- Add utility functions: schemaToJson, parseSchema, parseSchemaAsync
- Update all tools/prompts in tests and examples to use z.object()
- Update migration guides to document Zod schema requirement
- Replace z.safeParse with parseSchema in client.ts and server.ts - Remove direct zod/v4 imports from client.ts and server.ts - Update schema.ts to use public Zod v4 APIs (schema.type, schema.def) instead of internal ._zod properties
- Remove `& Result` type intersections from protocol and experimental tasks client - Relax ResponseMessage generic constraints to accept any type (defaulting to Result) - Standardize zod imports to use `import * as z from 'zod/v4'` consistently
…asts - getRequestSchema now returns z.ZodType<RequestTypeMap[M]> - getNotificationSchema now returns z.ZodType<NotificationTypeMap[M]> - Removes casts from setRequestHandler and setNotificationHandler in protocol.ts - Added JSDoc explaining why the internal cast is necessary
…ToolStream - AnyObjectSchema now uses z.core.$ZodObject (not just $ZodType) - Remove CompatibilityCallToolResultSchema from callToolStream - Simplify callToolStream to use concrete CallToolResultSchema - Update example files to match new API - Eliminates all type casts in experimental tasks client
Reverts the type parameter from `T = Result` back to `T extends Result` for ResultMessage, ResponseMessage, and takeResult to maintain proper type constraints.
The v2 examples incorrectly showed raw shapes instead of z.object() wrappers. Updated to be consistent with the documented requirement that v2 requires full Zod schemas.
When using registerToolTask with a two-argument handler (args, extra), an inputSchema must be provided. Without it, the executor calls the handler with only one argument, causing extra to be undefined. This fixes all remaining test failures after the rebase.
- Remove unused CallToolResultSchema import from simpleTaskInteractiveClient.ts - Apply prettier formatting to test files
…ndlers Tools using `(_args, extra)` handler signature require inputSchema to be defined, otherwise extra is undefined due to how the executor passes arguments.
be08dce to
8dc9279
Compare
Raw shapes (e.g., `{ prompt: z.string() }`) are no longer supported -
must use full Zod schemas (`z.object({ prompt: z.string() })`).
Summary
This PR removes Zod v3 support from the SDK. Users must now use Zod v4.0 or later.
Key changes:
zodCompat.ts,zodJsonSchemaCompat.ts)schema.tsutilities using native Zod v4 APIszod-to-json-schemadependency (Zod v4 has built-inz.toJSONSchema())inputSchema/argsSchemaBreaking Changes
1. Zod v4 required
Users must upgrade to Zod v4.0 or later and import from
zod/v4:2. Raw shapes no longer supported
Tool
inputSchemaand promptargsSchemamust now be full Zod schemas:3. Removed deprecated exports
completable()function removed from@modelcontextprotocol/server(useCompletable.string()etc.)Internal Changes
Replaced
zodCompat.tswithschema.tsThe 275-line compatibility layer was replaced with a ~95-line utility file using native Zod v4 APIs:
AnySchema=z.core.$ZodTypeAnyObjectSchema=z.core.$ZodObjectschemaToJson()wrapsz.toJSONSchema()parseSchema()/parseSchemaAsync()wrapz.safeParse()/z.safeParseAsync()getSchemaShape(),isOptionalSchema(),unwrapOptionalSchema()for schema introspectionSimplified tool/prompt execution
createToolExecutor()closure factory that captures schema types at registration timecreatePromptHandler()closure factory for promptsexecuteToolHandler()reduced from ~30 lines to a singletool.executor(args, extra)callRemoved dependencies
zod-to-json-schemaremoved (Zod v4 has built-in JSON Schema conversion)zod/v3from workspace dependenciesFiles Changed
packages/core/src/util/zodCompat.ts(275 lines)packages/core/src/util/zodJsonSchemaCompat.ts(53 lines)test/helpers/src/fixtures/zodTestMatrix.ts(v3/v4 test matrix)packages/core/src/util/schema.ts(94 lines)packages/server/src/server/mcp.ts(major refactor)zod/v4importsTest Plan
pnpm check:allpasses (typecheck + lint)pnpm test:allpasses (485+ tests)🤖 Generated with Claude Code