The least error-prone way for computing the functional derivative $df(M)/dM(x)$ by hand is the use of the formula
$\int dx \frac{\partial f(M)}{\partial M(x)} N(x) = \frac{d}{dt} f(M+tN) |_{t=0}$,
where $N$ is of the same type as $M$ (but c-valued if $M$ is an operator).
The right hand side is easy to work out, and the result is a linear functional in $N$, hence can always be written in the form on the left side, giving the desired functional derivative.
This post has been migrated from (A51.SE)