Solution (source code)

= Solution

Varying the scalar and integrating by parts gives
$$
\delta S=\int_M
(\nabla_a\nabla^a\psi-\mu^2\psi)\delta\psi\,d\operatorname{vol}_g,
$$
because the boundary term vanishes by the support assumption. The <fundamental lemma of the calculus of variations> therefore gives the <Klein-Gordon equation>
$$
\boxed{\nabla_a\nabla^a\psi-\mu^2\psi=0}.
$$