We report the fabrication of a magnesium diboride (MgB2) coil and evaluate its persistent-mode operation in a system cooled by a cryocooler with solid nitrogen (SN2) as a cooling medium. The main purpose of SN2 was to increase enthalpy of the cold mass. For this work, an in situ processed carbon-doped MgB2 wire was used. The coil was wound on a stainless steel former in a single layer (22 turns), with an inner diameter of 109 mm and height of 20 mm without any insulation. The two ends of the coil were then joined to make a persistent-current switch to obtain the persistent-current mode. After a heat treatment, the whole coil was installed in the SN2 chamber. During operation, the resultant total circuit resistance was estimated to be <7.4x10−14 Ω at 19.5 K±1.5 K, which meets the technical requirement for magnetic resonance imaging application.