Skip to content

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

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

Metadata

Metadata

Assignees

Labels

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

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions