Mexican Jumping Beans are seeds from a shrub (Sebastiania pavoniana). The shrub grows in Mexico, especially in the northwest of the country, in the state of Sonora. The beans 'jump' because they contain a larva from a moth of the family Cydia. Other members of this family include the codling moth, which lays its eggs in apples - if you find a grub in your apple, it may well be the larva of the codling moth.
(QUESTION - What is worse then biting into an apple and finding a caterpillar? ANSWER - Biting into an apple and finding half a caterpillar).
After the moth has laid an egg inside the seed, the egg hatches, and the resulting larva then eats the seed from the inside, creating a nice living space as it does so.
The larva can live for a long time inside the seed. The 'jumping' is the result of the larva moving around inside the seed. It does this if it is too warm, in the hope of moving to a cooler spot!
If conditions are right, the larva will become a pupa, and hatch into a moth which will emerge from the seed.