We develop a theoretical formalism for the description of the interaction of microwave photons with a thin (compared to the photon wavelength) magnetic metasurface comprised of dipolarly interacting nanoscale magnetic elements. We derive a scattering matrix describing the processes of photon transmission and reflection at the metasurface boundary. As an example of the use of the developed formalism, we demonstrate that the introduction of a magnetic metasurface inside a microstrip electromagnetic waveguide quantitatively changes the dispersion relation of the fundamental waveguide mode, opening a nonpropagation frequency band gap in the waveguide spectrum. The frequency position and the width of the band gap are dependent on the waveguide thickness and can be controlled dynamically by switching the magnetic ground state of the metasurface. For sufficiently thin waveguides, the position of the band gap is shifted from the resonance absorption frequency of the metasurface. In such a case, the magnetic metasurface inside a waveguide works as an efficient reflector, as the energy absorption in the metasurface is small, and most of the electromagnetic energy inside the nonpropagation band gap is reflected.