There are extensions for MIDI and  MIDI-over-Bluetooth for the MakeCode Editor.

To use on a computer, you can output raw MIDI serial data, then use Hairless MIDI to convert the serial data to MIDI and playback on a MIDI device of your choice. Here's and example using the Virtual MIDI piano keyboard.

And here's an example of Bluetooth MIDI

And you can also program with Bluetooth MIDI in Swift

There are also some great articles about MIDI on this community website. There is an example reusable MIDI class (built using the same hardware as above).

Further Information

Keywords for search: control a MIDI instrument from the micro:bit, Does the micro:bit support MIDI