Involved in the biosynthesis of caffeine. Catalyzes the conversion of 7-methylxanthine (7mX) to theobromine and of paraxanthine to caffeine. Has a 5-fold preference for 7mX. 7-methylxanthine + S-adenosyl-L-methionine = H(+) + S-adenosyl-L-homocysteine + theobromine Binds 1 Mg(2+) ion per subunit. Optimum pH is 7.5. Alkaloid biosynthesis. Expressed, at low levels, in stems, young leaves, floral buds and immature fruits (grains), but not in roots, old leaves and mature fruits. Tobacco plants (Nicotiana tabacum cv. Xanthi) expressing CaXMT1, CaMXMT1 and CaDXMT1 accumulate caffeine and become less appetant and toxic for caterpillars cutworms (Spodoptera litura). Caffeine also stimulates endogenous defense mechanisms against other pathogens (e.g. tobacco mosaic virus and Pseudomonas syringae) by triggering the expression of defense-related genes. Belongs to the methyltransferase superfamily. Type-7 methyltransferase family.