MCP server env vars from .mcp.json not passed to spawned process

Resolved 💬 5 comments Opened Feb 2, 2026 by edumusikse 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

  1. Create .mcp.json in a project root:
{
  "mcpServers": {
    "memory": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-memory"],
      "env": {
        "MEMORY_FILE_PATH": "/Users/me/.claude-memory/memory.json"
      }
    }
  }
}
  1. Start a Claude Code session in that project directory
  2. Use a memory MCP tool (e.g., mcp__memory__search_nodes)
  3. Inspect the spawned mcp-server-memory process 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_PATH is not set on the spawned process (confirmed via ps 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.json env config works correctly when used by Claude Desktop via claude_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-memory specifically: 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-memory via npx
  • .mcp.json in project root

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗