A piece of 3/4" Sch. 40 PVC pipe makes a good beater tool to try to force the batteries out of a MagD with minimal damage. First remove the rubber cover on the switch. Then use a 5/64" allen wrench to loosen up the set screw in the middle of the switch, it's way at the bottom of the hole. This will allow the whole switch assembly to be forced out the bottom of the light, along with any stuck batteries.
The 3/4" PVC is the perfect size. The ID is large enough to let it slip over the bulb post, and the protruding cam for the reflector, on the top of the switch. And the OD is small enough to make it past the snap in retaining ring inside the barrel. That ring is almost impossible to remove with the switch in place since there is a groove in the top of the switch holding it in the body groove.
Be aware that the 3/4" PVC will initially be hitting 4 small pieces of plastic between the top of the switch and the bulb post. As you try to force the switch, and batteries, out of the light, these will almost definitely be broken if any serious force is needed. But loss of these little braces won't affect the switch operation at all, so don't worry too much about breaking them. However, these pieces tend to break off fairly cleanly and then you have the flat end of the PVC hitting the flat end of the top of the switch. That will usually take quite a lot of force without damaging the switch operation. And depending how hard the batteries are stuck, it may take a lot of force. In a few rare cases, I've actually seen the metal walls of the body get bulged out by the force needed. But it's usually not too hard of a job to break the batteries loose once you can apply some direct force and not just try to "shake" the stuck battery loose.
Once you get it loose, you just need to clean everything up and install new batteries and you should be good to go.