A novel algorithm for the retrieval of the spatial mutual coherence function of the optical field of a light beam in the quasimonochromatic approximation is presented. The algorithm only requires that the intensity distribution is known in a finite number of transverse planes along the beam. The retrieval algorithm is based on the observation that a partially coherent field can be represented as an ensemble of coherent fields. Each field in the ensemble is propagated with coherent methods between neighboring planes, and the ensemble is then subjected to amplitude restrictions, much in the same way as in conventional phase recovery algorithms for coherent fields. The proposed algorithm is evaluated both for one- and two-dimensional fields using numerical simulations.