A coupled ab initio and thermodynamic study of the Al-H-Mg system has been carried out and a self-consistent thermodynamic database has been obtained. Magnesium alanate Mg(AlH4)2, a candidate material for hydrogen storage, has been included into the database. According to Density Functional first principles calculations, the alanate is an insulator and its thermodynamic properties have been obtained at room temperature. This compound has been found metastable at 298.15 K and 1 bar. The alanate has been found thermodynamically stable only at high pressure when the formation of the binary β-MgH2 phase is neglected. A reassessment of thermodynamic parameters of the liquid phase in the binary Mg-H system has also been carried out in order to be consistent with the Al-H system. The present results can reproduce reasonably well the available experimental data.