To determine the presence of atorvastatin (AT) in urine samples, a cost-effective and environmentally responsible technique has been developed combining magnetic molecularly imprinted polymer-based dispersive solid-phase microextraction and HPLC with UV detection. FESEM and TEM have been used to appropriately produce and analyze a magnetic molecularly imprinted polymer (MMIP), which has shown good selectivity and a high absorption capacity. Central composite design (CCD) optimized the factors influencing the suggested method’s extraction performance. The outcomes indicated that the proposed approach had a strong correlation (R2 > 0.99) within the linear range of 0.5–900 ng mL−1. With a high enrichment factor, the LOD and LOQ were 0.15 and 0.5 ng mL−1, respectively. For inter-day and intra-day experiments, the precisions expressed in terms of relative standard deviations were 2.51 % and 1.94 %, respectively. Urine samples were examined to evaluate the effectiveness of the suggested method, and extraction recoveries ranging from 90.5-97.7 % were found. These outcomes demonstrated how well the approach performed while analyzing AT in actual samples.