fix: support Zod runtimes that store literal values in _def.values[0]#1665
Open
Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
fix: support Zod runtimes that store literal values in _def.values[0]#1665Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Conversation
…modelcontextprotocol#1380) buildSchemaMap accessed schema.shape.method.value directly. In Zod runtimes that store literal values only in _def.values[0] (with neither the top-level .value shortcut nor _def.value present), this would throw "Schema method literal must be a string" during McpServer construction. Added getMethodLiteral() helper that reads the literal value from .value ?? ._def?.value ?? ._def?.values?.[0], and updated buildSchemaMap to use this helper. Fixes modelcontextprotocol#1380 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
@modelcontextprotocol/client
@modelcontextprotocol/server
@modelcontextprotocol/express
@modelcontextprotocol/hono
@modelcontextprotocol/node
commit: |
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
buildSchemaMapinpackages/core/src/types/types.tsreadsschema.shape.method.valuedirectly. In some Zod runtimes (particularly certain Zod 3.25.x releases), literal values are stored only in._def.values[0], with neither the top-level.valueproperty nor._def.valuepresent. This causesMcpServerconstruction to fail with:Steps to Reproduce
With a Zod runtime where literal schemas lack the
.valueshortcut, constructingnew McpServer({ name: 'my-server', version: '1.0' })throws the above error.Fix
Added
getMethodLiteral()helper that tries all three locations where a literal value may be stored:schema.value(standard Zod shortcut)schema._def.value(Zod v3 internal)schema._def.values[0](Zod 3.25.x variant)Updated
buildSchemaMapto use this helper instead of direct.valueaccess.Testing
Added a regression test at
test/integration/test/issues/test1380.zod.literal-values.test.tsthat mockszod/v4to expose literal schemas with only_def.values[0](hiding both.valueand._def.value), then verifiesnew McpServer(...)does not throw.Fixes #1380