Existing numerical tools for calculating the MHD stability of magnetically confined plasmas generally assume the existence of nested flux surfaces. These tools are therefore not immediately applicable to configurations with magnetic islands or regions with an ergodic magnetic field. However, in practice, these islands or ergodic regions are often small, and their effect on MHD stability can then be evaluated using a perturbation theory developed in the present paper. This procedure allows the effect of the broken magnetic topology on the stability of each eigenmode to be calculated without requiring any knowledge about the perturbed eigenfunctions.