From cce08de417857f25941503be903a86f970055c21 Mon Sep 17 00:00:00 2001 From: Yusufhan Sacak <67666222+JosephDoUrden@users.noreply.github.com> Date: Wed, 2 Sep 2026 18:03:51 +0300 Subject: [PATCH 1/3] fix(memory): resolve Vitest false positive for expected rejection (#3893) Wrap the addObservations call in an async closure before asserting with .rejects.toThrow(). This prevents Vitest's global unhandled rejection handler from capturing the expected error before the assertion can intercept it, eliminating the false-positive "Unhandled Errors" warning that was failing CI. Fixes #3073 --- src/memory/__tests__/knowledge-graph.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/memory/__tests__/knowledge-graph.test.ts b/src/memory/__tests__/knowledge-graph.test.ts index 236242413a..628ca567ee 100644 --- a/src/memory/__tests__/knowledge-graph.test.ts +++ b/src/memory/__tests__/knowledge-graph.test.ts @@ -146,11 +146,11 @@ describe('KnowledgeGraphManager', () => { }); it('should throw error for non-existent entity', async () => { - await expect( - manager.addObservations([ + await expect(async () => { + await manager.addObservations([ { entityName: 'NonExistent', contents: ['some observation'] }, - ]) - ).rejects.toThrow('Entity with name NonExistent not found'); + ]); + }).rejects.toThrow('Entity with name NonExistent not found'); }); }); From 96c49c73647ba8904a6916f070f282691111db19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=9F=B3=E5=B2=B3=E5=B3=B0?= <132282304+syf2211@users.noreply.github.com> Date: Wed, 2 Sep 2026 08:04:28 -0700 Subject: [PATCH 2/3] fix(memory): read serverInfo.version from package.json (#4407) Fixes #4406. The memory server previously hardcoded serverInfo.version as "0.6.3", which no longer matched published calendar versions. Resolve package.json from both source and dist layouts so Docker and npm installs report the installed package version. Co-authored-by: syf2211 --- src/memory/__tests__/server-version.test.ts | 25 +++++++++++++++++++ src/memory/index.ts | 4 +-- src/memory/version.ts | 27 +++++++++++++++++++++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/memory/__tests__/server-version.test.ts create mode 100644 src/memory/version.ts diff --git a/src/memory/__tests__/server-version.test.ts b/src/memory/__tests__/server-version.test.ts new file mode 100644 index 0000000000..f9cf437d52 --- /dev/null +++ b/src/memory/__tests__/server-version.test.ts @@ -0,0 +1,25 @@ +import { describe, it, expect } from 'vitest'; +import { createRequire } from 'node:module'; +import path from 'path'; +import { fileURLToPath } from 'url'; +import { resolvePackageVersion, SERVER_VERSION } from '../version.js'; + +const packageJson = createRequire(import.meta.url)('../package.json') as { version: string }; + +describe('server version', () => { + it('uses package.json version for serverInfo', () => { + expect(SERVER_VERSION).toBe(packageJson.version); + expect(resolvePackageVersion()).toBe(packageJson.version); + }); + + it('resolves package.json from the dist layout', () => { + const distDir = path.join(path.dirname(fileURLToPath(import.meta.url)), '..', 'dist'); + const distVersionPath = path.join(distDir, 'version.js'); + + expect(() => createRequire(distVersionPath)('./version.js')).not.toThrow(); + const distModule = createRequire(distVersionPath)('./version.js') as { + SERVER_VERSION: string; + }; + expect(distModule.SERVER_VERSION).toBe(packageJson.version); + }); +}); diff --git a/src/memory/index.ts b/src/memory/index.ts index b8704a9515..d5b862ca60 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -8,6 +8,7 @@ import { promises as fs } from 'fs'; import path from 'path'; import { randomBytes } from 'crypto'; import { fileURLToPath } from 'url'; +import { SERVER_VERSION } from './version.js'; // Define memory file path using environment variable with fallback export const defaultMemoryPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'memory.jsonl'); @@ -276,10 +277,9 @@ const RelationSchema = z.object({ relationType: z.string().describe("The type of the relation") }); -// The server instance and tools exposed to Claude const server = new McpServer({ name: "memory-server", - version: "0.6.3", + version: SERVER_VERSION, }); const RESOURCE_URI = "memory://knowledge-graph"; diff --git a/src/memory/version.ts b/src/memory/version.ts new file mode 100644 index 0000000000..f1df958a44 --- /dev/null +++ b/src/memory/version.ts @@ -0,0 +1,27 @@ +import { createRequire } from 'node:module'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +export function resolvePackageVersion(): string { + const require = createRequire(import.meta.url); + const moduleDir = path.dirname(fileURLToPath(import.meta.url)); + const candidates = [ + path.join(moduleDir, 'package.json'), + path.join(moduleDir, '..', 'package.json'), + ]; + + for (const candidate of candidates) { + try { + const pkg = require(candidate) as { version?: string }; + if (pkg.version) { + return pkg.version; + } + } catch { + // Try the next candidate when running from dist/ or source. + } + } + + throw new Error('Could not locate package.json for server version'); +} + +export const SERVER_VERSION = resolvePackageVersion(); From 48723c95dc54ffb743650f0d75484434c8c254c6 Mon Sep 17 00:00:00 2001 From: King Star Date: Wed, 2 Sep 2026 23:04:34 +0800 Subject: [PATCH 3/3] fix(memory): reject dangling relations (#4477) Signed-off-by: King Star --- src/memory/README.md | 1 + src/memory/__tests__/knowledge-graph.test.ts | 32 ++++++++++++++++++++ src/memory/index.ts | 11 +++++++ 3 files changed, 44 insertions(+) diff --git a/src/memory/README.md b/src/memory/README.md index 0f294231a9..18851aedaa 100644 --- a/src/memory/README.md +++ b/src/memory/README.md @@ -72,6 +72,7 @@ Example: - `to` (string): Target entity name - `relationType` (string): Relationship type in active voice - Skips duplicate relations + - Fails if either the source or target entity doesn't exist - **add_observations** - Add new observations to existing entities diff --git a/src/memory/__tests__/knowledge-graph.test.ts b/src/memory/__tests__/knowledge-graph.test.ts index 628ca567ee..61e823a2a6 100644 --- a/src/memory/__tests__/knowledge-graph.test.ts +++ b/src/memory/__tests__/knowledge-graph.test.ts @@ -99,6 +99,38 @@ describe('KnowledgeGraphManager', () => { expect(graph.relations).toHaveLength(1); }); + it('should reject relations from non-existent entities', async () => { + await manager.createEntities([ + { name: 'Alice', entityType: 'person', observations: [] }, + ]); + + await expect( + manager.createRelations([ + { from: 'Ghost', to: 'Alice', relationType: 'knows' }, + ]) + ).rejects.toThrow('Entity with name Ghost not found'); + + const graph = await manager.readGraph(); + expect(graph.relations).toHaveLength(0); + }); + + it('should reject relation batches that reference non-existent target entities', async () => { + await manager.createEntities([ + { name: 'Alice', entityType: 'person', observations: [] }, + { name: 'Bob', entityType: 'person', observations: [] }, + ]); + + await expect( + manager.createRelations([ + { from: 'Alice', to: 'Bob', relationType: 'knows' }, + { from: 'Alice', to: 'Ghost', relationType: 'knows' }, + ]) + ).rejects.toThrow('Entity with name Ghost not found'); + + const graph = await manager.readGraph(); + expect(graph.relations).toHaveLength(0); + }); + it('should handle empty relation arrays', async () => { const newRelations = await manager.createRelations([]); expect(newRelations).toHaveLength(0); diff --git a/src/memory/index.ts b/src/memory/index.ts index d5b862ca60..3f1179dd66 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -151,6 +151,17 @@ export class KnowledgeGraphManager { async createRelations(relations: Relation[]): Promise { const graph = await this.loadGraph(); + const entityNames = new Set(graph.entities.map(e => e.name)); + + relations.forEach(r => { + if (!entityNames.has(r.from)) { + throw new Error(`Entity with name ${r.from} not found`); + } + if (!entityNames.has(r.to)) { + throw new Error(`Entity with name ${r.to} not found`); + } + }); + const newRelations = relations.filter(r => !graph.relations.some(existingRelation => existingRelation.from === r.from && existingRelation.to === r.to &&