Just the tip is brought very close to the surface of the object under investigation, the cantilever is deflected by the interaction between the tip and the surface, which is what the AFM is designed to measure.
Several types of interaction can be detected.