Using x-ray photoemission spectroscopy, we investigated the self-metalation of free-base tetraphenylporphyrin (2HTPP) on thin MgO(100) films on Ag(100). The deposition of one monolayer 2HTPP on MgO results in the formation of magnesium(ii) tetraphenylporphyrin (MgTPP) at room temperature. We demonstrate that the efficiency of the reaction drastically depends on the morphology of the oxide layers. The latter is changed by varying the substrate temperature during the oxide growth. We observe the complete metalation of the 2HTPP monolayer when the MgO films are grown at 393 K. The increase of the growth temperature to 573 K leads to the reduction of the percentage of metalated molecules to ∼50%. We ascribe these results to the fact that MgTPP formation takes place through the hydroxilation of steps and defects on the MgO surface, which leads to an increase of the OH component in the O 1s line.