It is not the amount of a nutrient in a given food that matters, but its absorbability. Coffee actualy increases Mg elimination (being a diuretic). It's like spinach, which are suggested as a good source of iron by mnay and which is completely false, since it has little iron and phytate, whcih inhibits its absorption.
Daily supplementation with magnesium citrate is the only practical way I know to ensure optimal magnesium levels (not only to somewhat ameliorate a deficiency). When there is excess Mg stool movements become too frequent or too soft, which is corrected by reducing slightly the dialy dose.
Like I mentioned in this old article, Mg is a prima donna, which is difficult to acquire and retain and easy to lose, but which performs beautifully when present.
Med Hypotheses. 2001 Feb;56(2):163-70.
The multifaceted and widespread pathology of magnesium deficiency.
Even though Mg is by far the least abundant serum electrolyte, it is extremely important for the metabolism of Ca, K, P, Zn, Cu, Fe, Na, Pb, Cd, HCl, acetylcholine, and nitric oxide (NO), for many enzymes, for the intracellular homeostasis and for activation of thiamine and therefore, for a very wide gamut of crucial body functions. Unfortunately, Mg absorption and elimination depend on a very large number of variables, at least one of which often goes awry, leading to a Mg deficiency that can present with many signs and symptoms. Mg absorption requires plenty of Mg in the diet, Se, parathyroid hormone (PTH) and vitamins B6 and D. Furthermore, it is hindered by excess fat. On the other hand, Mg levels are decreased by excess ethanol, salt, phosphoric acid (sodas) and coffee intake, by profuse sweating, by intense, prolonged stress, by excessive menstruation and vaginal flux, by diuretics and other drugs and by certain parasites (pinworms). The very small probability that all the variables affecting Mg levels will behave favorably, results in a high probability of a gradually intensifying Mg deficiency. It is highly regrettable that the deficiency of such an inexpensive, low-toxicity nutrient result in diseases that cause incalculable suffering and expense throughout the world. The range of pathologies associated with Mg deficiency is staggering: hypertension (cardiovascular disease, kidney and liver damage, etc.), peroxynitrite damage (migraine, multiple sclerosis, glaucoma, Alzheimer's disease, etc.), recurrent bacterial infection due to low levels of nitric oxide in the cavities (sinuses, vagina, middle ear, lungs, throat, etc.), fungal infections due to a depressed immune system, thiamine deactivation (low gastric acid, behavioral disorders, etc.), premenstrual syndrome, Ca deficiency (osteoporosis, hypertension, mood swings, etc.), tooth cavities, hearing loss, diabetes type II, cramps, muscle weakness, impotence (lack of NO), aggression (lack of NO), fibromas, K deficiency (arrhythmia, hypertension, some forms of cancer), Fe accumulation, etc. Finally, because there are so many variables involved in the Mg metabolism, evaluating the effect of Mg in many diseases has frustrated many researchers who have simply tried supplementation with Mg, without undertaking the task of ensuring its absorption and preventing excessive elimination, rendering the study of Mg deficiency much more difficult than for most other nutrients.