The incorporation of lithium by MgH2 through an electrochemical conversion reaction is a valuable alternative to Li intercalation into graphite for next-generation Li-ion cells. The incorporation of lithium occurs by the reduction of magnesium hydride to magnesium metal nanoparticles surrounded by an amorphous matrix of lithium hydride. In this study we present a computational investigation of the conversion reaction of MgH2 to give Mg and LiH by first-principles methods. Density functional theory calculations have been performed using plane waves and projector augmented wave (PAW) pseudopotentials within the generalized-gradient approximation by the VASP code. The existence of intermediate phases has been checked by finite temperature ab initio thermodynamic calculations. Also, the occurrence of solid solutions in the first stages of lithium incorporation has been studied by the supercell approach by predicting their thermodynamic stability at 0 K. Five different solid solutions have been mimed by forming 0D defects in the MgH2 lattice: (a) vacancies in the hydride sites; (b) interstitial lithium insertion; (c) substitution of lithium in hydride sites; (d) substitution of lithium in magnesium sites; (e) substitution of lithium in magnesium sites with parallel formation of vacancies in the hydride sites. Preliminary results about the thermodynamics of the conversion reaction in nanometric MgH2 clusters are also discussed.