Using first-principles calculations we have investigated the interaction of hydrogen molecules with clean and M (Ti, V, and Ni) doped Mg(0001) surfaces. The calculations have been carried out using plane-wave-based pseudopotential method under the formalism of density functional theory. First we have calculated the stability of the M atoms on the Mg surface. On the basis of the energetic criteria, we found that all these M atoms prefer to substitute one of the Mg atoms from the second layer than the top surface atom. In the second step we have studied the interaction of a hydrogen molecule with the clean and doped Mg surface. The results show that for M atoms at the surface, the hydrogen molecule undergoes spontaneous dissociative chemisorptions. However, for M atoms in the second layer, it requires to cross an activation barrier to undergo molecular dissociation. Furthermore, to understand the mobility of hydrogen atoms on the surface we have calculated the diffusion energy barriers for the M doped surface. Contrary to the molecular dissociation behavior, it is found that the mobility of hydrogen atoms on the surface is easier if the M atoms are placed in the second layer in comparison to that in the top surface layer. It is believed that the results of the present study provide useful information based on the first-principles calculations for synthesizing Mg based materials for hydrogen storage with optimal performance.