The mean curvature $H$ is equal to half of the trace of the shape operator $S$:
$$
H = \frac{1}{2}\mathrm{trace}(S).
$$
By definition, the principle curvatures $k_1$, $k_2$ are the eigenvalues of $S$, hence $H=\frac{1}{2}(k_1 + k_2)$. The argument goes as follows. Since $S$ is a symmetric operator, at each point $p$ of the surface, there exist two orthonormal eigenvectors $e_1$ and $e_2$, the principal directions: $Se_1 = k_1 e_1$ and $S e_2 = k_2 e_2$. So with respect to these eigenvectors the matrix of the shape operator is $\mathrm{diag}(k_1, k_2)$, whose trace is clearly $k_1 + k_2$.
The same argument, but explained a little differently: since the shape operator is diagonalisable, there exists at each point an orthogonal matrix $U$ such that $U^T S U = \mathrm{diag}(k_1, k_2)$. Then
$$
k_1 + k_2 = \mathrm{trace}(U^T S U) = \mathrm{trace}(S U U^T) = \mathrm{trace}(S).
$$
Here we used the fact that $\mathrm{trace}(AB) = \mathrm{trace}(BA)$ for any two square matrices.
When we have coordinates $\mathbf{x}(u,v)$ on the surface, we can calculate the matrix of $S$. One can show that the matrix is
$$
\begin{bmatrix}
E & F \\
F & G
\end{bmatrix}^{-1}
\begin{bmatrix}
e & f \\
f & g
\end{bmatrix}
=
\frac{1}{EG-F^2}
\begin{bmatrix}
e G - f F & f G - g F \\
f E - e F & g E- f F \\
\end{bmatrix},
$$
where
$$
\begin{align*}
E = \mathbf{x}_u\cdot \mathbf{x}_u, \quad F = \mathbf{x}_u\cdot \mathbf{x}_v, \quad G = \mathbf{x}_v\cdot \mathbf{x}_v \\
e = \mathbf{x}_{uu}\cdot N, \quad f = \mathbf{x}_{uv}\cdot N, \quad g = \mathbf{x}_{vv}\cdot N.
\end{align*}
$$
Taking half the trace of this matrix gives the second expression for $H$.