After Mxy was punished by Fifth Dimension authorities, he was court-ordered to help out those whom he’d wronged in order to use his powers freely again, and his final task was to help Kara by offering her to salvage her friendship with Lena.
After failing over and over again, Kara thanked Mxy for the help and decided to just move forward anyway, accomplishing the Imp’s final task.
Peter Gadiot portrayed the character early on, with Thomas Lennon taking over the role in Season 5.
Mxy has appeared throughout the series since Season 2, when he came to National City to profess his love for Kara, endangering the lives of others with his mystical powers in an attempt to “woo” her.