Why is there a transistor between the MCU and LED?
There are several reasons for using a transistor like that.  One is if the load (in this case, the LED) requires more current than a microcontroller I/O pin is capable of providing.  Another is if the load is powered by a voltage significantly different from the microcontroller's power supply.  Perhaps the microcontroller is powered by a 3.3 volt supply while the load is powered by 12 volts.  Another reason could be to isolate the microcontroller from various secondary effects, such as back EMF in the case of an inductive load such as a motor or relay.  It can also be useful to isolate relatively high current (but still within the I/O pin capability) but possibly high frequency signals that could cause ground bounce or similar issues, such as when the microcontroller is driving an LED with a high frequency PWM signal.