Precision spectroscopy of Mg atoms in a magneto-optical trap