  We report on hyperfine-resolved laser spectroscopy of the A$^2\Pi \leftarrow
$X$^2\Sigma^+$ transition of MgF, relevant for laser cooling. We recorded 25
rotational transitions with an absolute accuracy of better than 20 MHz,
assigned 56 hyperfine lines and determined precise rotational, fine and
hyperfine structure parameters for the A$^2\Pi$ state. The radiative lifetime
of the A$^2\Pi$ state was determined to be 7.2(3) ns, in good agreement with
\textit{ab initio} calculations. The transition isotope shift between bosonic
isotopologues of the molecule is recorded and compared to predicted values
within the Born-Oppenheimer approximation. We measured the Stark effect of
selected rotational lines of the A$^2\Pi \leftarrow $X$^2\Sigma^+$ transition
by applying electric fields of up to 10.6 kV cm$^{-1}$ and determined the
permanent electric dipole moments of $^{24}$MgF in its ground X$^2\Sigma^+$ and
first excited A$^2\Pi$ states to be $\mu_X=$2.88(20) D and $\mu_A=$3.20(22) D,
respectively. Based on these measurements, we caution for potential losses from
the optical cycling transition, due to electric field induced parity mixing in
the excited state. In order to scatter $10^4$ photons, the electric field must
be controlled to below 1 V cm$^{-1}$.
