This invention relates to a microcantilever stress sensor for detecting and quantifying low levels of contaminants in liquids and gases. The invention uses a chemical agent to impart chemical specificity to the microcantilever stress sensor. The microcantilever deflects when the chemical agent is replaced by a more strongly adsorbing chemical species. The magnitude of the deflection is then used as a measure of the quantity of contaminant present.