fix: use getLiteralValue for Zod v3 method literal extraction#1876
Open
JosephDoUrden wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
Open
fix: use getLiteralValue for Zod v3 method literal extraction#1876JosephDoUrden wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
JosephDoUrden wants to merge 1 commit intomodelcontextprotocol:v1.xfrom
Conversation
|
commit: |
…andler Replace inline Zod v3/v4 literal extraction in Server.setRequestHandler and Client.setRequestHandler with the existing getLiteralValue() helper from zod-compat.ts, which already handles the _def.values[0] fallback for late Zod v3 releases (e.g., zod@3.25.1) where the literal value is stored under _def.values instead of _def.value. This fixes "Schema method literal must be a string" errors when constructing McpServer with zod@3.25.x. Fixes modelcontextprotocol#1380
d07003c to
f456351
Compare
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.
Summary
Fix
"Schema method literal must be a string"error when constructingMcpServerwith late Zod v3 releases (e.g.,zod@3.25.1) where the literal value is stored under_def.values[0]instead of_def.value.Closes #1380
Root cause
Server.setRequestHandlerandClient.setRequestHandlerhad inline Zod literal extraction that only checked_def.valueand.value. Inzod@3.25.x, the literal is stored under_def.values[0]instead. The existinggetLiteralValue()helper inzod-compat.tsalready handles this fallback correctly, but it wasn't being used in these two locations.Changes
src/server/index.ts: Replace inline v3/v4 literal extraction withgetLiteralValue()callsrc/client/index.ts: Same replacementThis is a v1.x backport as discussed in #1380 — the issue resolves itself in v2 with the Zod v3 removal.
Test plan
npm test)npm run build)AI Disclosure
AI assistance (Claude) was used for issue research and codebase exploration. The implementation was written and reviewed by the author.