-
Notifications
You must be signed in to change notification settings - Fork 860
Description
I'm using Claude Code within WSL2 (Linux), and the default Claude Code config doesn't connect properly.
Here's what Claude told me it did to set it up on it's own, took me like an hour of asking it "please fix" over and over.
Setting up Unity MCP with Claude Code on WSL2
If you're running Claude Code from WSL2 and Unity on Windows, the MCP server runs on the Windows side but Claude Code needs to reach it from WSL. Here's how to bridge the two.
- Install the Unity package
In Unity Package Manager, add by git URL:
https://github.com/CoplayDev/unity-mcp.git?path=/MCPForUnity#main
In the Unity MCP settings, change the port to 8090 (or any free port — the default 8080 conflicts with Tailscale if you use it).
- Install uv on Windows
The MCP server requires uv. From an admin PowerShell:
irm https://astral.sh/uv/install.ps1 | iex
- Set up port forwarding from WSL to Windows
WSL2 runs in a separate network namespace, so you need to forward the MCP port. From an admin PowerShell:
netsh interface portproxy add v4tov4 listenport=8090 listenaddress=0.0.0.0 connectport=8090 connectaddress=127.0.0.1
Then add a firewall rule to allow it:
New-NetFirewallRule -DisplayName "Unity MCP Server" -Direction Inbound -LocalPort 8090 -Protocol TCP -Action Allow
- Find your WSL host IP
From inside WSL, run:
cat /etc/resolv.conf | grep nameserver | awk '{print $2}'
This prints the Windows host IP as seen from WSL (e.g. 172.21.48.1). It's a private address that varies per machine.
- Add the MCP server to Claude Code
From WSL, using the IP from step 4:
claude mcp add --transport http UnityMCP http://<YOUR_WSL_HOST_IP>:8090/mcp
For example:
claude mcp add --transport http UnityMCP http://172.21.48.1:8090/mcp
Note: this uses HTTP transport, not stdio — since the server is running on the Windows side.
- Verify
Start Unity, then start Claude Code. You should see UnityMCP listed as a connected MCP server. You can test it by asking Claude to get your scene info.
Notes
- If you restart your machine, the WSL host IP may change. Re-run step 4 and update the MCP config if needed.
- The port proxy persists across reboots. To remove it later: netsh interface portproxy delete v4tov4 listenport=8090 listenaddress=0.0.0.0
- If the connection fails, make sure Unity is running and the MCP server is started (check the Unity MCP panel).