Shell
#!/bin/bash
# Kill all MCP server processes and free memory
echo "π Finding MCP processes..."
MCP_BEFORE=$(ps aux | grep -E "mcp-server|npm exec.*mcp" | grep -v grep | wc -l | tr -d ' ')
MEM_BEFORE=$(ps aux | grep -E "mcp-server|npm exec.*mcp" | grep -v grep | awk '{sum+=$6} END {print int(sum/1024)}')
if [ "$MCP_BEFORE" -eq 0 ]; then
echo "β
No MCP servers running"
exit 0
fi
echo " Found $MCP_BEFORE processes using ${MEM_BEFORE}MB"
echo ""
echo "ποΈ Killing MCP servers..."
pkill -f "mcp-server" 2>/dev/null
pkill -f "npm exec.*mcp" 2>/dev/null
sleep 1
MCP_AFTER=$(ps aux | grep -E "mcp-server|npm exec.*mcp" | grep -v grep | wc -l | tr -d ' ')
if [ "$MCP_AFTER" -eq 0 ]; then
echo "β
All MCP servers killed"
echo "πΎ Freed ~${MEM_BEFORE}MB of memory"
else
echo "β οΈ $MCP_AFTER processes still running (may need sudo)"
fi