From 04209ec24813c063775bb4e0e9e51bc265d3bf1c Mon Sep 17 00:00:00 2001 From: s2005 Date: Sat, 21 Dec 2024 18:38:12 +0100 Subject: [PATCH 1/3] feat(memory): add MEMORY_FILE_PATH environment variable support - Add environment variable MEMORY_FILE_PATH to configure custom storage location - Support both absolute and relative paths - Update documentation with configuration examples - Bump version to 0.6.3 --- src/memory/README.md | 23 +++++++++++++++++++++++ src/memory/index.ts | 14 +++++++++----- src/memory/package.json | 2 +- 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/memory/README.md b/src/memory/README.md index e405a0d4..eead5faf 100644 --- a/src/memory/README.md +++ b/src/memory/README.md @@ -158,6 +158,29 @@ Add this to your claude_desktop_config.json: } ``` +#### NPX with custom setting + +The server can be configured using the following environment variables: + +```json +{ + "mcpServers": { + "memory": { + "command": "npx", + "args": [ + "-y", + "@modelcontextprotocol/server-memory" + ], + "env": { + "MEMORY_FILE_PATH": "/path/to/custom/memory.json" + } + } + } +} +``` + +- `MEMORY_FILE_PATH`: Path to the memory storage JSON file (default: `memory.json` in the server directory) + ### System Prompt The prompt for utilizing memory depends on the use case. Changing the prompt will help the model determine the frequency and types of memories created. diff --git a/src/memory/index.ts b/src/memory/index.ts index 0117c920..14ef92ad 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -10,10 +10,15 @@ import { promises as fs } from 'fs'; import path from 'path'; import { fileURLToPath } from 'url'; +// Define memory file path using environment variable with fallback +const defaultMemoryPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'memory.json'); -// Define the path to the JSONL file, you can change this to your desired local path -const __dirname = path.dirname(fileURLToPath(import.meta.url)); -const MEMORY_FILE_PATH = path.join(__dirname, 'memory.json'); +// If MEMORY_FILE_PATH is just a filename, put it in the same directory as the script +const MEMORY_FILE_PATH = process.env.MEMORY_FILE_PATH + ? path.isAbsolute(process.env.MEMORY_FILE_PATH) + ? process.env.MEMORY_FILE_PATH + : path.join(path.dirname(fileURLToPath(import.meta.url)), process.env.MEMORY_FILE_PATH) + : defaultMemoryPath; // We are storing our memory using entities, relations, and observations in a graph structure interface Entity { @@ -178,8 +183,7 @@ class KnowledgeGraphManager { } } -const knowledgeGraphManager = new KnowledgeGraphManager(); - +const knowledgeGraphManager = new KnowledgeGraphManager; // The server instance and tools exposed to Claude const server = new Server({ diff --git a/src/memory/package.json b/src/memory/package.json index 741244b1..b64cf3b6 100644 --- a/src/memory/package.json +++ b/src/memory/package.json @@ -1,6 +1,6 @@ { "name": "@modelcontextprotocol/server-memory", - "version": "0.6.2", + "version": "0.6.3", "description": "MCP server for enabling memory for Claude through a knowledge graph", "license": "MIT", "author": "Anthropic, PBC (https://anthropic.com)", From 5d0bee029505c66fd94cb78df5e814f7107b4cce Mon Sep 17 00:00:00 2001 From: s2005 Date: Sat, 21 Dec 2024 18:54:35 +0100 Subject: [PATCH 2/3] fix(memory): revert back instantiation of KnowledgeGraphManager --- src/memory/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/memory/index.ts b/src/memory/index.ts index 14ef92ad..75b30aae 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -183,7 +183,7 @@ class KnowledgeGraphManager { } } -const knowledgeGraphManager = new KnowledgeGraphManager; +const knowledgeGraphManager = new KnowledgeGraphManager(); // The server instance and tools exposed to Claude const server = new Server({ From 05fb0eab366ef3b9c0fd0e4d8273c2fb800d7d17 Mon Sep 17 00:00:00 2001 From: s2005 <17839543+s2005@users.noreply.github.com> Date: Sat, 21 Dec 2024 18:59:17 +0100 Subject: [PATCH 3/3] Add newline before server instance initialization As it was before --- src/memory/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/memory/index.ts b/src/memory/index.ts index 75b30aae..62f7aeb6 100644 --- a/src/memory/index.ts +++ b/src/memory/index.ts @@ -185,6 +185,7 @@ class KnowledgeGraphManager { const knowledgeGraphManager = new KnowledgeGraphManager(); + // The server instance and tools exposed to Claude const server = new Server({ name: "memory-server",