fix: getParseErrorMessage now surfaces custom Zod v4 error messages#1663
Open
Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
fix: getParseErrorMessage now surfaces custom Zod v4 error messages#1663Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
In Zod v4, `error.message` is a JSON serialization of the issues array
rather than a user-facing string. The previous implementation prioritized
`error.message`, which caused custom error messages defined via
`.min(1, 'My custom error')` or custom error maps to be swallowed —
callers saw a raw JSON blob instead of the human-readable message.
Fix by extracting messages from `error.issues` first, falling back to
`error.message` only when no issue messages are available.
Also update call sites in `client.ts` and `mcp.ts` that were
hand-rolling `issues.map(i => i.message).join(', ')` to use
`getParseErrorMessage` consistently.
Closes modelcontextprotocol#1415
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
…coercion-functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
In Zod v4,
error.messageis a JSON serialization of the issues array rather than a user-facing string. The previous implementation ofgetParseErrorMessageprioritizederror.message, which caused custom error messages defined via.min(1, 'My custom error')or custom error maps to be completely swallowed. Instead of seeing"My custom error", callers received a raw JSON blob like:This affected tool input validation errors, output schema validation, prompt argument errors, and
listChangedoptions validation — anywhere the SDK surfaces a Zod parse failure to the developer.Closes #1415
Fix
Extract messages from
error.issuesfirst; fall back toerror.messageonly when no issue messages are available.Also updated call sites in
client.tsandmcp.tsthat were hand-rollingissues.map(i => i.message).join(', ')to usegetParseErrorMessagefor consistency.Changes
packages/core/src/util/schema.ts— fixgetParseErrorMessageto preferissue.messageover the JSON-serializederror.messagepackages/core/test/util/schema.test.ts— new test file with regression tests for custom Zod v4 messages and fallback behaviourpackages/client/src/client/client.ts— usegetParseErrorMessageinstead of rawerror.messagepackages/server/src/server/mcp.ts— usegetParseErrorMessageconsistently (3 call sites)Testing
All existing tests pass (
pnpm build:all && pnpm test:all).