Skip to content

Commit 9386c71

Browse files
author
ichimi abunai
committed
feat: add Unity Editor support for remote MCP bridge connections
- Add AllowRemoteConnections setting to McpUnitySettings - Update WebSocket server to bind to 0.0.0.0 when remote connections enabled - Add UI checkbox in Unity Editor window for remote connection toggle - Server automatically restarts when binding setting changes - Defaults to localhost-only connections for security
1 parent ee52e4a commit 9386c71

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

Editor/UnityBridge/McpUnityEditorWindow.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,19 @@ private void DrawServerTab()
135135

136136
EditorGUILayout.Space();
137137

138+
// Allow remote connections toggle
139+
bool allowRemoteConnections = EditorGUILayout.Toggle(new GUIContent("Allow Remote Connections", "Allow connections from remote MCP bridges. When disabled, only localhost connections are allowed (default)."), settings.AllowRemoteConnections);
140+
if (allowRemoteConnections != settings.AllowRemoteConnections)
141+
{
142+
settings.AllowRemoteConnections = allowRemoteConnections;
143+
settings.SaveSettings();
144+
// Restart server to apply binding change
145+
mcpUnityServer.StopServer();
146+
mcpUnityServer.StartServer();
147+
}
148+
149+
EditorGUILayout.Space();
150+
138151
// Enable info logs toggle
139152
bool enableInfoLogs = EditorGUILayout.Toggle(new GUIContent("Enable Info Logs", "Show informational logs in the Unity console"), settings.EnableInfoLogs);
140153
if (enableInfoLogs != settings.EnableInfoLogs)

Editor/UnityBridge/McpUnityServer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,11 @@ public void StartServer()
125125

126126
try
127127
{
128-
_webSocketServer = new WebSocketServer($"ws://localhost:{McpUnitySettings.Instance.Port}");
128+
var host = McpUnitySettings.Instance.AllowRemoteConnections ? "0.0.0.0" : "localhost";
129+
_webSocketServer = new WebSocketServer($"ws://{host}:{McpUnitySettings.Instance.Port}");
129130
_webSocketServer.AddWebSocketService("/McpUnity", () => new McpUnitySocketHandler(this));
130131
_webSocketServer.Start();
131-
McpLogger.LogInfo($"WebSocket server started successfully on port {McpUnitySettings.Instance.Port}.");
132+
McpLogger.LogInfo($"WebSocket server started successfully on {host}:{McpUnitySettings.Instance.Port}.");
132133
}
133134
catch (SocketException ex) when (ex.SocketErrorCode == SocketError.AddressAlreadyInUse)
134135
{

Editor/UnityBridge/McpUnitySettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ public class McpUnitySettings
3636

3737
[Tooltip("Optional: Full path to the npm executable (e.g., /Users/user/.asdf/shims/npm or C:\\path\\to\\npm.cmd). If not set, 'npm' from the system PATH will be used.")]
3838
public string NpmExecutablePath = string.Empty;
39+
40+
[Tooltip("Allow connections from remote MCP bridges. When disabled, only localhost connections are allowed (default).")]
41+
public bool AllowRemoteConnections = false;
3942

4043
/// <summary>
4144
/// Singleton instance of settings

0 commit comments

Comments
 (0)