Skip to content

fix(memory): remove Zod-based outputSchema to fix serialization failures#3966

Open
ianliuy wants to merge 1 commit intomodelcontextprotocol:mainfrom
ianliuy:fix/issue-3622
Open

fix(memory): remove Zod-based outputSchema to fix serialization failures#3966
ianliuy wants to merge 1 commit intomodelcontextprotocol:mainfrom
ianliuy:fix/issue-3622

Conversation

@ianliuy
Copy link
Copy Markdown

@ianliuy ianliuy commented Apr 16, 2026

What's broken?

The memory server's tool definitions pass Zod schema objects directly to outputSchema, which violates the MCP spec requiring plain JSON Schema objects. This causes _zod serialization errors when the tools/list endpoint serializes schemas to JSON-RPC responses.

Who is affected?

Projects using the npm @modelcontextprotocol/sdk directly (rather than Claude Desktop's bundled SDK) encounter serialization failures when calling tools/list or invoking tools with outputSchema defined.

Root cause

outputSchema fields use Zod raw shapes like:

outputSchema: {
  entities: z.array(EntitySchema),
  relations: z.array(RelationSchema)
}

The MCP spec requires these to be plain JSON Schema objects.

Why not just replace with plain JSON Schema?

I investigated replacing Zod schemas with hand-written JSON Schema objects (the approach suggested in the issue). However, the current SDK (v1.26.0–1.29.0) cannot accept plain JSON Schema for outputSchema:

  1. tools/list silently drops itnormalizeObjectSchema() returns undefined for non-Zod objects, so outputSchema never appears in the response
  2. Tool calls crashvalidateToolOutput() calls safeParseAsync(undefined, ...) which throws Cannot read properties of undefined (reading '_zod')

This is a TypeScript SDK limitation, not a spec issue. Until the SDK adds native JSON Schema passthrough for outputSchema, the safest fix is to remove it entirely.

Fix

Remove outputSchema and structuredContent from all 9 tool registrations. Tools continue to return data via the content array (JSON text), preserving full functionality. The only change is that tools/list no longer advertises output schemas for these tools.

Testing

  • npm run build passes (TypeScript compilation clean)
  • Verified at runtime that tools still return correct JSON data via content
  • Verified that removing outputSchema skips output validation (no crashes)

Fixes #3622

Remove outputSchema and structuredContent from all 9 tool registrations
in the memory server. The Zod schema objects passed to outputSchema
violate the MCP spec (which requires plain JSON Schema) and cause
_zod serialization errors with the npm SDK.

The current SDK (1.26.0+) only accepts Zod types for outputSchema
and cannot pass through plain JSON Schema objects (they get silently
dropped from tools/list and cause crashes in output validation).
Removing outputSchema entirely is the safest fix until the SDK adds
native JSON Schema support for outputSchema.

All tool responses still return data via the content array (JSON text),
so no functionality is lost.

Fixes modelcontextprotocol#3622

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Yiyang Liu <37043548+ianliuy@users.noreply.github.com>
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.

outputSchema uses Zod objects instead of JSON Schema, violating spec and causing serialization failures

1 participant