Most of mine are M5. But it probably varies.
Although I like the look of black painted ones, they tend to rust after awhile. So I bought a bunch of stainless M5 and I'm slowly replacing them. I did need to get a variety of lengths. I bought maybe 12, 15, 20, 25 and I think one even longer. I got mine from Amazon in bags of maybe 100. A few bucks a bag, but my heirs will get these.
I suggest removing one from a water bottle cage or some other easy bolt. See if that fits the seat stays, dropouts or where ever you need to attach the rack. If it does, take that to your LBS. I'm sure they have some lying around that they can give or sell to you.
Seatpost racks may not handle the weight you want.
You say a mountain bike. I don't know that model but if it has a suspension, make sure the rack doesn't interfere with that.