Skip to content

Environment variables not respected in @modelcontextprotocol/server-memory package #1018

Closed

Description

@syahiidkamil

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

  1. Install the package with npm i -g @modelcontextprotocol/server-memory
  2. Set environment variable: export MEMORY_FILE_PATH="/custom/path/memory.json"
  3. Run the server: mcp-server-memory
  4. 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

Activity

  1. rossshannon commented on Mar 24, 2025

    @rossshannon

    Related items #692 #674 and #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);
    
  2. added
    bugSomething isn't working
    server-memoryReference implementation for the Memory MCP server - src/memory
    on Mar 27, 2025
  3. self-assigned this
    on Mar 29, 2025
  4. anoblet commented on Apr 28, 2025

    @anoblet

    Was this ever fixed? I'm not able to get memory.json written anywhere.

    Edit: I got it working.

  5. thuantruong-kite commented on Jun 1, 2025

    @thuantruong-kite

    +1? a lot of contributions for this issue, please merge it

  6. sascharo commented on Jun 4, 2025

    @sascharo

    Was this ever fixed? I'm not able to get memory.json written 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.

  7. olaservo commented on Jun 7, 2025

    @olaservo
    Member

    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?

  8. sascharo commented on Jun 7, 2025

    @sascharo

    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?

    I just replied to you here: #1481 (comment)

    I just did set it to @latest and 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 the memory.jsonl in the project root, just like everything else in VS Code. server-memory@latest is not writing to memory.jsonl in 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 set MEMORY_FILE_PATH to the absolute path, everything works.

  9. DenysVuika commented on Jul 1, 2025

    @DenysVuika

    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

  10. aliev commented on Jul 11, 2025

    @aliev
    Contributor

    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

  11. Anselmoo commented on Jul 26, 2025

    @Anselmoo

    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.

  12. itsmetoolala commented on Sep 20, 2025

    @itsmetoolala

    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"

  13. Derjyn commented on Oct 16, 2025

    @Derjyn

    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?

  14. twooten commented on Dec 12, 2025

    @twooten

    This was a bit of a pain but got it working. I used the Claude Code extension in VS Code to resolve it.

    1. Clone the repo:
      git clone https://github.com/modelcontextprotocol/servers.git mcp-servers
    2. Build the memory server from source:
    cd /Users/my_user/projects/mcp-servers/src/memory
    npm install
    npm run build
    
    1. Configure Claude to use the local build
    Edit ~/.claude.json and add this to the project's mcpServers section:
    "memory": {
      "type": "stdio",
      "command": "node",
      "args": [
        "/Users/my_user/projects/mcp-servers/src/memory/dist/index.js"
      ],
      "env": {
        "MEMORY_FILE_PATH": "/Users/my_user/projects/.mcp/memory.jsonl"
      }
    }
    

    Hopefully this helps someone in the future.

  15. ferhimedamine commented on Jun 12, 2026

    @ferhimedamine
  16. laozhangzzz commented on Jun 25, 2026

    @laozhangzzz
  17. olaservo commented on Sep 3, 2026

    @olaservo
    Member

    The published package has read MEMORY_FILE_PATH since 0.6.3 was released in 2025 (c0939060), and every version since. The remaining path problems reported here are about relative values resolving against the package directory rather than the working directory; that is tracked in #692 and fixed by #4327. Closing this one as completed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingserver-memoryReference implementation for the Memory MCP server - src/memory

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions