Skip to content

fix(memory): strip extra properties from entities/relations to fix schema validation#3634

Open
ctonneslan wants to merge 1 commit intomodelcontextprotocol:mainfrom
ctonneslan:fix/memory-read-graph-extra-properties
Open

fix(memory): strip extra properties from entities/relations to fix schema validation#3634
ctonneslan wants to merge 1 commit intomodelcontextprotocol:mainfrom
ctonneslan:fix/memory-read-graph-extra-properties

Conversation

@ctonneslan
Copy link

Problem

read_graph, search_nodes, and open_nodes fail with:

McpError: MCP error -32602: Structured content does not match the tool's output schema: 
data/entities/0 must NOT have additional properties

This happens when the memory.jsonl file contains entities with extra properties not defined in EntitySchema (e.g. custom_id, metadata from older versions, or properties added by external tools).

The MCP SDK validates structuredContent against the outputSchema and rejects entities with extra fields.

Fix

Strip entities and relations to only include schema-defined fields before returning in all three graph-returning tools:

const cleanEntities = graph.entities.map(({ name, entityType, observations }) => ({
  name, entityType, observations
}));
const cleanRelations = graph.relations.map(({ from, to, relationType }) => ({
  from, to, relationType
}));

This ensures the output matches the schema while preserving all data in the underlying JSONL file (extra properties are still stored, just not returned in the structured output).

Fixes #3144

…output

read_graph, search_nodes, and open_nodes fail with schema validation
error when the memory.jsonl file contains entities with additional
properties not in the EntitySchema (e.g. custom_id from older versions
or external tools).

The MCP SDK validates structuredContent against the outputSchema and
rejects entities with extra fields. Now strips entities and relations
to only include schema-defined fields before returning.

Fixes modelcontextprotocol#3144
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 on read_graph for entities with additional properties

1 participant