Two-dimensional materials, such as transition metal dichalcogenides (TMD), are highly promising for future electronics applications. The metal ion migration within the layered structures plays an important role during device fabrication and can dramatically affect the device functionality, e.g., by changing the resistivity. While often harmful, the resistance switching has been harnessed in the TMD-based memristors. While metal atom migration in these materials has been previously investigated using first-principles calculations, surprisingly little work has been devoted to understanding the drift under applied electric field as is important in electronics applications. Here, we used density-functional theory calculations to study metal atoms and ions in MoS2-based devices. We investigate the formation and migration of Ag, Au, Cu, and Li metals using first principles and extend the results into macroscopic properties using kinetic Monte Carlo simulations. Our results point out the most favorable defects along with their charge states and provide their diffusion and drift speeds under different temperatures and electric fields. We compare our results to experimentally realized electrochemical metallization cell memristors based on vertically aligned MoS2 and provide insight on the switching mechanism. In detail, silver and copper are found to be viable active electrode materials and the choice between the two could lead to significantly different memristive behavior. Even as our focus is on vertically grown MoS2 memristors, the results of this study are also applicable to other types of electronic devices. locked icon locked icon locked icon locked icon locked icon locked icon locked icon locked icon locked icon locked icon locked icon locked icon locked icon locked icon locked icon Physics Subject Headings (PhySH)First-principles calculationsInterstitialsIonic transportResistive switchingTransition metal dichalcogenides