Electron-spin resonance carried out with scanning tunneling microscopes (ESR-STM) is a recently developed experimental technique that is attracting enormous interest on account of its potential to carry out single-spin on-surface resonance with subatomic resolution. Here we carry out a theoretical study of the role of tip-adatom interactions and provide guidelines for choosing the experimental parameters in order to optimize spin resonance measurements. We consider the case of the Fe adatom on a MgO surface and its interaction with the spin-polarized STM tip. We address three problems: first, how to optimize the tip-sample distance to cancel the effective magnetic field created by the tip on the surface spin, in order to carry out proper magnetic field sensing. Second, how to reduce the voltage dependence of the surface-spin resonant frequency, in order to minimize tip-induced decoherence due to voltage noise. Third, we propose an experimental protocol to infer the detuning angle between the applied field and the tip magnetization, which plays a crucial role in the modeling of the experimental results.