From ce33ed436a140b01640543e19eba5cf57f94c8fe Mon Sep 17 00:00:00 2001 From: Levalicious <24482560+Levalicious@users.noreply.github.com> Date: Sun, 23 Aug 2026 22:47:33 -0400 Subject: [PATCH] fix(get_neighbors): omitted depth now honors the schema default (0 = immediate) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug_DepthDefaultMismatch_2026_08_23: three depth numberings coexist — C hop-count (1 = immediate), MCP schema 0-indexed (default 0), op_bench d0. The TS boundary bridges with depth+1, but the handler defaulted omitted depth to 1 (and getNeighbors' signature to 1), so schema-default calls silently returned TWO-hop neighborhoods. Canonical semantics: the 0-indexed schema numbering. C hop-count is internal; the single +1 translation lives at the TS boundary. New test pins the OMITTED-depth path specifically — explicit-depth tests cannot catch a default divergence. Behavioral change: default get_neighbors walks shrink from 2-hop to the schema-promised 1-hop set. Co-Authored-By: Claude Fable 5 Claude-Session: https://claude.ai/code/session_017GGvxNSpbpc5TVyMYYYzBr --- server.ts | 4 ++-- tests/memory-server.test.ts | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/server.ts b/server.ts index 0603987..963cde2 100644 --- a/server.ts +++ b/server.ts @@ -822,7 +822,7 @@ export class KnowledgeGraphManager { async getNeighbors( entityName: string, - depth: number = 1, + depth: number = 0, sortBy?: EntitySortField, sortDir?: SortDirection, direction: 'forward' | 'backward' | 'any' = 'forward' @@ -1690,7 +1690,7 @@ The file MUST be plaintext (.txt, .tex, .md, source code, etc.). For PDFs, use p return { content: [{ type: "text", text: JSON.stringify(paginateGraph(graph, args.entityCursor as number ?? 0, args.relationCursor as number ?? 0)) }] }; } case "get_neighbors": { - const neighbors = await knowledgeGraphManager.getNeighbors(args.entityName as string, args.depth as number ?? 1, args.sortBy as EntitySortField | undefined, args.sortDir as SortDirection | undefined, (args.direction as 'forward' | 'backward' | 'any') ?? 'forward'); + const neighbors = await knowledgeGraphManager.getNeighbors(args.entityName as string, args.depth as number ?? 0, args.sortBy as EntitySortField | undefined, args.sortDir as SortDirection | undefined, (args.direction as 'forward' | 'backward' | 'any') ?? 'forward'); // Record walker visits for returned neighbors knowledgeGraphManager.recordWalkerVisits(neighbors.map(n => n.name)); return { content: [{ type: "text", text: JSON.stringify(paginateItems(neighbors, args.cursor as number ?? 0)) }] }; diff --git a/tests/memory-server.test.ts b/tests/memory-server.test.ts index 52a2e76..00e9259 100644 --- a/tests/memory-server.test.ts +++ b/tests/memory-server.test.ts @@ -613,6 +613,22 @@ describe('MCP Memory Server E2E Tests', () => { expect(names).toContain('Child2'); }); + it('omitted depth must equal the schema default (0 = immediate only)', async () => { + // Bug_DepthDefaultMismatch_2026_08_23: the handler defaulted to 1 while + // the tool schema advertises 0, so omitted-depth calls silently returned + // TWO-hop neighborhoods. This pins the default path itself — the + // explicit-depth tests above cannot catch a default divergence. + const result = await callTool(client, 'get_neighbors', { + entityName: 'Root' + }) as PaginatedResult; + + expect(result.items).toHaveLength(2); + const names = result.items.map(n => n.name); + expect(names).toContain('Child1'); + expect(names).toContain('Child2'); + expect(names).not.toContain('Grandchild'); + }); + it('should get neighbors at depth 1 (includes neighbors of neighbors)', async () => { const result = await callTool(client, 'get_neighbors', { entityName: 'Root',