You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Unity MCP fails with "Invalid JSON format" error when creating C# scripts larger than ~2000 bytes. #136
The current TCP buffer is using a buffer of size 8192, but I wonder if the wrapper for the script exceed that limit. Did you find a solution to this?
I too am encountering this buffer issue. I am able to reproduce the issue if I allow Claude to answer with longer scripts it wants to create. If I force Claude to keep the answer short, no issues whatsoever. Claude Code (in paid mode) can have a context of up to 200,000 tokens. Quote from Anthropic "Context Window (Token Limit): The actual "buffer" for Claude's understanding and response generation is measured in tokens, not bytes. The context window for Claude Pro and the API is currently 200,000+ tokens, equivalent to about 500 pages of text or 100 images. However, the free version's context window can vary. "
My suggestion would be perhaps some form of simple chunking, where you have a stop bit that gets sent when no more data is being sent. That action would then trigger the actual file being written when sending TO Unity FROM Claude. I'm not sure how other integrations handle working with large code and say GPT or other LLMs, but would imagine they all use a common, but simple mechanism to ensure they aren't truncating a response to file on transfer or send. I get no timeouts on the Claude side, so it may be a matter of working within the constraints of MCP.... I'm not that smart.
I found another possible workaround. I routinely when using CC directly instruct it to keep files under a certain limit so that it's faster to debug and troubleshoot, and do this by having in my prompt an instruction that says if a file is over a certain limit in tokens (usually 20,000 is the limit) to intelligently chunk the file into smaller files and use includes or similar..... What seems to be working thus far with your implementation is to tell Claude Desktop to be aware of the 8192 tcp socket size limit. In doing this, Claude responded that it would instead either create smaller files and use includes, and, that it would use helper scripts along with files to auto-generate (user interaction then is to right mouse click in inspector the header section of the object, and then select the auto-generate function). I'm using this now to rapidly prototype terrain and it seems to work well.
My suggestion, since Claude is intelligent enough to understand packet data sizes, would be to embed into whatever prompt sequence you're sending the limiter statement. Just simply embedding "Keep files under an overall size of 7500 bytes or smaller by using smaller files and includes, or by using helpers scripts, or both". It may even work if you embed that when the first "chat" request is sent. That could serve as a workaround to the TCP send window issue until a more elegant solution is found. Just a thought, it seems to be working for me.
I asked Claude Code, and "he" solved this buffer issue
If I may ask - what did you ask, and what was the actual solution ? I've been just using a manual system prompt to ensure staying below 7KB file sizes with pretty good success (it makes Claude work harder, since "he" has to modularize all his scripting)... LOL.
I asked Claude Code, and "he" solved this buffer issue
If I may ask - what did you ask, and what was the actual solution ? I've been just using a manual system prompt to ensure staying below 7KB file sizes with pretty good success (it makes Claude work harder, since "he" has to modularize all his scripting)... LOL.
I just copy this issue title to CC, then CC modified both MCP server and unity bridge code upgrading buffer to separated buffer
Activity
Scriptwonder commentedon Jul 6, 2025
The current TCP buffer is using a buffer of size 8192, but I wonder if the wrapper for the script exceed that limit. Did you find a solution to this?
melkourie commentedon Jul 14, 2025
I too am encountering this buffer issue. I am able to reproduce the issue if I allow Claude to answer with longer scripts it wants to create. If I force Claude to keep the answer short, no issues whatsoever. Claude Code (in paid mode) can have a context of up to 200,000 tokens. Quote from Anthropic "Context Window (Token Limit): The actual "buffer" for Claude's understanding and response generation is measured in tokens, not bytes. The context window for Claude Pro and the API is currently 200,000+ tokens, equivalent to about 500 pages of text or 100 images. However, the free version's context window can vary. "
My suggestion would be perhaps some form of simple chunking, where you have a stop bit that gets sent when no more data is being sent. That action would then trigger the actual file being written when sending TO Unity FROM Claude. I'm not sure how other integrations handle working with large code and say GPT or other LLMs, but would imagine they all use a common, but simple mechanism to ensure they aren't truncating a response to file on transfer or send. I get no timeouts on the Claude side, so it may be a matter of working within the constraints of MCP.... I'm not that smart.
melkourie commentedon Jul 14, 2025
I found another possible workaround. I routinely when using CC directly instruct it to keep files under a certain limit so that it's faster to debug and troubleshoot, and do this by having in my prompt an instruction that says if a file is over a certain limit in tokens (usually 20,000 is the limit) to intelligently chunk the file into smaller files and use includes or similar..... What seems to be working thus far with your implementation is to tell Claude Desktop to be aware of the 8192 tcp socket size limit. In doing this, Claude responded that it would instead either create smaller files and use includes, and, that it would use helper scripts along with files to auto-generate (user interaction then is to right mouse click in inspector the header section of the object, and then select the auto-generate function). I'm using this now to rapidly prototype terrain and it seems to work well.
My suggestion, since Claude is intelligent enough to understand packet data sizes, would be to embed into whatever prompt sequence you're sending the limiter statement. Just simply embedding "Keep files under an overall size of 7500 bytes or smaller by using smaller files and includes, or by using helpers scripts, or both". It may even work if you embed that when the first "chat" request is sent. That could serve as a workaround to the TCP send window issue until a more elegant solution is found. Just a thought, it seems to be working for me.
xuguozhi commentedon Jul 15, 2025
I asked Claude Code, and "he" solved this buffer issue
melkourie commentedon Jul 15, 2025
If I may ask - what did you ask, and what was the actual solution ? I've been just using a manual system prompt to ensure staying below 7KB file sizes with pretty good success (it makes Claude work harder, since "he" has to modularize all his scripting)... LOL.
xuguozhi commentedon Jul 15, 2025
I just copy this issue title to CC, then CC modified both MCP server and unity bridge code upgrading buffer to separated buffer
dsarno commentedon Aug 30, 2025
Should be fixed in 3.1.0. Please let us know if you see an improved experience.