Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/memory/__tests__/resource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@ import { describe, it, expect, vi } from 'vitest';
import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { SubscribeRequestSchema, UnsubscribeRequestSchema } from '@modelcontextprotocol/sdk/types.js';
import {
getPackageVersion,
KnowledgeGraphManager,
registerKnowledgeGraphResource,
registerKnowledgeGraphSubscriptions,
} from '../index.js';
import packageJson from '../package.json' with { type: 'json' };

describe('package metadata', () => {
it('reads the server version from package.json', () => {
expect(getPackageVersion()).toBe(packageJson.version);
});
});

describe('knowledge-graph resource', () => {
it('registers with kebab-case name, correct URI, and JSON mime type', () => {
Expand Down
30 changes: 28 additions & 2 deletions src/memory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,36 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { SubscribeRequestSchema, UnsubscribeRequestSchema } from "@modelcontextprotocol/sdk/types.js";
import { z } from "zod";
import { promises as fs } from 'fs';
import { promises as fs, readFileSync } from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';

export function getPackageVersion(): string {
let currentDir = path.dirname(fileURLToPath(import.meta.url));

while (true) {
const packageJsonPath = path.join(currentDir, 'package.json');

try {
const packageJson = JSON.parse(readFileSync(packageJsonPath, 'utf-8')) as {
name?: string;
version?: string;
};
if (packageJson.name === '@modelcontextprotocol/server-memory' && packageJson.version) {
return packageJson.version;
}
} catch {
// Keep walking up until we find this workspace package.
}

const parentDir = path.dirname(currentDir);
if (parentDir === currentDir) {
return '0.6.3';
}
currentDir = parentDir;
}
}

// Define memory file path using environment variable with fallback
export const defaultMemoryPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'memory.jsonl');

Expand Down Expand Up @@ -256,7 +282,7 @@ const RelationSchema = z.object({
// The server instance and tools exposed to Claude
const server = new McpServer({
name: "memory-server",
version: "0.6.3",
version: getPackageVersion(),
});

const RESOURCE_URI = "memory://knowledge-graph";
Expand Down
Loading