Runtime MCP Operation
Hi Justin, what would it take to run Runtime/Play Mode compilation and adjustment with MCP? I tried projects like LLMR before, and dynamically running adjustments seem to be approachable with Roslyn and LLM(even though it can be really messy), and they basically resemble the idea that with any given input, user can see any live changes during gameplay. I am not an expert in this, so I would love to hear the community's thoughts on this. Thanks!
I love the idea. Right now everything's mostly running in the editor. The assembly is just editor. Would have to open it up to runtime. Most of the functionality (minus deleting) should carry over no problem.
I love the idea. Right now everything's mostly running in the editor. The assembly is just editor. Would have to open it up to runtime. Most of the functionality (minus deleting) should carry over no problem.
Just tried the run-time generation. The main problem with Run-time is that every time new script is generated or script is changd, scene and the assembly will reload. This can be solved with using Roslyn, but maybe not a priority now.
Tested my current Runtime implementation, and found this issue
@msanatan I agree that memory leak check is important, but is it possible to come up with a more elegant solution so that I could actually get my scripts generated in runtime?
Tested my current Runtime implementation, and found this issue
[@msanatan](https://github.com/msanatan) I agree that memory leak check is important, but is it possible to come up with a more elegant solution so that I could actually get my scripts generated in runtime?
FYI, the change is attributed to me because I copied the folder, you added this 3 months ago 😅. That said, these checks won't be enough. I'm not too familiar with the Roslyn integration, but that would give us a syntax tree to more methodologically traverse and validate.
It's possible it does this already, but in a case where we're writing scripts I'd probably just compile them in memory, catch any errors before writing them to the file, and let the LLM try again with the error.
My mistake! Will look into that and submit a PR soon.
Just for my knowledge, what do we mean/expect from runtime tools? When I think about it, I imagine that someone is able to bundle MCP for Unity in their game/experience, and our plugin allows LLMs to connect to their game via MCP. Is that what we mean? For e.g. I can create Tic Tac Toe game and use MCP for Unity's runtime tools, Claude or another model can play against me with the tools I've created.
If it that, here are my thoughts about the use case and how we can implement it.
FastMCP (and other MCP SDKs) support dynamic tools https://gofastmcp.com/servers/tools#disabling-tools (a few Discord chats spoke about being able to enable/disable Tools in the UI - something I'd love to see and this feature supports it!). We're able to enable and disable tools at runtime, in my head this can be very cleanly done as an HTTP request, which is something already in development in #295.
So runtime tools would require:
- User creating a runtime tool
- Unity plugin sends a request to the MCP server with the tools and resources available/enabled
- If their MCP client supports dynamic tooling (Claude Code/Desktop, and VS Code definitely do) they'll see their runtime tools
Users can add custom tools, though it somewhat clunkily requires Python and C# code still. However, tools are enabled at startup, and we don't have a way to disable the editor tools easily. Those gaps would cleanly facilitate runtime tools.
What's the approach you have in mind?
I think I should rephrase this as a "hot-reload feature"? (Sorry, I make it sound like tools that support runtime:) )
With the current MCP, I remember that if you are in the middle of the game with some scene states changed, compiling and reloading the domain would cause the scene to restart. This is Unity's default mechanism, triggered by any little script change. But I want to explore the option to keep the game going even after a script change, which explores more options for fun projects/research.
I am currently exploring options, including using Roslyn or other dynamic hot-reload repos (like this one: https://github.com/focus-creative-games/hybridclr), but I think Roslyn might be the easiest one, since we already have some features using it. let me know what you think.
A bit of update on this, I made this single-script plugin could execute scripts in play mode without interrupting the flow, while also let you save the scripts (because they will be lost once the play mode stops). I am right now following the tool creating .md to create a mcp tool that can have LLM-generated scripts in playtime.
This has been transferred to a discussion: https://github.com/CoplayDev/unity-mcp/discussions/781
[@msanatan](https://github.com/msanatan) I agree that memory leak check is important, but is it possible to come up with a more elegant solution so that I could actually get my scripts generated in runtime?