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 9865c5318e..0a9ce8ff0a 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -7,6 +7,7 @@ import { z } from "zod"; import { promises as fs } from 'fs'; import path from 'path'; 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'); @@ -253,10 +254,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();