This study investigated the effect of Macleaya cordata extract (MCE) on the performance, gut health, and microbiota of laying hens. A total of 192 thirty-wk-old Hyline brown laying hens were randomly divided into 4 treatment groups. The CON group received a basal diet, while the low (MCE250), medium (MCE350), and high (MCE450) dose groups were supplemented with 250, 350, and 450 mg/kg MCE, respectively. The egg weight and Haugh unit demonstrated a linear and quadratic increase with the MCE dose during the initial 4-wk period of the experiment (P < 0.05). Furthermore, the dietary supplementation of MCE led to a significant enhancement in eggshell thickness and Haugh unit at wk 8 and the data showed a statistically significant linear and quadratic increase (P < 0.05). Serum cytokine assay showed that dietary supplementation of MCE led to linear and quadratic increases in IL-4 and IL-10 level (P < 0.05). Dietary supplementation of 350 and 450 mg/kg MCE was observed to result in linear and quadratic increase in serum lysozyme levels (P < 0.05). The addition of MCE to the diet resulted in a linear and quadratic increase in the levels of sIgA in the jejunum and ileum (P < 0.05). In terms of gene expression, the addition of MCE to the diet resulted in linear and quadratic increases in the expression of IL-10, IgA, Serpinb14, Serpinb14B, and OIH (P < 0.05). The expression of jejunal genes pIgR and IL-4 was observed to increase in a linear and quadratic manner, respectively, following the dietary addition of 350 mg/kg MCE and IL-1β decreased in a linear manner (P < 0.05). Moreover, these favorable effects were maximized at medium dosage (350 mg/kg) of MCE addition, and intestinal microbial composition in the control and MCE350 groups was assessed. 350 mg/kg MCE increased the relative abundance of Bryobacter and Parasutterella and decreased the relative abundance of Erysipelatoclostridium in the cecum (P < 0.05). Spearman correlation analysis revealed that Bryobacter, Parasutterella, Skermanella, and Erysipelatoclostridium were associated with nonspecific immune functions (P < 0.05). In conclusion, 350 mg/kg MCE supplementation elevated the immune response, and upregulated the expression of genes related to protein production in eggs, thereby improving egg quality. These effects may be associated with changes in the microbiota, specifically Bryobacter, Parasutterella, and Erysipelatoclostridium.