MCP Automation Server
Source 2 Viewer has an opt-in loopback server that lets an agent drive the real viewer window over the Model Context Protocol. The agent can open files, move the camera, change sidebar controls, inspect entities, models and particle systems, and fire entity inputs. It can also pick, trace, pause and step simulation time, read the log and render stats, and take screenshots.
The server is for development and testing of the viewer. The tools can open anything the user can open in the UI, and eval runs arbitrary code, so there is no sandbox.
Running Code in the Viewer
The eval tool compiles C# statements and runs them inside the viewer process, with access to private members, and replies with the value the script returns as JSON. A script sees the main form, the tab with its viewer, renderer and scene, and a dictionary that lasts between calls. The code is passed inline or as the path of a file.
A script that runs longer than timeout seconds is aborted, which can leave viewer state inconsistent.
Starting the Server
Only Debug builds have the server, so build and run the GUI from source:
dotnet run --project GUI -- --mcp--mcp listens on http://127.0.0.1:13338/mcp. --mcp=<port> selects a different port, so several viewers can run at the same time.
The server speaks only MCP revision 2026-07-28.
Connecting an Agent
Add the endpoint to your agent as an HTTP MCP server. For example, in Claude Code:
claude mcp add --transport http source2viewer http://127.0.0.1:13338/mcpWhen the viewer runs with --mcp, the agent sees the tools and their descriptions, and uses them to drive the viewer.
While the viewer runs with --mcp, settings changes stay in memory and are not saved, and errors go to the agent instead of opening the error dialog.

