6. Given the complex number $z=x+y \mathrm{i}(x, y \in \mathbf{R})$, satisfying that the ratio of the real part to the imaginary part of $\frac{z+1}{z+2}$ is $\sqrt{3}$. Then the maximum value of $\frac{y}{x}$ is
6. $\frac{4 \sqrt{2}-3 \sqrt{3}}{5}$.

Notice,
$$
\begin{array}{l}
\frac{z+1}{z+2}=\frac{x+1+y \mathrm{i}}{x+2+y \mathrm{i}} \\
=\frac{(x+1+y \mathrm{i})(x+2-y \mathrm{i})}{(x+2+y \mathrm{i})(x+2-y \mathrm{i})} \\
=\frac{(x+1)(x+2)+y^{2}+y \mathrm{i}}{(x+2)^{2}+y^{2}} .
\end{array}
$$

From the given condition,
$$
\begin{array}{l}
(x+1)(x+2)+y^{2}-\sqrt{3} y=0 \\
\Rightarrow\left(x+\frac{3}{2}\right)^{2}+\left(y-\frac{\sqrt{3}}{2}\right)^{2}=1 .
\end{array}
$$

Thus, the trajectory of the moving point $P(x, y)$ is a circle with center $Q\left(-\frac{3}{2}, \frac{\sqrt{3}}{2}\right)$ and radius 1.
When $\frac{y}{x}$ reaches its maximum value, the line $O P$ is tangent to the circle.
Since the inclination angle of the line $O Q$ is $\frac{5 \pi}{6}$, we have
$$
\begin{array}{l}
\frac{y}{x}=\tan \left(\angle P O Q-\frac{\pi}{6}\right)=\tan \left(\arcsin \frac{1}{\sqrt{3}}-\frac{\pi}{6}\right) \\
=\frac{\frac{1}{\sqrt{2}}-\frac{1}{\sqrt{3}}}{1+\frac{1}{\sqrt{6}}}=\frac{\sqrt{3}-\sqrt{2}}{1+\sqrt{6}}=\frac{4 \sqrt{2}-3 \sqrt{3}}{5} .
\end{array}
$$