When the spring is in unstretched position, the extension is $0$. At the equilibrium, which is the mean position of the SHM, extension is $\frac{mg}{k}$.
The maximum extension possible should be, by conservation of Energy, $$mgx=\frac{1}{2}kx^2\quad x = \text{extension of spring}$$ and $x$ should come out to be $\sqrt{\frac{2mg}{k}}$.
Since the origin is at unstretched position and not the mean position,the amplitude should come out to be $$A = \sqrt{\frac{2mg}{k}} - \frac{mg}{k},$$ the displacement between mean position and extreme position.
The books I have seen have $\frac{mg}{k}$ as the amplitude. Doesn't it mean that the total extension of spring is $\frac{2mg}{k}$ (mean position + extreme position)? Won't that violate the law of conservation of mechanical energy, as it is greater than $\sqrt{\frac{2mg}{k}}$? How is this the amplitude, and what's the logic behind it?