MCP server env vars from .mcp.json not passed to spawned process
Status Fixed / completed
Maintainer reply None cached
Workaround ✓ Mentioned in thread ↓
Activity 5 comments · opened Feb 2, 2026 · closed Feb 2, 2026
Description
Environment variables defined in .mcp.json under a server's env key are not being passed to the spawned MCP server process. This means MCP servers that depend on env-based configuration (like @modelcontextprotocol/server-memory with MEMORY_FILE_PATH) silently fall back to defaults.
Steps to Reproduce
- Create
.mcp.jsonin a project root:
{
"mcpServers": {
"memory": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"],
"env": {
"MEMORY_FILE_PATH": "/Users/me/.claude-memory/memory.json"
}
}
}
}
- Start a Claude Code session in that project directory
- Use a memory MCP tool (e.g.,
mcp__memory__search_nodes) - Inspect the spawned
mcp-server-memoryprocess environment:
ps eww -p <PID> | grep MEMORY_FILE_PATH
Expected Behavior
The process should have MEMORY_FILE_PATH=/Users/me/.claude-memory/memory.json in its environment, and the MCP memory server should read/write to that file.
Actual Behavior
MEMORY_FILE_PATHis not set on the spawned process (confirmed viaps eww)- The server uses an ephemeral in-memory store instead of the configured file
- Data written via Claude Code's MCP tools is lost on server restart
- The same
.mcp.jsonenv config works correctly when used by Claude Desktop viaclaude_desktop_config.json
Diagnostic Evidence
# Claude Desktop's server (PID from Claude.app) — env var present:
MEMORY_FILE_PATH=/Users/me/.claude-memory/memory.json
# Claude Code's server (PID from npx) — env var missing:
MEMORY_FILE_PATH not set
Both servers use identical config ("env": {"MEMORY_FILE_PATH": "..."}) — only the Claude Code spawner fails to pass it through.
Impact
- MCP servers that rely on env vars for configuration silently malfunction
- No error or warning is shown — the server starts fine but with wrong config
- For
server-memoryspecifically: knowledge graph data is not persisted and not shared with Claude Desktop, defeating the purpose of a shared memory store
Environment
- macOS (Darwin 25.2.0, arm64)
- Claude Code (latest as of 2026-02-02)
@modelcontextprotocol/server-memoryvia npx.mcp.jsonin project root
5 Comments
Additional Finding: User-scope config also affected
Tried moving the MCP server config from project scope (
.mcp.json) to user scope viaclaude mcp add -e MEMORY_FILE_PATH=... -s user:The config shows correctly with the env var listed. However, the already-running server process in this session still doesn't have the env var:
This needs a fresh Claude Code session to test properly. Will update after restarting Claude Code to confirm whether user-scope config correctly passes env vars on fresh session start.
The
claude mcp getoutput confirms Claude Code knows about the env var — the question is whether it passes it to the spawned process.Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
Workaround Found
The
@modelcontextprotocol/server-memoryhas a default fallback path whenMEMORY_FILE_PATHis not set:This resolves to:
~/.npm/_npx/<hash>/node_modules/@modelcontextprotocol/server-memory/dist/memory.jsonlWorkaround: Symlink the default fallback file to the actual shared memory file:
This makes Claude Code's memory server read/write the same file as Claude Desktop, even though the env var isn't being passed.
Limitation: The symlink breaks whenever
npxrefreshes its cache for@modelcontextprotocol/server-memory, since the entire_npx/<hash>/directory gets recreated. Needs periodic re-symlinking.The underlying bug remains: Claude Code should be passing
envvars from.mcp.jsonto spawned MCP server processes, matching Claude Desktop's behavior.Closing as duplicate of #11927. Added diagnostic evidence from this reproduction as a comment there.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.