L-tryptophan functionalized AgNPs were successfully fabricated using a one-pot synthesis method and assessed as a colorimetric probe for rapid and accurate determination of Mg2+ ions. The developed sensor showed a selective response towards Mg2+ with no interference from Ca2+ in the wide concentration range of 1–200 µM. The sensor's response was optimized in the pH range of 9–10, which can be attributed to the protonation of amine groups and their interaction with Mg2+ ions. The stability and selectivity of the sensor were examined in different salt (NaCl) and other metal ions, respectively. The L-tryptophan-AgNPs sensor detected Mg2+ with the limit of detection of 3 µM, which is way lower than the concentration range of magnesium in human serum (0.75–1.05 mM). The recovery values of the developed sensor were in the range of 96–102% for the determination of Mg2+ in urine samples. The obtained performances proved the potential application of the developed sensor for clinical diagnostic of Mg2+ ions where an accurate and rapid response is needed.