From 3a70167fd62b772ddd6f9a25f3fa53ab009ee201 Mon Sep 17 00:00:00 2001 From: Charlie Tonneslan Date: Wed, 18 Mar 2026 11:40:28 -0400 Subject: [PATCH] fix(memory): strip extra properties from entities/relations in graph 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 #3144 --- src/memory/index.ts | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/memory/index.ts b/src/memory/index.ts index b560bf1e53..b07ae1a0e8 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -416,9 +416,19 @@ server.registerTool( }, async () => { const graph = await knowledgeGraphManager.readGraph(); + // Strip extra properties from entities and relations to match output schema. + // The JSONL file may contain entities with additional properties that were + // stored by older versions or external tools. + const cleanEntities = graph.entities.map(({ name, entityType, observations }) => ({ + name, entityType, observations + })); + const cleanRelations = graph.relations.map(({ from, to, relationType }) => ({ + from, to, relationType + })); + const cleanGraph = { entities: cleanEntities, relations: cleanRelations }; return { - content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }], - structuredContent: { ...graph } + content: [{ type: "text" as const, text: JSON.stringify(cleanGraph, null, 2) }], + structuredContent: cleanGraph }; } ); @@ -439,9 +449,16 @@ server.registerTool( }, async ({ query }) => { const graph = await knowledgeGraphManager.searchNodes(query); + const cleanEntities = graph.entities.map(({ name, entityType, observations }) => ({ + name, entityType, observations + })); + const cleanRelations = graph.relations.map(({ from, to, relationType }) => ({ + from, to, relationType + })); + const cleanGraph = { entities: cleanEntities, relations: cleanRelations }; return { - content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }], - structuredContent: { ...graph } + content: [{ type: "text" as const, text: JSON.stringify(cleanGraph, null, 2) }], + structuredContent: cleanGraph }; } ); @@ -462,9 +479,16 @@ server.registerTool( }, async ({ names }) => { const graph = await knowledgeGraphManager.openNodes(names); + const cleanEntities = graph.entities.map(({ name, entityType, observations }) => ({ + name, entityType, observations + })); + const cleanRelations = graph.relations.map(({ from, to, relationType }) => ({ + from, to, relationType + })); + const cleanGraph = { entities: cleanEntities, relations: cleanRelations }; return { - content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }], - structuredContent: { ...graph } + content: [{ type: "text" as const, text: JSON.stringify(cleanGraph, null, 2) }], + structuredContent: cleanGraph }; } );