We present a universal theory for the critical behavior of an impurity at the two-dimensional superfluid-Mott insulator transition. Our analysis is motivated by a numerical study of the Bose-Hubbard model with an impurity site by Huang et al. (Phys. Rev. B 94, 220502 (2016)), who found an impurity phase transition as a function of the trapping potential. The bulk theory is described by the $O(2)$ symmetric Wilson-Fisher conformal field theory, and we model the impurity by a localized spin-1/2 degree of freedom. We also consider a generalized model by considering an $O(N)$ symmetric bulk theory coupled to a spin-$S$ degree of freedom. We study this field theory using the $epsilon = 3 - d$ expansion, where the impurity-bulk interaction flows to an infrared stable fixed point at the critical trapping potential. We determine the scaling dimensions of the impurity degree of freedom and the associated critical exponents near the critical point. We also determine the universal contribution of the impurity to the finite temperature compressibility of the system at criticality. Our results are compared with recent numerical simulations.