Magnesium (Mg). Guide. A magnesium test checks the level of magnesium in the blood. Magnesium is an important electrolyte needed for proper muscle, nerve, and enzyme function. It also helps the body use energy and is needed to move other electrolytes (potassium and sodium) into and out of cells. Most of the magnesium in the body is found in the bones and inside the cells. Only a tiny amount of magnesium is normally present in the blood.