Why does MCP server-memory ignore MEMORY_FILE_PATH when run through npx?
I configured the @modelcontextprotocol/server-memory MCP server in Claude Desktop with MEMORY_FILE_PATH pointing to a custom location, but memory.json is still created in the npx cache directory. The env var is set and the target directory exists, yet the server ignores it. Is this a known issue and is there a working workaround?
Originally asked on GitHub: https://github.com/modelcontextprotocol/servers/issues/692
6 answers
Status: not fixed; the issue was closed as not planned. The server code does read MEMORY_FILE_PATH, but when launched through npx the env var does not reliably reach the running server process, so the server falls back to the default path next to the installed package in the npx cache.
The workaround that worked in the thread was to bypass npx and run the installed server directly with node:
- Install globally: npm install -g @modelcontextprotocol/server-memory
- Find the install path: npm root -g
- Edit claude_desktop_config.json:
{ "memory": { "command": "node", "args": ["/usr/local/lib/node_modules/@modelcontextprotocol/server-memory/dist/index.js"], "env": { "MEMORY_FILE_PATH": "/Users/XX/Library/Application Support/Claude/mcp/memory.json" } } }
Use the path returned by npm root -g. The thread reports this lets MEMORY_FILE_PATH reach the server process and the custom memory.json is used.
Other workarounds mentioned in the thread: symlink the memory.json that npx created in the cache directory to your custom path (works as an interim fix, but one user reported an MCP update moved everything to a new directory), or patch /src/memory/index.ts to hardcode MEMORY_FILE_PATH (suggested in the thread, but not confirmed as tested).
Did this work for you?What @sstklen tried on GitHub (Worked)
Installed @modelcontextprotocol/server-memory globally with npm install -g, got the path from npm root -g, and changed the MCP config to run node with the absolute path to dist/index.js while keeping MEMORY_FILE_PATH in env.
Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Set MEMORY_FILE_PATH in the env block of the MCP server config and created the target directory, but memory.json was still written to ~/.npm/_npx/... under the package directory.
Source: https://github.com/modelcontextprotocol/servers/issues/692 (opens external site)
Did this work for you?What @Derjyn tried on GitHub (Didn't work)
In OpenCode, configured the server-memory entry with npx and environment MEMORY_FILE_PATH set to {file:./memory.json}; the memory file was neither written nor read.
Did this work for you?What @davidtorcivia tried on GitHub (Partly worked)
Symlinked the npx-cache memory.json to the desired custom location. It worked as an interim workaround; a later report said an MCP update moved the package into a new directory, so it was not durable.
Did this work for you?What @creativehelm tried on GitHub (Outcome unclear)
Suggested replacing the env-based path logic in /src/memory/index.ts with a hardcoded MEMORY_FILE_PATH. The thread does not confirm this was applied or tested.
Did this work for you?
Related questions
- mcp-server-fetch: 'AnyUrl' object has no attribute 'decode' error
- Does the official MCP Postgres example validate SQL before executing it?
- How to fix UTF-8 Japanese text corruption/crash in mcp-server-sqlite with Claude Desktop on Windows?
- MCP Knowledge Graph Memory Server fails with ${workspaceFolder} in MEMORY_FILE_PATH
- npx @modelcontextprotocol/server-filesystem: ERR_MODULE_NOT_FOUND for zod-to-json-schema