A metal–organic framework with a pendant Lewis basic recognition site was employed to achieve selective detection of the nitro explosive TNP in the aqueous phase.