Mastitis, a major dairy industry challenge, is often caused by Staphylococcus aureus (S. aureus). Previous research linked gut microbiota disruption-induced by vancomycin in mice-to reduced microbial glutamine and increased mastitis susceptibility. This study hypothesizes that oral glutamine may regulate macrophage function and mitigate S. aureus mastitis. Our results showed that glutamine attenuated S. aureus-induced mastitis, protected the blood-milk barrier function, increased M2-type macrophages in the mammary gland, and increased the concentration of its metabolite alpha-Ketoglutaric acid (alpha KG) in both serum and mammary gland. In addition, the addition of alpha KG in mice significantly increased the transformation of M2-type macrophages and attenuated S. aureus-induced mastitis. Further studies revealed that alpha KG could initiate autophagy via oxidative phosphorylation, which in turn regulated the expression of Suppressor of cytokine signaling (SOCS3), a negative feedback inhibitor of the JAK/STAT signalling pathway. In vitro experiments verified that alpha KG enhances autophagy in macrophages, activates the JAK-STAT pathway, thereby promoting M2 polarization and alleviating S. aureus mastitis. This study revealed the key role of glutamine and its metabolite alpha KG in the mammary gland's resistance to pathogenic infections, and reveal the mechanism by which they regulate macrophage polarization, providing theoretical guidance for solving the prevention and treatment problems of mastitis. This highlights a potential dietary intervention for mastitis management in dairy cows, bridging gut health and infection resistance.