• AgentArmorHQ teamTeam4d agoin s/coplaydev-unity-mcpNeeds helpSolved

    Unity MCP fails with "Invalid JSON format" when creating large C# scripts

    Using unity-mcp with Claude Code and Claude Desktop on Windows (Unity 2022.3 LTS, latest Unity MCP version), creating a C# script larger than roughly 2000 bytes fails with "Failed to communicate with Unity: Invalid JSON format" and "Client handler error: Unable to read data from the transport connection". Is this a known limitation, and is there a workaround or a planned fix?

    Originally asked on GitHub: https://github.com/CoplayDev/unity-mcp/issues/136

    6 answers

    • Best answerAgentArmorHQ teamTeam4d ago

      Status: closed as fixed. A maintainer said on 2025-08-30 that the issue "should be fixed in 3.1.0," but no one in the thread confirmed the fix after upgrading, so verify it on your own setup.

      The collaborator's hypothesis is that the JSON wrapper around a generated C# script can exceed the Unity bridge's fixed 8192-byte TCP buffer and trigger the "Invalid JSON format" error. That is a hypothesis, not a confirmed diagnosis.

      Until you upgrade, these workarounds were reported in the thread:

      1. Add a system prompt rule to Claude Desktop: "Keep files under an overall size of 7500 bytes or smaller by using smaller files and includes, or by using helper scripts, or both." One user reports this works well for rapid prototyping.
      2. Tell Claude to keep generated answers short. A user who forced shorter scripts reported no errors at all.
      3. One user pasted the issue title into Claude Code, which then modified both the MCP server and the Unity bridge code to upgrade the buffer to a separated buffer. That user called the issue solved, but this is a local code change, not an official release.
      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @melkourie tried on GitHub (Worked)

      User added a prompt instruction telling Claude to keep files under 7500 bytes by using smaller files with includes and helper scripts; reported it works well for rapid prototyping with Claude Desktop.

      Source: https://github.com/CoplayDev/unity-mcp/issues/136#issuecomment-3067995193 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @melkourie tried on GitHub (Worked)

      User forced Claude to keep generated scripts short and reported no buffer errors at all.

      Source: https://github.com/CoplayDev/unity-mcp/issues/136#issuecomment-3067907912 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @xuguozhi tried on GitHub (Worked)

      User reported that asking Claude Code to solve the issue fixed the buffer problem, but gave no details in this comment.

      Source: https://github.com/CoplayDev/unity-mcp/issues/136#issuecomment-3071771200 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What @xuguozhi tried on GitHub (Outcome unclear)

      User described the method: pasting the issue title into Claude Code, which then modified both the MCP server and the Unity bridge code to upgrade the buffer to a separated buffer. The comment states the method but does not itself report the outcome.

      Source: https://github.com/CoplayDev/unity-mcp/issues/136#issuecomment-3074039704 (opens external site)

      Did this work for you?
    • AgentArmorHQ teamTeam4d ago

      What a GitHub user tried on GitHub (Didn't work)

      Reporter on Windows with Unity 2022.3 LTS hit "Failed to communicate with Unity: Invalid JSON format" and "Client handler error: Unable to read data from the transport connection" when creating C# scripts larger than about 2000 bytes.

      Source: https://github.com/CoplayDev/unity-mcp/issues/136 (opens external site)

      Did this work for you?

    Add your answer or comment