servers
servers copied to clipboard
Environment variables not respected in @modelcontextprotocol/server-memory package
Description
The published version of @modelcontextprotocol/server-memory (0.6.2) on npm does not respect the MEMORY_FILE_PATH environment variable. The repository source code correctly handles environment variables, but the compiled version published to npm uses a hardcoded path for the memory file.
Fix
Publish to npm the latest 0.6.3 version
Steps to Reproduce
- Install the package with
npm i -g @modelcontextprotocol/server-memory - Set environment variable:
export MEMORY_FILE_PATH="/custom/path/memory.json" - Run the server:
mcp-server-memory - Observe that the memory file is still created at the default location, not the path specified in the environment variable
Expected Behavior
The server should use the path specified in the MEMORY_FILE_PATH environment variable for storing the memory file.
Actual Behavior
The server ignores the environment variable and always uses a hardcoded path: path.join(__dirname, 'memory.json').
Logs
When checking the source file index.ts (at github): https://github.com/modelcontextprotocol/servers/blob/main/src/memory/index.ts
// The code correctly handles environment variables
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;
But the compiled index.js in the distributed package has:
// Environment variable handling is stripped during compilation
const MEMORY_FILE_PATH = path.join(__dirname, 'memory.json');
Additional Context
- The latest GitHub repository version is 0.6.3, but npm still has 0.6.2
- The issue can be resolved by publishing the 0.6.3 version to npm
Fix
Publish to npm the latest 0.6.3 version
Related items https://github.com/modelcontextprotocol/servers/issues/692 https://github.com/modelcontextprotocol/servers/issues/674 and https://github.com/modelcontextprotocol/servers/issues/220 could all be closed when this is fixed.
It’s confusing as when you read the code of the package at https://github.com/modelcontextprotocol/servers/tree/main/src/memory you are looking at pre-release code (even though the last change to the readme was on February 2nd). FYI @jerome3o-anthropic
I resolved (temporarily) by hardcoding a change to the code on-disk, at e.g., /Users/X/.nvm/versions/node/v22.5.1/lib/node_modules/@modelcontextprotocol/server-memory/dist/index.js
with this code to enable shared memory across clients and devices (overdid it with the argument/environment handling to avoid any ambiguities):
const defaultPath = '/Users/X/Library/CloudStorage/Dropbox/Memory/memories.jsonl'; // Hack
const MEMORY_FILE_PATH = process.env.MEMORY_FILE_PATH ||
(process.argv.includes('--memory-path') ?
process.argv[process.argv.indexOf('--memory-path') + 1] :
defaultPath);
console.error('Using memory file path:', MEMORY_FILE_PATH);
Was this ever fixed? I'm not able to get memory.json written anywhere.
Edit: I got it working.
+1? a lot of contributions for this issue, please merge it
Was this ever fixed? I'm not able to get
memory.jsonwritten anywhere.Edit: I got it working.
What's your solution? My only working workaround is an absolute path but it's not a great solution.
My understanding was that version 2025.4.25 finally included the fix for this, if you're still having this issue could you try adding @latest to your package version eg in your config use: @modelcontextprotocol/server-memory@latest?
My understanding was that version
2025.4.25finally included the fix for this, if you're still having this issue could you try adding@latestto your package version eg in your config use:@modelcontextprotocol/server-memory@latest?
I just replied to you here: https://github.com/modelcontextprotocol/servers/issues/1481#issuecomment-2951745237
I just did set it to
@latestand did reset the MCP server cache, though it still doesn't work as I expected. When I set"MEMORY_FILE_PATH": "memory.jsonl"I expect it to access thememory.jsonlin the project root, just like everything else in VS Code.server-memory@latestis not writing tomemory.jsonlin the project but to somewhere else, not sure where. At least it's not throwing an error, so I assume it's writing to somewhere else. I've been looking for the file, but I couldn't find it on my box. Do I misunderstand how the server works? Does it not interpret"memory.jsonl"as a relative path? The file does exist and when it setMEMORY_FILE_PATHto the absolute path, everything works.
This is so frustrating, none of the examples in docs works properly.
- Docker examples just fail with "Error: Cannot find module '/app/dist/index.js'",
- "npx" examples fail with NVM installed....
It would really help if maintainers put effort into quality control
Hey everyone,
I ran into the same issue and decided to solve it for myself by rewriting this server in Rust. It’s basically the same MCP implementation, but with some improvements to the search logic and with tokio under the hood — which should give better performance and handle resources more reliably.
If anyone’s interested, I’ve published it as a separate project.
There are brew formulas with prebuilt binaries for popular platforms on the releases page.
You can set the path to the memory file using the same approach — via the MEMORY_FILE_PATH environment variable.
Here’s the link: https://github.com/aliev/mcp_memory
Hey everyone,
Is there any update?
Running on a local machine with MacOS works fine, but using it via ssh-remote on a Ubuntu machine does not allow of use.
"memory": {
"type": "stdio",
"command": "npx",
"args": [
"-y",
"@modelcontextprotocol/server-memory@latest"
],
"env": {
"MEMORY_FILE_PATH": "${input:memory_file_path}"
},
"gallery": true
},
and:
"inputs": [
{
"id": "memory_file_path",
"type": "promptString",
"description": "Path to the memory storage file",
"password": false
}
]
When memory_file_path is set through VSCODE to /home/user/.mcp/memory.json, it cannot establish a connection. However, if I manually define the file path, it recognizes it but cannot write the memories.
Again, if using locally, both approaches work fine ...🤔
I also changed the r+w permission via chmod; it is really a little bit frustrating.
JUST a mention/note: Still not fixed. I ran into the same error today and still not knowing how memoy-tool exactly works. Why isn't there a good documentation about? Nah, just asking myself. ^_~ "Error: Failed to list local tools"
This still isn't (properly?) resolved. I'm using OpenCode (this works just fine, minimal translation for the MCP setup), and while the reference to the memory.json file works, the file is never written to when forming new memory. Pretty important for this to work cleanly, one would assume.
On the same topic - where is the default memory file stored if we don't define one?