Detection of magnesium in a buffer?
$\ce{Mg^2+}$ forms complexes with 4-(2-Pyridylazo)resorcinol that can be detected spectrophotometrically: Simultaneous spectrophotometric determination of calcium and magnesium in water, described by E. Gómez, J.M. Estela, V. Cerdà in Analytica Chim. Acta 1991, 249, 513-518.

(DOI: 10.1016/S0003-2670(00)83027-5)