The 19-year-old, a regular in the Scotland U21 side, has made 58 first team appearances at Tynecastle.
Born in East Kilbride on the other side of the country, McGhee has been with Hearts since 2007 when he joined their youth system making his debut as a 16-year-old.
He is initially expected to train with Boro's U21s as he tries to work his way through to Premier League level.
Boro hold an option to convert the deal to a permanent one.
McGhee has made 16 appearances for the Scottish U21s, the most recent two as captain and has scored four career goals, all of which have come in Hearts victories - against Aberdeen, Queen of the South, Falkirk, and Arbroath.