Magnesium-doped CoFe2O4 nanoparticles (MgCF)@SiO2-NH-COOH were prepared through a step-wise procedure for the removal of two cationic dyes from real wastewater. MgCF was successfully synthesized through the co-precipitation technique. Subsequently, these nanoparticles were coated within a silica (SiO2) shell and functionalized with amino groups utilizing 3-Aminopropylethoxysilane (APTES). To assess its adsorption capabilities, the nanocomposite underwent further modification with Gallic acid (GA). MgCF@SiO2-NH-COOH has a well-developed pore structure with a BET surface area of 31.655m2/g, which also has a crystalline structure. Adsorption tests revealed the excellent performance of MgCF@SiO2-NH-COOH in removing Methylene Blue (MB) and Rhodamine B (RhB) dyes. Kinetic studies demonstrated that the adsorption of MB and RhB followed the Boyd kinetic model. The Langmuir isotherm model provided the best fit for the experimental data, with a maximum adsorption capacity of 103 mg/g and 89 mg/g for MB and RhB, respectively. Moreover, recycling tests established the high stability and reusability of MgCF-SiO2-APTES-GA nanocomposites, with consistent adsorption performance over at least five cycles. At the first stage, the adsorption was 98.6 % for MB and 95.3 % for RhB, and after five regenerations, the adsorption was 82.5 % for MB and 79.6 % for RhB. This research offers a cost-effective compound that addresses pressing environmental concerns related to the removal of organic dyes from wastewater.