Cosmological constraints on the scalar-tensor theory of gravity by analyzing the angular power spectrum data of the cosmic microwave background ( CMB ) obtained from the Planck 2015 results are presented . We consider the harmonic attractor model , in which the scalar field has a harmonic potential with curvature ( \beta ) in the Einstein frame and the theory relaxes toward the Einstein gravity with time . Analyzing the TT , EE , TE and lensing CMB data from Planck by the Markov chain Monte Carlo method , we find that the present-day deviation from the Einstein gravity ( { \alpha _ { 0 } } ^ { 2 } ) is constrained as { \alpha _ { 0 } } ^ { 2 } < 2.5 \times 10 ^ { -4 - 4.5 \beta ^ { 2 } } ( 95.45 \% { C . L . } ) and { \alpha _ { 0 } } ^ { 2 } < 6.3 \times 10 ^ { -4 - 4.5 \beta ^ { 2 } } ( 99.99 \% { C . L . } ) for 0 < \beta < 0.4 . The time variation of the effective gravitational constant between the recombination and the present epochs is constrained as G _ { rec } / G _ { 0 } < 1.0056 ( 95.45 \% { C . L . } ) and G _ { rec } / G _ { 0 } < 1.0115 ( 99.99 \% { C . L . } ) . We also find that the constraints are little affected by extending to nonflat cosmological models because the diffusion damping effect revealed by Planck breaks the degeneracy of the projection effect . PACS numbers 04.80.Cc , 98.80.Es