there are several kinds of magnesium, each created for different purposes. i like this list from bulletproof's dave asprey. magnesium threonate is recommended for memory and brain functioning. that seems the most related to mental health, though there are other ones that provide relief for sore muscles and constipation, and which promote energy and relaxation.
PLEASE NOTE: i am NOT a doctor, but a licensed clinical social worker who stresses the inextricably linked nature of emotions and the psychiatric manifestations of the body's organ/system processes. i am not giving medical advice; i am sharing things i find interesting, and may have supported my recovery (i am still recovering) from mold toxicity and acute chemical sensitivity.