Skip to content

fix: support Zod runtimes that store literal values in _def.values[0]#1665

Open
Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Vadaski:fix/1380-mcpserver-schema-method-literal
Open

fix: support Zod runtimes that store literal values in _def.values[0]#1665
Vadaski wants to merge 2 commits intomodelcontextprotocol:mainfrom
Vadaski:fix/1380-mcpserver-schema-method-literal

Conversation

@Vadaski
Copy link

@Vadaski Vadaski commented Mar 12, 2026

Problem

buildSchemaMap in packages/core/src/types/types.ts reads schema.shape.method.value directly. 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 .value property nor ._def.value present. This causes McpServer construction to fail with:

TypeError: Schema method literal must be a string

Steps to Reproduce

With a Zod runtime where literal schemas lack the .value shortcut, constructing new 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:

  1. schema.value (standard Zod shortcut)
  2. schema._def.value (Zod v3 internal)
  3. schema._def.values[0] (Zod 3.25.x variant)

Updated buildSchemaMap to use this helper instead of direct .value access.

Testing

Added a regression test at test/integration/test/issues/test1380.zod.literal-values.test.ts that mocks zod/v4 to expose literal schemas with only _def.values[0] (hiding both .value and ._def.value), then verifies new McpServer(...) does not throw.

Fixes #1380

…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>
@Vadaski Vadaski requested a review from a team as a code owner March 12, 2026 04:16
@changeset-bot
Copy link

changeset-bot bot commented Mar 12, 2026

⚠️ No Changeset found

Latest commit: dae1d57

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 12, 2026

Open in StackBlitz

@modelcontextprotocol/client

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/client@1665

@modelcontextprotocol/server

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/server@1665

@modelcontextprotocol/express

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/express@1665

@modelcontextprotocol/hono

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/hono@1665

@modelcontextprotocol/node

npm i https://pkg.pr.new/modelcontextprotocol/typescript-sdk/@modelcontextprotocol/node@1665

commit: 5c89932

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: new McpServer() throws "Schema method literal must be a string" during initialization (method literal stored under _def.values[0])

1 participant