The mid-infrared instrument for the James Webb space telescope, VI: the medium resolution spectrometer