Mg is the reducing agent (gives away electrons); Cu2+ is the oxidising agent (accepts them)
Spectator ions and ionic equations
In the full equation Mg(s) + CuSO4(aq) → MgSO4(aq) + Cu(s), the sulfate ion SO42− appears on both sides unchanged
An ion that is unchanged in a reaction is a spectator ion — it does not take part in the chemistry
Leaving out the spectator ions gives the ionic equation, which highlights the actual redox change: Mg(s) + Cu2+(aq) → Mg2+(aq) + Cu(s)
A practice prompt
In the reaction Cu(s) + 2 AgNO3(aq) → Cu(NO3)2(aq) + 2 Ag(s), Cu loses two electrons to form Cu2+ (oxidation) while each Ag+ gains one electron to form Ag (reduction)
Copper is therefore the reducing agent here, and silver(I) is the oxidising agent