A and B-site doping has been viewed as a very effective approach to stabilise the desired perovskite cube phase of pure and doped hetero-structure CsPbI3-Pb1-xMgxSe and the simple system CsPb1-xMgxI3. In this analysis, the effect of (Mg2+) on the crystal structure, electronic, mechanical, and optical responses of hetero-structure CsPbI3-Pb1-xMgxSe and CsPb1-xMgxI3 were thoroughly investigated, by employing first-principles computations. A theoretical study of target responses of the metal-halide CsPbI3 is presented with a plane wave ultra-soft pseudopotential approach as personified in the CASTP code. The computed results show that the band gap of CsPbI3-Pb1-xMgxSe can be changed from '1.809eV' to '1.75eV' when the concentration range (x = 0 to 0.25) is changed. A valuable band gap of '0.48eV' and '1.28eV' of doped CsPbI3-Pb1-xMgxSe can be achieved under concentrations changed from (x = 0.25 to '0.75eV') and as shown in direct (Γ - Γ) nature and become optically active. The density of states shows that Cs-6p, I-4p, and Pb-6p states contribute to the valence band maximum, whereas the main involvement conduction band minimum by Mg-5p and Cs-6p states in the CsPbI3-Pb1-xMgxSe system. Elastic properties designate the flexibility and softness of target materials. The computed elastic parameters further indicate that this hetero-structure material is stable under the doping concentration condition. Replacing the Pb2+ site with Mg2+ has red-shifted the maximum absorption edges and changed the optical characteristics to be anisotropic. Their ability of these two materials with their Mg2+ based mixed halide perovskite nature for optoelectronic applications.