Our study investigated the causal relationship between immune cells, metabolites, and epilepsy using two-sample Mendelian Randomization (MR) and mediation MR analysis of 731 immune cell traits and 1400 metabolites. Our core methodology centered on inverse-variance weighted MR, supplemented by other methods. This approach was crucial in clarifying the potential intermediary functions of metabolites in the genetic links between traits of immune cells and epilepsy. We found a causal relationship between immune cells and epilepsy. Specifically, the genetically predicted levels of CD64 on CD14-CD16- are positively correlated with the risk of epilepsy (p < 0.001, OR = 1.0826, 95% CI 1.0361–1.1312). Similarly, metabolites also exhibit a causal relationship with both immune cells (OR = 1.0438, 95% CI 1.0087–1.0801, p = 0.0140) and epilepsy (p = 0.0334, OR = 1.0897, 95% CI 1.0068–1.1795), and sensitivity analysis was conducted to further validate these relationships. Importantly, our intermediate MR results suggest that the metabolite Paraxanthine to linoleate (18:2n6) ratio may mediate the causal relationship between immune cell CD64 on CD14-CD16- and epilepsy, with a mediation effect of 5.05%. The results suggest the importance of specific immune cell levels and metabolites in understanding epilepsy’s pathogenesis, which is significant for its prevention and treatment.