Magnesium is involved in the formation of bone, helps maintain normal muscle and nerve function, keeps heart rhythms normal and participates in more than 300 biochemical reactions in the body. Magnesium also helps the body produce energy and make proteins. Green leafy vegetables, nuts, legumes and whole grains are rich food sources of magnesium.