Conversation
barankrky
added a commit
to barankrky/UnityExplorer
that referenced
this pull request
Sep 19, 2026
Add a native MCP (Model Context Protocol) server that runs inside the UnityExplorer DLL. No Node.js, stdio adapter, or external bridge process is required, and no new third-party dependency is introduced. Transport (src/MCP/Transport): - McpHttpBridge: loopback-only HTTP server built on TcpListener, with bearer token auth, request size and header limits, bounded request queue, and per-request timeout. Non-loopback peers are rejected at the socket level. - Legacy HTTP+SSE and stateless Streamable HTTP modes, selectable in the UI. - JsonWire: dependency-free JSON scanner so the transport works on net35 and IL2CPP without pulling in a serializer. - Handlers are only ever invoked from the Unity main thread; network workers parse, authorize, and enqueue, then PumpMainThread dispatches. Protocol and runtime (src/MCP/Runtime): - McpNativeProtocolHandler implements initialize, notifications/initialized, ping, tools/list, and tools/call. Negotiated protocol versions span 2024-11-05 through 2025-11-25. - McpGameCapabilityExecutor exposes 13 tools: get_status, list_scenes, search_objects, get_object, get_member, list_methods, set_member, set_transform, set_enabled, invoke_method, create_object, destroy_object, and execute_batch. - McpObjectRegistry hands out session-local object handles keyed by native instance ID for IL2CPP wrapper stability. - McpValueCodec and McpMemberPath handle JSON <-> CLR/Unity conversion and nested member paths, including write-back for boxed value types. - McpReflection resolves IL2CPP-generated types via GetActualType so members declared on derived wrappers stay visible, and respects UnityExplorer's reflection blacklist. Security defaults: MCP is disabled, binds 127.0.0.1, starts read-only with dangerous operations off, and auto-generates a token when none is set. The dangerous-operations flag is reset to off on every startup. Permissions are enforced in the executor, so execute_batch cannot bypass them. UI and wiring: - McpPanel configures enable/disable, transport, port, paths, token, read-only mode, dangerous operations, logging, and limits, and shows live status plus copyable client configuration. - ConfigManager gains the MCP_* settings; ExplorerCore initializes the manager, ExplorerBehaviour pumps and shuts it down. - docs/MCP.md and docs/MCP_SECURITY.md document setup, the tool list, permission matrix, runtime limits, and the threat model. Adaptations from the reference implementation (originalnicodr#136): - Scene handle reads go through UnityHelpers.GetSceneIntHandle() instead of Scene.handle directly, so list_scenes and search_objects work on Unity 6.3+ where handle became a SceneHandle struct. - The 2026-07-28 protocol revision is not advertised, because it mandates Mcp-Method/Mcp-Name headers this transport does not implement. - The panel calls McpManager directly rather than through a reflection bridge, since the server is compiled into this assembly. - Docs are English and naming reflects UnityExplorer rather than the fork.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a native MCP server directly inside CinematicUnityExplorer.
The MCP server is implemented entirely in C# and runs inside the game process. It does not require Node.js, an
external bridge process, or any additional runtime dependency.
The implementation supports both legacy SSE and Streamable HTTP transports, selectable from the in-game MCP settings
panel.
Preview
Changes
Built-in MCP server
src/MCP/.initializenotifications/initializedpingtools/listtools/callRuntime game-control tools
Add MCP tools for:
IL2CPP compatibility
wrapper type.
System.Collections.Generic.List<T>into IL2CPP Unity APIs whereIl2CppSystem.Collections.Generic.List<T>is required.HTTP transports
MCP settings UI
Add a scrollable MCP settings panel with the same visual style as the other CUE panels.
The panel provides controls for:
The UI also displays runtime status and generates client configuration information for Agent/MCP clients.
Documentation
Add:
docs/MCP.mddocs/MCP_SECURITY.mdThe documentation describes:
Security considerations
The MCP server is disabled by default and binds to
127.0.0.1by default.Mutation and dangerous operations are protected by runtime checks:
Users should only enable write access for trusted local MCP clients and should use a recoverable test save.
Compatibility
The implementation is intended to support:
The MCP transport and runtime code does not depend on Node.js or an external process.
Testing
Dropdown.OptionDataentries, which avoids the IL2CPPList<T>type mismatch.mcp-server/Node.js adapter are not part of this PR.