You should be fine. (It's advisable not to keep the keyboard on top, discussed below).
This mode is known as closed-clamshell or closed-display mode. Apple even has a support document sharing guidelines regarding this mode:
However, a few general instructions need to be kept in mind:
Make sure your MacBook is placed on a flat surface with no obstructions to the vents and air-flows, especially towards the lower end of the back side. That's where the vents are placed.
Do not keep it close to other electronic items which tend to get hot. Ideally your MacBook shouldn't heat up. (You can check that by placing your hand on top of the lid).
Note: To complement point 1 & 2, ideally don't keep anything 3"-4" around your MacBook. Keep that area open with proper air flow.
Refrain from keep anything on top of the device and apply any kind of pressure. I'd advise you not to use it in the way that you have demonstrated (with the keyboard on top). Consider moving the keyboard from top and keeping it elsewhere.
A few folks prefer keeping it in a vertical orientation rather horizontal as it provides for better air flow and exposed vents. There are various cases/docks which allow you to house your MacBook in upright position (random example). This advise may be helpful if you are using the MacBook in clamshell mode for pro-longed period of time. It also helps in saving desk space. (Space on desk for your keyboard 🙂.)
Keep the MacBook plugged-in to a power source. However, also consider draining the battery to a full discharge once in a while (recommended is at least once a month) to maintain its health.
I have a similar setup with an external display, wired keyboard and wired mouse connected to my MacBook Pro. I make it a point to completely discharge the battery (thereby completing one charge cycle) once a month. The advise is purely based on personal experience (~5 years of usage) and generally understood guidelines regarding maintaining a MacBook Pro.