Mergrave was a doctor in the city Castrovalva. Like all residents of the city, he wasn't real, but rather a block transfer computation creation of the Master.
When he was told to investigate a smashed window on the upper floor, he found the Doctor. He explained that Portreeve was in fact the Master. Mergrave sacrified his life to keep the Master trapped in a doomed Castrovalva. (TV: Castrovalva)