Taken together, we clarified the protective effect of HEX in SARA- and S. aureus-induced mastitis, which may provide a potential strategy for mastitis prevention and highlight the protective role of beneficial endogenous metabolites in regulating disease outcomes. Here, HHEX is linked to mastitis.