If you're talking about D&D-like magic vs. steam-punk mecha, then magic has several things they can work with that are relatively minor changes to existing spells or new versions of old spells.
Because there are so many wizard spells that attack in so many different ways, I suspect they will be sufficient to defeat your mechas. Oh, the wizards will lose in the first round, due to "surprise" at facing these giant puffing, iron, golems. But they'll develop new tactics and spells quickly.
Enhance existing spells.
Bump a spell up to a higher spell level to increase the range. This helps protect your mages while they fight the mechs.
Make a more powerful version of Animate Object to just take control of the mechs from their drivers.
More anti-metal magic
D&D has flesh to stone spell. Use that template to create:
- Metal to Wood spell. Suddenly your Mecha has a wooden container vessel for their fire-based steam power plant. That's not good. And the thickness of all the load-bearing supports is now insufficient for the weight.
- Soften Metal spell. This is a spell that basically makes iron or steel more like warm butter. Too soft to hold its own weight.
The fire box of your mechas are also vulnerable to magic.
- Douse Fire quenches the fire in their firebox, rendering the mechas inert.
- Boost Fire spell (opposite of douse fire) makes the fire too hot, so it either blows up the mecha or melts the firebox.
And, of course, fireball and delayed blast fireball are always fan favorites for fighting any enemy...
Whatever your mecha's weapons are, your wizards are going to focus some energy on building defense spells to block it or them.
Back in the day, Bigby had all kinds of various "handy" spells. Let's work on a Bigby's Pushing Hand spell that literally just pushes on the mechs. Hard enough to knock them down.
Or let's use some sort of Freezing magic to either quench the firebox or make the metal too brittle to support the stresses they must bear.
Never forget the power of Wish and Limited Wish. Or weather spells to soak the mechas so they get stuck in mud.
Remember, too, that your wizards can teleport in, launch a quick attack from behind obstacles before the mecha even see them, then teleport out to safety.
They can also use scrying spells to see where the mecha drivers stop to encamp for the night. Then, while the crews are resting or restocking their fuel and water reservoirs or whatever, they can teleport in a variety of stealth attacks. Rogues, rust monsters, etc. are all viable options for night attacks against the crews when they're not ready for battle. Remember, if the fire in a steam engine cools, it takes time to build up enough steam pressure to be combat-ready again.
For that matter, they can just enchant arrows and let elf rangers punch holes in the water tank or the steam pressure vessel. Drain the tanks, stop the mechs. Now the crew has to patch the holes, refill the tanks, and then build up pressure again. While taking sniper fire from those rangers, who can take a few shots and vanish into the tree line before counter fire can find them.
As Secespitus mentions, powerful wizards could send the Mecha away. Either teleport them to an active volcano, out over the ocean, or to the elemental plane of fire. Or just a hundred meters up in the air ought to do it, if you don't want to get all fancy.
You can also teleport large rocks above the mecha. My guess is they don't move all that fast, so aiming should be possible.
Cast Darkness on the mech's windshields. Now they can't target you.
Wizards are highly adaptable. Mechas are not. They must use the attack methods they were designed with. That lack of flexibility means they cannot win in the long term.