BackgroundThis study aimed to investigate the bidirectional causal relationships between trace elements (such as zinc, magnesium, phosphate, and folate) and upper gastrointestinal ulcers (including gastric and duodenal ulcers). We utilized a two-sample Mendelian randomization (MR) analysis to achieve this.MethodsWe conducted a two-sample MR analysis using summary-level data from genome-wide association studies (GWAS) obtained from public genomics repositories. We utilized a range of MR methods, including inverse-variance weighted (IVW), MR-Egger, and weighted median methods, and conducted a meta-analysis to synthesize results across different datasets. To ensure the robustness of our findings, we performed extensive sensitivity analyses, including pleiotropy assessment, heterogeneity tests, and leave-one-out analysis.ResultsOur findings are significant, indicating a positive causal relationship between increased zinc levels and the risk of gastric ulcers. Moreover, magnesium and folate appear to offer potential protective effects against gastroduodenal ulcers (p < 0.05). The meta-analysis further supports the causal relationship between zinc and gastric ulcers (p < 0.05), confirming zinc’s significant causal impact on this condition.ConclusionThe study confirms a positive causal relationship between zinc and gastric ulcers and highlights the complexity of how trace elements regulate the progression of upper gastrointestinal ulcers. These results provide a scientific basis for dietary recommendations regarding trace element intake in clinical and public health practices. They also offer new insights into effective prevention and treatment strategies for gastric and duodenal ulcers.