Anybody have any experience with Unity MCP ? I was doing everything just fine in Windsurf, however, with Cursor I keep receiving a “Invalid JSON format” error anytime I try to make changes in my Unity project through the MCP server.
This error is in the unity console :Client handler error: Unable to read data from the transport connection: An established connection was aborted by the software in your host machine.
The UnityMCP server is connect properly (I can see in settings/MCP). Also want to point out that it works when creating a .cs file but that’s about it.
I have tried disabling anti-virus, firewall, etc. and no luck.
You’re hitting that “Invalid JSON format” because the Unity‑MCP Bridge is spitting out JSON your client can’t parse, then aborting the socket when Unity sees the malformed payload (WSAECONNABORTED). You’ve got four solid paths to fix it—each with trade‑offs—plus a bonus if you need a more flexible MCP client.
Problem Breakdown
Error message:
Client handler error: Unable to read data from the transport connection:
An established connection was aborted by the software in your host machine.
Invalid JSON format
Pointed to UnityMcpBridge.cs:198 when making edits in Cursor via MCP.
Root causes:
Malformed JSON emitted by the Bridge (e.g., trailing commas, concatenated fragments).
Unity’s built‑in JSONUtility only supports “structured” JSON with fixed classes—anything outside that will break at runtime.
Network aborts often mean the other side closed the socket because it couldn’t parse or accept the data.
Firewall/AV can also drop connections mid‑stream if they think something’s fishy.
Solution Options
1. Upgrade the Unity‑MCP Bridge to v0.2.4
What to do:
In Unity’s Package Manager, update com.ivanmurzak.unity-mcp to 0.2.4 (released Apr 19, 2025).
Why it helps:
That release fixes several C# SDK and compilation quirks under Unity 6000.+, which could have been mangling JSON under the hood.
Pros:
Zero code changes on your side.
Official fix from the maintainer.
Cons:
If your bug isn’t exactly what they patched, you might still see the error.
2. Switch to a Robust JSON Library
What to do:
Swap Unity’s JsonUtility for Newtonsoft JSON (already a dependency in package.json).
In UnityMcpBridge.cs, replace calls to JsonUtility.ToJson/FromJson with JsonConvert.SerializeObject/JsonConvert.DeserializeObject.
Pros:
Handles arbitrary JSON shapes, escaping, and nested fragments without choking.
Gives you clear exceptions on exactly what’s malformed.
Cons:
You’ll need to tweak the Bridge code (or fork it).
Slightly increases package size.
3. Audit Your Network Stack / Firewall
What to do:
Ensure Unity Editor & Python MCP server ports are allowed in Windows Firewall & any AV suites.
If you’re on a corporate VPN or proxy, try a local network with no middleboxes.
Confirm that the Bridge’s SignalR (or raw TCP) handshake isn’t being dropped.
Pros:
Quick check with no code changes.
Rules out OS‑level interference.
Cons:
If JSON is truly malformed, this won’t fix it.
Firewalls may be managed by IT—you may not have permissions.
4. Proxy STDIO→HTTP or Use a Local mcp‑proxy Bridge
What to do:
Run an MCP‑proxy that converts Bridge STDIO to a local SSE/HTTP endpoint.
Point Unity MCP’s “AI Connector” at http://localhost:6278 (or your chosen port).
Pros:
Decouples the transport—if one side misbehaves, the proxy can sanitize the stream.
No Bridge code changes.
Cons:
Introduces a third process to maintain.
Adds a bit of latency & complexity.
Bonus: OmniMind for Ultimate Flexibility
If you find yourself wrestling too much with Bridge internals or Inspector quirks, check out OmniMind—a super‑slick, JSON‑config‑driven Python MCP client. With two lines of code, you declare transports, commands, and env‑vars in a JSON file, then pip install omnimind and run it:
pip install omnimind
from omnimind import OmniMind
agent = OmniMind(config_path="multi_server_config.json")
agent.run()
Unbiased plug‑and‑play: Works headlessly (no Unity GUI), perfect for CI or remote servers.
Full config control: Precisely shape every request & header in a JSON.
Lightweight: No pricey API locks—MIT‑licensed and zero‑fuss.