Keep MacBook on when closed without keyboard and mouse
I would connect a Bluetooth keyboard and mouse if you can’t have physical cables connected. 

This function is in firmware, so you’d need to engineer a solution to change Apple’s conditions for closed clamshell mode. 


https://support.apple.com/en-us/HT201834