Skip to content

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

@kirill578

Description

@kirill578

Describe the bug
new McpServer() throws during construction with:

Error: Schema method literal must be a string

This happens before any user code registers tools/resources/prompts (during SDK initialization when it installs default request handlers like ping). It appears the SDK’s Server.setRequestHandler() only reads method literals from _def.value / .value, but in some Zod runtimes the literal is stored under _def.values[0].

Related theme / potentially overlapping work:

To Reproduce
Steps to reproduce the behavior:

  1. Install deps (any package manager):
  2. Run:
// repro.js
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
new McpServer({ name: "repro", version: "1.0.0" });
console.log("constructed");
  1. node repro.js

Expected behavior
new McpServer() constructs successfully (default handlers like ping should register without error).

Logs
Example stack:

Error: Schema method literal must be a string
    at Server.setRequestHandler (.../node_modules/@modelcontextprotocol/sdk/dist/cjs/server/index.js:117:19)
    at new Protocol (.../node_modules/@modelcontextprotocol/sdk/dist/cjs/shared/protocol.js:37:14)
    at new Server (.../node_modules/@modelcontextprotocol/sdk/dist/cjs/server/index.js:41:9)
    at new McpServer (.../node_modules/@modelcontextprotocol/sdk/dist/cjs/server/mcp.js:28:23)

Additional observed detail:

  • For the SDK’s internal request schemas (e.g. PingRequestSchema), method’s schema _def contains { type, values } and the literal is at _def.values[0], while _def.value and .value are undefined.
  • dist/cjs/server/index.js currently does:
    • methodValue = legacyDef?.value ?? v3Schema.value;
    • then throws if typeof methodValue !== 'string'

Additional context
Workaround (ugly): monkey-patch Server.prototype.setRequestHandler before new McpServer() to fallback to _def.values[0] when _def.value/.value are missing, then retry registration. This suggests the SDK should either:

  • use the existing compat helper (it already has logic to read values[0] in some places), or
  • extend Server.setRequestHandler method-literal extraction to check _def.values[0] as a fallback.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1Significant bug affecting many users, highly requested featurebugSomething isn't workingready for workEnough information for someone to start working on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions