The least error-prone way for computing the functional derivative df(M)/dM(x) by hand is the use of the formula
∫dx∂f(M)∂M(x)N(x)=ddtf(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)