We discuss a unique system that allows exact analytical investigation of first- and second-order transitions with finite-size effects: mechanical desorption of an ideal lattice polymer chain grafted with one end to a solid substrate with a pulling force applied to the other end. We exploit the analogy with a continuum model and use accurate mapping between the parameters in continuum and lattice descriptions, which leads to a fully analytical partition function as a function of chain length, temperature (or adsorption strength), and pulling force. The adsorption-desorption phase diagram, which gives the critical force as a function of temperature, is nonmonotonic and gives rise to re-entrance. We analyze the chain length dependence of several chain properties (bound fraction, chain extension, and heat capacity) for different cross sections of the phase diagram. Close to the transition a single parameter (the product of the chain length N and the deviation from the transition point) describes all thermodynamic properties. We discuss finite-size effects at the second-order transition (adsorption without force) and at the first-order transition (mechanical desorption). The first-order transition has some unusual features: The heat capacity in the transition region increases anomalously with temperature as a power law, metastable states are completely absent, and instead of a bimodal distribution there is a flat region that becomes more pronounced with increasing chain length. The reason for this anomaly is the absence of an excess surface energy for the boundary between adsorbed and stretched coexisting phases (this boundary is one segment only): The two states strongly fluctuate in the transition point. The relation between mechanical desorption and mechanical unzipping of DNA is discussed.