I have M3's sitting in a bookshelf and they sound great! Bass response is unchanged from when I had them outside the bookshelf. I only have 3 or 4 inches max clearance for the ports.

Biggest issue may be keeping items on the shelves from resonating due to the vibrations from the speakers. If you have a good number of books in your bookshelf, then that will add enough mass to the unit to keep resonances tamed.