From 97611910f4e3cdb8c2fadca20786d71599e706d6 Mon Sep 17 00:00:00 2001 From: Yiyang Liu <37043548+ianliuy@users.noreply.github.com> Date: Thu, 16 Apr 2026 14:28:20 -0700 Subject: [PATCH] fix(memory): remove Zod-based outputSchema to fix serialization failures 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 #3622 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Yiyang Liu <37043548+ianliuy@users.noreply.github.com> --- src/memory/index.ts | 65 +++++++-------------------------------------- 1 file changed, 10 insertions(+), 55 deletions(-) diff --git a/src/memory/index.ts b/src/memory/index.ts index b560bf1e53..7efbc27ad3 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -266,16 +266,12 @@ server.registerTool( description: "Create multiple new entities in the knowledge graph", inputSchema: { entities: z.array(EntitySchema) - }, - outputSchema: { - entities: z.array(EntitySchema) } }, async ({ entities }) => { const result = await knowledgeGraphManager.createEntities(entities); return { - content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }], - structuredContent: { entities: result } + content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] }; } ); @@ -288,16 +284,12 @@ server.registerTool( description: "Create multiple new relations between entities in the knowledge graph. Relations should be in active voice", inputSchema: { relations: z.array(RelationSchema) - }, - outputSchema: { - relations: z.array(RelationSchema) } }, async ({ relations }) => { const result = await knowledgeGraphManager.createRelations(relations); return { - content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }], - structuredContent: { relations: result } + content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] }; } ); @@ -313,19 +305,12 @@ server.registerTool( entityName: z.string().describe("The name of the entity to add the observations to"), contents: z.array(z.string()).describe("An array of observation contents to add") })) - }, - outputSchema: { - results: z.array(z.object({ - entityName: z.string(), - addedObservations: z.array(z.string()) - })) } }, async ({ observations }) => { const result = await knowledgeGraphManager.addObservations(observations); return { - content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }], - structuredContent: { results: result } + content: [{ type: "text" as const, text: JSON.stringify(result, null, 2) }] }; } ); @@ -338,17 +323,12 @@ server.registerTool( description: "Delete multiple entities and their associated relations from the knowledge graph", inputSchema: { entityNames: z.array(z.string()).describe("An array of entity names to delete") - }, - outputSchema: { - success: z.boolean(), - message: z.string() } }, async ({ entityNames }) => { await knowledgeGraphManager.deleteEntities(entityNames); return { - content: [{ type: "text" as const, text: "Entities deleted successfully" }], - structuredContent: { success: true, message: "Entities deleted successfully" } + content: [{ type: "text" as const, text: "Entities deleted successfully" }] }; } ); @@ -364,17 +344,12 @@ server.registerTool( entityName: z.string().describe("The name of the entity containing the observations"), observations: z.array(z.string()).describe("An array of observations to delete") })) - }, - outputSchema: { - success: z.boolean(), - message: z.string() } }, async ({ deletions }) => { await knowledgeGraphManager.deleteObservations(deletions); return { - content: [{ type: "text" as const, text: "Observations deleted successfully" }], - structuredContent: { success: true, message: "Observations deleted successfully" } + content: [{ type: "text" as const, text: "Observations deleted successfully" }] }; } ); @@ -387,17 +362,12 @@ server.registerTool( description: "Delete multiple relations from the knowledge graph", inputSchema: { relations: z.array(RelationSchema).describe("An array of relations to delete") - }, - outputSchema: { - success: z.boolean(), - message: z.string() } }, async ({ relations }) => { await knowledgeGraphManager.deleteRelations(relations); return { - content: [{ type: "text" as const, text: "Relations deleted successfully" }], - structuredContent: { success: true, message: "Relations deleted successfully" } + content: [{ type: "text" as const, text: "Relations deleted successfully" }] }; } ); @@ -408,17 +378,12 @@ server.registerTool( { title: "Read Graph", description: "Read the entire knowledge graph", - inputSchema: {}, - outputSchema: { - entities: z.array(EntitySchema), - relations: z.array(RelationSchema) - } + inputSchema: {} }, async () => { const graph = await knowledgeGraphManager.readGraph(); return { - content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }], - structuredContent: { ...graph } + content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }] }; } ); @@ -431,17 +396,12 @@ server.registerTool( description: "Search for nodes in the knowledge graph based on a query", inputSchema: { query: z.string().describe("The search query to match against entity names, types, and observation content") - }, - outputSchema: { - entities: z.array(EntitySchema), - relations: z.array(RelationSchema) } }, async ({ query }) => { const graph = await knowledgeGraphManager.searchNodes(query); return { - content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }], - structuredContent: { ...graph } + content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }] }; } ); @@ -454,17 +414,12 @@ server.registerTool( description: "Open specific nodes in the knowledge graph by their names", inputSchema: { names: z.array(z.string()).describe("An array of entity names to retrieve") - }, - outputSchema: { - entities: z.array(EntitySchema), - relations: z.array(RelationSchema) } }, async ({ names }) => { const graph = await knowledgeGraphManager.openNodes(names); return { - content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }], - structuredContent: { ...graph } + content: [{ type: "text" as const, text: JSON.stringify(graph, null, 2) }] }; } );