If $G$ is a compact group and $V$ is a representation, the inclusion $V^G \to V$ has an easy-to-write-down retract: \begin{equation*} V \to V^G,\:\: v \mapsto \frac{1}{|G|} \int_G g\cdot v\;dg \end{equation*}
If $\mathfrak{g}$ is a Lie algebra and $M$ a module, there is also a notion of the invariants $M^\mathfrak{g}$, but here this is all the elements that are annihilated by $\mathfrak{g}$. Is there a similarly nice retract $M \to M^\mathfrak{g}$? If $\mathfrak{g}$ were the Lie algebra of a Lie group, you should be able to get it by using the above formula "infinitesimally", but I'm having trouble working it out, and in any case it seems like you should be able to come up with it purely Lie-algebra-theoretically. Probably you need $\mathfrak{g}$ to be finite-dimensional, and/or other assumptions if they're helpful.
Thanks!
Purely in terms of Lie algebra cohomology the funcor $F:M\mapsto M^{\mathfrak{g}}$ is left-exact, and its right derived functors are the cohomology groups $H^n(\mathfrak{g},M)=R^nF(M)$.