Dev.to AI 🤖 Ai 👁 0 📖 4 min read

My Mac Kept Freezing Because of 555 Idle MCP Servers

My Mac kept freezing while I ran coding agents It has 24 GB of RAM. Swap sat at 38.7 GB out of 39.9 Nothing heavy was open. Just a few agent sessions, or so I thought TL;DR Each agent session starts its own copy of

My Mac Kept Freezing Because of 555 Idle MCP Servers

My Mac kept freezing while I ran coding agents

It has 24 GB of RAM. Swap sat at 38.7 GB out of 39.9

Nothing heavy was open. Just a few agent sessions, or so I thought

TL;DR

  • Each agent session starts its own copy of every MCP server in its global config
  • Desktop agent apps keep old sessions alive for days, and their MCP servers stay up with them
  • My Mac had 94 sessions holding 555 MCP server processes
  • Moving servers into project configs and closing old sessions fixes most of it
  • prismor discover mcp --prune --stop ended 373 copies in 6 seconds and gave me back 21 GB of swap

1. What was running

My cleanup script flagged 287 processes. Most were two lines repeated about a hundred times each:

npm exec get-an-expert-agent@latest
npm exec @microsoft/clarity-mcp-server

Both are MCP servers. I had started neither by hand

So I walked each process up to its parent and counted:

  • 94 agent sessions still alive, holding 3.9 GB
  • 105 copies of colab-mcp at 1.5 GB
  • 178 processes for get-an-expert at 508 MB
  • 178 processes for clarity at 492 MB
  • 94 copies of termmirror at 252 MB

That makes 555 MCP server processes, about a third of everything running on my machine

94 idle sessions, 555 MCP server processes: bar chart of resident memory and process counts by server

Those memory numbers sit on the low side. Most of these processes had idled for days, so macOS had pushed them into swap. And ps leaves swap out

2. My first guess was wrong

I blamed npx. It wraps each server in npm exec, and I assumed that wrapper swallowed the shutdown signal and left orphans behind

So I tested it. My script started a stand-in session and launched a server over stdio. Then it killed that session with SIGKILL to fake a crash

[direct]  session owns 2 processes:
    npm exec get-an-expert-agent@latest
    node .../get-an-expert-agent
[direct]  5s after the session is killed: 0 still running

Both exited. Once a session dies, its server's stdin closes and any stdio server shuts down

Then I checked parents. All 555 servers had a live agent process above them. Those sessions were open and idle

3. Real cause

Illustration: three workstations with sleeping computers, each connected to its own stack of MCP servers

Three things stack up

One copy per session. Each stdio MCP server runs as a child of whichever session launched it. Ten sessions means ten copies of every server

Global config. I had four servers in the top-level mcpServers of ~/.claude.json. So every session in every project started all four. Most of those sessions made zero calls to Clarity or Colab

Sessions that stay open. Claude's desktop app keeps each sidebar session running, MCP children included. 78 of my 94 sessions were over a day old, and my oldest had run for 156 hours

And npx doubles the bill. Each npx server is two processes, and its wrapper eats about as much memory as the server itself

Check: count MCP processes by parent

ps -axo pid,ppid,etime,command | grep -E 'npm exec|mcp' | grep -v grep | awk '{print $2}' | sort | uniq -c | sort -rn | head

Red flag: those parent PIDs repeat over and over, and each one belongs to an agent

4. Fixes that work today

  • Move servers out of global config and into each project's .mcp.json. Biggest win by far
  • Close sessions once they're done. /exit in the CLI, or close them in the desktop app
  • Install npx servers once with npm i -g <package> and point config at that binary. Half as many processes

5. What I added to Prismor

Prismor already sees each tool call my agents make, so it knows which MCP servers get used. I built three things on top of that

See it. prismor discover mcp now lists each server with its running copies, their memory and how many sessions called it in the last 7 days

Terminal screenshot of prismor discover mcp listing running MCP server copies, memory, usage and config

On my Mac one screen showed it all. Three servers ran about 90 copies each, with zero calls all week. Prismor flags those

Clean it up.

prismor discover mcp --prune --stop

Illustration: idle MCP servers being lifted off a conveyor into a recycling bin

  • --prune saves a backup, then drops flagged servers from global config. New sessions stop starting them
  • --stop ends copies running right now. Open sessions keep going and lose those servers' tools, which costs nothing when nobody calls them

Both commands show their plan and ask before acting

Stop idle servers I keep.

Illustration: an MCP gateway pausing an idle server while keeping the others connected

Some servers I do call now and then. Prismor's MCP gateway can stop those after a quiet period (--idle-timeout). Agents still see their tools, and my next call starts the server again in about a quarter of a second

I leave it off for servers that hold state between calls, like one keeping a browser open

6. Does it work?

I tested each fix in an isolated rig: 10 stand-in sessions with 4 real MCP servers each, 3 of them never called

Bar chart: 10 sessions with 4 MCP servers each, memory held by the servers across baseline, prune, stop and gateway modes

  • Baseline: 40 processes, 1,484 MB
  • After --prune: 10 processes, 401 MB (−73%)
  • After --stop: 10 processes, 401 MB, with all sessions still running
  • Gateway with idle stop: 10 processes, 145 MB (−90%)

Then I ran it on my own Mac. 373 copies ended in 6 seconds

Swap dropped from 38.3 GB to 17.2 GB, and every open session kept running

Limits

  • Usage counts cover Claude Code today. Other agents show copies and memory without usage
  • ps leaves out swapped memory, so on a busy machine real savings run higher than what Prismor reports

Try it

pip install prismor
prismor discover mcp

Prismor is open source: https://github.com/PrismorSec/prismor

https://prismor.dev

📰 Read the original article on Dev.to AI

Originally published by Dev.to AI. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.