Little is known about the associations of magnesium (Mg) and calcium (Ca) with hemoglobin glycation index (HGI) and triglyceride-glucose index (TyG) in adults. In this study, we examined the associations of serum Mg and Ca with HGI and TyG in adults with coronary artery disease (CAD). This hospital-based cross-sectional study included 10757 CAD patients with a mean age of 61.6 years. Serum concentrations of Mg and Ca were measured in clinical laboratory. Overall, serum Mg and Ca were inversely associated with HGI and TyG. In multivariable analyses, Mg and Ca were inversely associated with HGI (MgQ4 vs. Q3: -0.601 vs. -0.528; CaQ4 vs. Q1: -0.769 vs. -0.645). In terms of TyG, inverse associations of serum Mg and Ca with TyG were observed. The corresponding TyG values were 9.054 (vs. 9.099) for Mg and 9.068 (vs. 9.171) for Ca in the fourth quartile compared with the first quartile. Moreover, Mg, Ca or Mg/Ca ratio were also inversely associated with HbA1c and FBG. In path analysis, no mediating effects of obesity on "serum Mg (or Ca)- HGI (or TyG)" associations were observed. Generally, our study identified the inverse associations of the serum Mg and Ca levels with HGI and TyG in adults with CAD. Large sample longitudinal study, and particularly randomized controlled trials, are warranted to validate our findings and overcome the limitations of cross-sectional studies.