Skip to content

fix(memory): include type field in output schemas to fix validation error - #4090

Closed
aayushbaluni wants to merge 1 commit into
modelcontextprotocol:mainfrom
aayushbaluni:fix/3074-memory-schema-validation
Closed

fix(memory): include type field in output schemas to fix validation error#4090
aayushbaluni wants to merge 1 commit into
modelcontextprotocol:mainfrom
aayushbaluni:fix/3074-memory-schema-validation

Conversation

@aayushbaluni

Copy link
Copy Markdown

Summary

Fixes #3074

When structured output validation is enabled, the memory server's read_graph, search_nodes, and open_nodes tools fail with MCP error -32602 because stored entities contain a type field not declared in the output schema.

Root Cause

Entities in the JSONL knowledge graph include a type property (discriminator for entity vs relation lines), but the tool output schemas used strict validation that rejected unknown properties.

Fix

Declared optional type literals on entity and relation Zod schemas and attach the discriminators when loading from JSONL so structured responses match both the file format and the output schema.

Testing

  • Ran memory package Vitest suite (npm test in src/memory)
  • Verified TypeScript build succeeds

…rror

The memory server stores entities with a 'type' field in JSONL, but the
tool output schemas did not include this property. When structured output
validation is enabled, this causes MCP error -32602 for read_graph,
search_nodes, and open_nodes tools.

Fixes modelcontextprotocol#3074
@aayushbaluni
aayushbaluni force-pushed the fix/3074-memory-schema-validation branch from 42e3f80 to d8d57b8 Compare May 1, 2026 18:47
@olaservo

olaservo commented Jun 4, 2026

Copy link
Copy Markdown
Member

Thanks for the PR! The underlying issue with the type discriminator leaking into entity output and tripping additionalProperties: false was fixed in #3213 (commit 8af50b9) by stripping type in loadGraph() instead. Since the field is no longer present on returned entities, declaring it in the schema isn't needed, and we'd prefer the output schema stay strict. Closing as superseded by the merged fix.

Drafted with assistance from Claude Code.

@olaservo olaservo closed this Jun 4, 2026
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.

Memory MCP, schema validation error: MCP error -32602

2 participants