Here's an idea for magic that could just be modded in (right now probably).
I'd try it, but I don't know how to mod (hehe)
Anyway, instead of making a race, caste, or other qualification that makes someone "magical" by default, make it a weapon.
Say a wand perhaps. Take the template of a crossbow, mod out the requirement for ammunition.
Change the fired projectile to somethning with a high melding point, or something, so that it will disappear after a few moments (long enough to hit a target).
Change the required skill to "Magic" or "Wand Use" and make the time it takes to level INSANE.
Do wahtever modding required to make wands and such accessable.
Now, every once and a while, a dwarf with magical ability will come to your fortress. Since it would take a hundred years to train one from scratch, you have to depend on one just arriving, unless you want to train one, in which case, magic school.
You could mod the time it takes to train to be less insane, so you have a bunch of sorcerers ready to defend your fortress.
All that needs to happen is making the crossbow use a different skill, have a different name, and change the projectile setup.
The only thing that I'm not sure is possible is the projectile setup. Maybe someone with more modding experience than I could suggest soemthing?