In this study, the effects of different shear deformations on the structural stability, electronic structure, and optical properties of a Mg atom adsorption system of S vacancy defect SnS2 are systematically investigated based on density functional theory. It is shown that the presence of an S-vacancy defect makes the band gap of the SnS2 system significantly smaller than that of the perfect SnS2 system, and the SnS2 system is changed from a direct band gap semiconductor to an indirect band gap semiconductor. The optimal adsorption position of a Mg atom on the S-vacancy SnS2 system is above the S atom where the adsorption energy is the largest and the system is the most stable. The density of states of the adsorption system is predominantly contributed by the S-3p and Sn-5s orbital electrons. The imposition of shear deformation leads to the introduction of certain impurity energy levels in the adsorption system, and the forbidden bandwidth near the Fermi energy level decreases. As compared to the intrinsic SnS2, the absorption and reflection peaks of adsorption systems under different shear deformation are red-shifted and appear in the ultraviolet region. This improves the utilization of the adsorption system for ultraviolet light to a great extent. The model calculations in this paper are performed using the CASTEP module of the Material Studio (MS) software based on the first principles of Density Functional Theory (DFT) (Wei et al. in Physica B 545:99-106, 2018) for plane wave artifacts. Geometrical optimization and computational procedures are used to calculate the exchange-correlation energy using the Perdew-Burke-Ernzerhof (PBE) generalized function (Perdew et al. in Phys Rev B Condens Matter 48:4978, 1993) of the generalized gradient approximation (GGA). The Monkhorst-Pack method (Monkhorst and Pack in Phys Rev B 13:5188-5192, 1976) was used to rationalize the sampling of the highly symmetric k-points in the Brillouin zone. The grid of k-points is set to be 6 × 6 × 1. The plane-wave truncation energy is set to be 400eV. The energy convergence criterion is 1.0 × 10-5eV. The residual stress of all atoms is 0.01eV/Å. A vacuum layer with a thickness of 15Å is set up in the z-direction, which ensures that the interactions of the system along the z-axis between the top and the bottom layers can be ignored during the whole simulation process. We construct a 3 × 3 × 1 SnS2 system containing 27 atoms as the computational model. The intrinsic SnS2 contains 9 Sn atoms and 18 S atoms.