fix(memory): remove Zod-based outputSchema to fix serialization failures#3966
Open
ianliuy wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
fix(memory): remove Zod-based outputSchema to fix serialization failures#3966ianliuy wants to merge 1 commit intomodelcontextprotocol:mainfrom
ianliuy 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>
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.
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