Skip to content

Commit dc21983

Browse files
authored
Merge pull request #2567 from modelcontextprotocol/claude/issue-2361-20250817-1626
fix: Change memory server default filename from memory.json to memory.jsonl
2 parents 534e1cb + 78af9dd commit dc21983

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/memory/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,14 +173,14 @@ The server can be configured using the following environment variables:
173173
"@modelcontextprotocol/server-memory"
174174
],
175175
"env": {
176-
"MEMORY_FILE_PATH": "/path/to/custom/memory.json"
176+
"MEMORY_FILE_PATH": "/path/to/custom/memory.jsonl"
177177
}
178178
}
179179
}
180180
}
181181
```
182182

183-
- `MEMORY_FILE_PATH`: Path to the memory storage JSON file (default: `memory.json` in the server directory)
183+
- `MEMORY_FILE_PATH`: Path to the memory storage JSONL file (default: `memory.jsonl` in the server directory)
184184

185185
# VS Code Installation Instructions
186186

src/memory/index.ts

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,43 @@ import path from 'path';
1111
import { fileURLToPath } from 'url';
1212

1313
// Define memory file path using environment variable with fallback
14-
const defaultMemoryPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'memory.json');
14+
const defaultMemoryPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'memory.jsonl');
1515

16-
// If MEMORY_FILE_PATH is just a filename, put it in the same directory as the script
17-
const MEMORY_FILE_PATH = process.env.MEMORY_FILE_PATH
18-
? path.isAbsolute(process.env.MEMORY_FILE_PATH)
19-
? process.env.MEMORY_FILE_PATH
20-
: path.join(path.dirname(fileURLToPath(import.meta.url)), process.env.MEMORY_FILE_PATH)
21-
: defaultMemoryPath;
16+
// Handle backward compatibility: migrate memory.json to memory.jsonl if needed
17+
async function ensureMemoryFilePath(): Promise<string> {
18+
if (process.env.MEMORY_FILE_PATH) {
19+
// Custom path provided, use it as-is (with absolute path resolution)
20+
return path.isAbsolute(process.env.MEMORY_FILE_PATH)
21+
? process.env.MEMORY_FILE_PATH
22+
: path.join(path.dirname(fileURLToPath(import.meta.url)), process.env.MEMORY_FILE_PATH);
23+
}
24+
25+
// No custom path set, check for backward compatibility migration
26+
const oldMemoryPath = path.join(path.dirname(fileURLToPath(import.meta.url)), 'memory.json');
27+
const newMemoryPath = defaultMemoryPath;
28+
29+
try {
30+
// Check if old file exists and new file doesn't
31+
await fs.access(oldMemoryPath);
32+
try {
33+
await fs.access(newMemoryPath);
34+
// Both files exist, use new one (no migration needed)
35+
return newMemoryPath;
36+
} catch {
37+
// Old file exists, new file doesn't - migrate
38+
console.error('DETECTED: Found legacy memory.json file, migrating to memory.jsonl for JSONL format compatibility');
39+
await fs.rename(oldMemoryPath, newMemoryPath);
40+
console.error('COMPLETED: Successfully migrated memory.json to memory.jsonl');
41+
return newMemoryPath;
42+
}
43+
} catch {
44+
// Old file doesn't exist, use new path
45+
return newMemoryPath;
46+
}
47+
}
48+
49+
// Initialize memory file path (will be set during startup)
50+
let MEMORY_FILE_PATH: string;
2251

2352
// We are storing our memory using entities, relations, and observations in a graph structure
2453
interface Entity {
@@ -434,6 +463,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
434463
});
435464

436465
async function main() {
466+
// Initialize memory file path with backward compatibility
467+
MEMORY_FILE_PATH = await ensureMemoryFilePath();
468+
437469
const transport = new StdioServerTransport();
438470
await server.connect(transport);
439471
console.error("Knowledge Graph MCP Server running on stdio");

0 commit comments

Comments
 (0)