Conventional methods for histopathologic tissue diagnosis are labor- and time-intensive and can delay decision-making during diagnostic and therapeutic procedures. We report the development of an automated and biocompatible handheld mass spectrometry device for rapid and nondestructive diagnosis of human cancer tissues. The device, named MasSpec Pen, enables controlled and automated delivery of a discrete water droplet to a tissue surface for efficient extraction of biomolecules. We used the MasSpec Pen for ex vivo molecular analysis of 20 human cancer thin tissue sections and 253 human patient tissue samples including normal and cancerous tissues from breast, lung, thyroid, and ovary. The mass spectra obtained presented rich molecular profiles characterized by a variety of potential cancer biomarkers identified as metabolites, lipids, and proteins. Statistical classifiers built from the histologically validated molecular database allowed cancer prediction with high sensitivity (96.4%), specificity (96.2%), and overall accuracy (96.3%), as well as prediction of benign and malignant thyroid tumors and different histologic subtypes of lung cancer. Notably, our classifier allowed accurate diagnosis of cancer in marginal tumor regions presenting mixed histologic composition. Last, we demonstrate that the MasSpec Pen is suited for in vivo cancer diagnosis during surgery performed in tumor-bearing mouse models, without causing any observable tissue harm or stress to the animal. Our results provide evidence that the MasSpec Pen could potentially be used as a clinical and intraoperative technology for ex vivo and in vivo cancer diagnosis.