fix(memory): remove Zod-based outputSchema to fix serialization failures#3966
fix(memory): remove Zod-based outputSchema to fix serialization failures#3966ianliuy wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
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>
|
@claude review |
|
Claude finished @cliffhall's task in 1m 35s —— View job PR Review
SummaryThis PR removes What the PR doesThe original code passed raw Zod schema objects (e.g. CorrectnessThe fix is correct and complete. All 9 affected tools are consistently updated:
Removing All tools continue returning data via Concerns1. This is a feature regression, not a definitive fix. The memory server was one of the few places in this codebase intentionally demonstrating MCP's structured tool output feature ( 2. The PR description overstates the SDK constraint slightly. The PR says the SDK "cannot accept plain JSON Schema for 3. No new tests. There are no tests for tool registration metadata (i.e., no test that asserts Minor notes
VerdictThe fix correctly resolves the immediate serialization crash. The approach is the right call given the SDK limitation. The main ask before merging: create or reference a follow-up issue to restore |
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_zodserialization errors when thetools/listendpoint serializes schemas to JSON-RPC responses.Who is affected?
Projects using the npm
@modelcontextprotocol/sdkdirectly (rather than Claude Desktop's bundled SDK) encounter serialization failures when callingtools/listor invoking tools withoutputSchemadefined.Root cause
outputSchemafields use Zod raw shapes like: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:tools/listsilently drops it —normalizeObjectSchema()returnsundefinedfor non-Zod objects, sooutputSchemanever appears in the responsevalidateToolOutput()callssafeParseAsync(undefined, ...)which throwsCannot 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
outputSchemaandstructuredContentfrom all 9 tool registrations. Tools continue to return data via thecontentarray (JSON text), preserving full functionality. The only change is thattools/listno longer advertises output schemas for these tools.Testing
npm run buildpasses (TypeScript compilation clean)contentoutputSchemaskips output validation (no crashes)Fixes #3622