We present a modification of the gauge cell Monte Carlo simulation method [A. V. Neimark and A. Vishnyakov, Phys. Rev. E 62, 4611 (2000)] designed for chemical potential calculations in small confined inhomogeneous systems. To measure the chemical potential, the system under study is set in chemical equilibrium with the gauge cell, which represents a finite volume reservoir of ideal particles. The system and the gauge cell are immersed into the thermal bath of a given temperature. The size of the gauge cell controls the level of density fluctuations in the system. The chemical potential is rigorously calculated from the equilibrium distribution of particles between the system cell and the gauge cell and does not depend on the gauge cell size. This scheme, which we call a mesoscopic canonical ensemble, bridges the gap between the canonical and the grand canonical ensembles, which are known to be inconsistent for small systems. The ideal gas gauge cell method is illustrated with Monte Carlo simulations of Lennard-Jones fluid confined to spherical pores of different sizes. Special attention is paid to the case of extreme confinement of several molecular diameters in cross section where the inconsistency between the canonical ensemble and the grand canonical ensemble is most pronounced. For sufficiently large systems, the chemical potential can be reliably determined from the mean density in the gauge cell as it was implied in the original gauge cell method. The method is applied to study the transition from supercritical adsorption to subcritical capillary condensation, which is observed in nanoporous materials as the pore size increases.