Skip to content

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

Open
aayushbaluni wants to merge 1 commit intomodelcontextprotocol:mainfrom
aayushbaluni:fix/3074-memory-schema-validation
Open

fix(memory): include type field in output schemas to fix validation error#4090
aayushbaluni wants to merge 1 commit intomodelcontextprotocol: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
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

1 participant