More specifically, the invention relates to a sensor based on magnetic resonance for detecting the presence or monitoring the concentration of an analyte in a sample solution. The sensor comprises magnetic nanoparticles linked to a moiety upon which the analyte can reversibly bind, the nanoparticles being confined in a chamber with semipermeable walls which are impermeable to the nanoparticles but permeable to the analyte. Upon binding of the analyte to the nanoparticles, the latter aggregate which can be detected by a change in the T2 relaxation time of the sample solution within the chamber (magnetic relaxation switch). The analyte may be a carbohydrate such as glucose, an antibody, an amino acid, a nucleic acid, an oligonucleotide, a therapeutic agent, a peptide, a protein, etc. The assay may be read out using MRS or MRI, e.g. of well plates for high throughput analysis. The assay may be implantable.