Where to get gear shifter for 31.8mm handle bars?
22.2 mm (7⁄8 in) is the standard diameter for the brake, shifter and grip area of MTB handlebars. 

I think you bought a bar that was designed for bar-end shifters only. Easiest way out of this is to swap the bar for one that allows shifters and brakes to be mounted on the area between the stem and forward turn.