Summary
MCP stdio servers using npx are spawned per-session but never cleaned up when sessions end. Over time, orphaned processes accumulate and consume significant RAM.
Observed Behavior
On a 30GB RAM server, 41 orphaned context7-mcp processes were found consuming ~2.4GB of RAM total (~60-100MB each). Each subagent/session spawn creates a new npm exec @upstash/context7-mcp process chain that persists after the parent session ends.
Timeline of accumulation:
- 19:30 → 6 processes
- 19:39 → +3 (9 total)
- 20:35 → +3 (18 total)
- 23:32 → +9 (33 total, burst from parallel subagent spawns)
- 23:49 → +3 (42 total)
Root Cause
- MCP stdio protocol requires each client to spawn its own server process
- OpenClaw gateway spawns a new MCP server per session/subagent invocation
- When the session/subagent ends, the MCP server process is not terminated (no SIGTERM/SIGKILL sent)
npx exacerbates this by spawning a parent npm process + child node process (double the overhead)
Workaround
Installing the MCP server globally (npm install -g @upstash/context7-mcp) and changing the config from:
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp", "--api-key", "..."]
}
to:
"context7": {
"command": "context7-mcp",
"args": ["--api-key", "..."]
}
This reduces per-process overhead (~40MB vs ~100MB) but does not fix the orphaning issue. Processes still accumulate; they just use less RAM each.
Expected Behavior
The gateway should track child MCP server PIDs and send SIGTERM when the parent session/subagent exits, regardless of exit reason (completion, error, timeout, cancellation).
Environment
- OpenClaw version: 2026.4.14
- Host OS: Linux 6.8.0-110-generic (x64)
- Host: Hetzner VPS, 32GB RAM
- Session type: Telegram direct chat + subagent spawns
Related Issues
Summary
MCP stdio servers using
npxare spawned per-session but never cleaned up when sessions end. Over time, orphaned processes accumulate and consume significant RAM.Observed Behavior
On a 30GB RAM server, 41 orphaned context7-mcp processes were found consuming ~2.4GB of RAM total (~60-100MB each). Each subagent/session spawn creates a new
npm exec @upstash/context7-mcpprocess chain that persists after the parent session ends.Timeline of accumulation:
Root Cause
npxexacerbates this by spawning a parent npm process + child node process (double the overhead)Workaround
Installing the MCP server globally (
npm install -g @upstash/context7-mcp) and changing the config from:to:
This reduces per-process overhead (~40MB vs ~100MB) but does not fix the orphaning issue. Processes still accumulate; they just use less RAM each.
Expected Behavior
The gateway should track child MCP server PIDs and send SIGTERM when the parent session/subagent exits, regardless of exit reason (completion, error, timeout, cancellation).
Environment
Related Issues