Apple - Magic Mouse disconnects randomly
As stated in the other answers there are numerous reasons to this. I have experienced 2.
Problems with the bluetooth antenna/signal
One of my Mac minis would drop the magic mouse, the keyboard and bluetooth headset regularly. I solved the problem by removing the antenna and putting it back (a few tries were necessary to get a stable connection).
On My macbook it seems the magic mouse and another bluetooth mouse seem to disconnect when the mouse is held in hand (hand covering the mouse) very close to the right side of the screen. It looks like there is a dark spot on the bluetooth antenna which prevents it from picking signal from devices positioned in particular places next to the computer.
My bluetooth headset loses the connection (drops some sound) when I stand next to the computer with my head and body between the computer and the right ear cup.
So you should check if you don't have a similar dark spot next to your computer. Or if the disconnections are not happening (more often) in particular situations which could impact the signal.
Batteries
Some batteries will start having problems with the contact, when oxidation occurs all you have to do is turn quickly the batteries in the mouse to remove the oxidation... If it's not enough you can try scratching the parts which are touching the mouse's contacts and the mouse's contacts with something metallic to remove any traces of oxidation.
Also tapping the mouse on the desk will increase the chances of batteries moving and shifting position just so slightly that they might be touching the connectors with a dirtier part.
Mismatched rechargeable batteries seem to create problems. Using two batteries both from the same brand but with different recharge cycles seems to trigger disconnections of my Razer mouse.
This answer also has a good explanation about how the battery level is calculated. It also states that some "cheap" batteries will discharge differently and will not be able to properly power the mouse after a short period of time:
...they can't supply the sudden bursts of power the radio in the mouse requires, so some transmissions are lost...
Other
One other major problem you might experience is interferences. You will want to have a look at this list of sources.
For the last few months, I've had the same problem with my magic mouse. The only fix I've found is to remove the battery cover and leave it off. I came across this advice from someone on another blog and it's worked for me.
The first thing to do would be to try replacing the batteries — even if they may seem full, there's still a chance they could affect performance.
If that doesn't work, take a look around your workspace for possible sources of interference, such as cordless phones or microwaves. Apple has a knowledge base article listing many possible sources, and suggestions on how to avoid problems.
Finally, if the problem is easily reproducible, perhaps you should take your computer and mouse in to the Apple Store to get their advice (and, if necessary, perhaps a replacement).
(It would also be interesting to note — if you have any other bluetooth devices, do they experience the same connection problems that your Magic Mouse does?)