From de5b69455ad55525d6cb2342085304e3c36ef723 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 26 Apr 2025 12:50:02 +0900 Subject: [PATCH 1/8] Add env UNITY_REQUEST_TIMEOUT to allow setting the timeout in seconds for requests to the Unity Editor Bridge. --- Server/build/unity/mcpUnity.js | 6 +++++- Server/src/unity/mcpUnity.ts | 8 ++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Server/build/unity/mcpUnity.js b/Server/build/unity/mcpUnity.js index 44fd6935..7013a8f8 100644 --- a/Server/build/unity/mcpUnity.js +++ b/Server/build/unity/mcpUnity.js @@ -8,7 +8,7 @@ export class McpUnity { port; ws = null; pendingRequests = new Map(); - REQUEST_TIMEOUT = 10000; + REQUEST_TIMEOUT; retryDelay = 1000; constructor(logger) { this.logger = logger; @@ -19,6 +19,10 @@ export class McpUnity { const envPort = process.env.UNITY_PORT || envRegistry; this.port = envPort ? parseInt(envPort, 10) : 8090; this.logger.info(`Using port: ${this.port} for Unity WebSocket connection`); + // Initialize timeout from environment variable (in seconds; it is the same as Cline) or use default (10 seconds) + const envTimeout = process.env.UNITY_REQUEST_TIMEOUT; + this.REQUEST_TIMEOUT = envTimeout ? parseInt(envTimeout, 10) * 1000 : 10000; + this.logger.info(`Using request timeout: ${this.REQUEST_TIMEOUT / 1000} seconds`); } /** * Start the Unity connection diff --git a/Server/src/unity/mcpUnity.ts b/Server/src/unity/mcpUnity.ts index 3b552635..83838c00 100644 --- a/Server/src/unity/mcpUnity.ts +++ b/Server/src/unity/mcpUnity.ts @@ -33,7 +33,7 @@ export class McpUnity { private port: number; private ws: WebSocket | null = null; private pendingRequests: Map = new Map(); - private readonly REQUEST_TIMEOUT = 10000; + private readonly REQUEST_TIMEOUT: number; private retryDelay = 1000; constructor(logger: Logger) { @@ -46,8 +46,12 @@ export class McpUnity { const envPort = process.env.UNITY_PORT || envRegistry; this.port = envPort ? parseInt(envPort, 10) : 8090; - this.logger.info(`Using port: ${this.port} for Unity WebSocket connection`); + + // Initialize timeout from environment variable (in seconds; it is the same as Cline) or use default (10 seconds) + const envTimeout = process.env.UNITY_REQUEST_TIMEOUT; + this.REQUEST_TIMEOUT = envTimeout ? parseInt(envTimeout, 10) * 1000 : 10000; + this.logger.info(`Using request timeout: ${this.REQUEST_TIMEOUT / 1000} seconds`); } /** From 96e1101c50307daaf31967d606ea5389d70af0dd Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 26 Apr 2025 13:12:02 +0900 Subject: [PATCH 2/8] Add Test Timeout server settings --- Editor/Services/ITestRunnerService.cs | 4 +--- Editor/Services/TestRunnerService.cs | 11 ++++++----- Editor/UnityBridge/McpUnityEditorWindow.cs | 18 ++++++++++++++++++ Editor/UnityBridge/McpUnitySettings.cs | 4 ++++ 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Editor/Services/ITestRunnerService.cs b/Editor/Services/ITestRunnerService.cs index 780ba3f3..d23f7cc7 100644 --- a/Editor/Services/ITestRunnerService.cs +++ b/Editor/Services/ITestRunnerService.cs @@ -26,12 +26,10 @@ public interface ITestRunnerService /// Test mode to run /// Optional test filter /// TaskCompletionSource to resolve when tests are complete - /// Timeout in minutes, defaults to 10 /// Task that resolves with test results when tests are complete void ExecuteTests( TestMode testMode, string testFilter, - TaskCompletionSource completionSource, - int timeoutMinutes = 1); + TaskCompletionSource completionSource); } } diff --git a/Editor/Services/TestRunnerService.cs b/Editor/Services/TestRunnerService.cs index 7b7fc87d..bfe188e7 100644 --- a/Editor/Services/TestRunnerService.cs +++ b/Editor/Services/TestRunnerService.cs @@ -49,13 +49,11 @@ public List GetAllTests() /// Test mode to run /// Optional test filter /// TaskCompletionSource to resolve when tests are complete - /// Timeout in minutes, defaults to 10 /// Task that resolves with test results when tests are complete public async void ExecuteTests( TestMode testMode, string testFilter, - TaskCompletionSource completionSource, - int timeoutMinutes = 1) + TaskCompletionSource completionSource) { // Create filter var filter = new Filter @@ -72,15 +70,18 @@ public async void ExecuteTests( // Execute tests _testRunnerApi.Execute(new ExecutionSettings(filter)); + // Use timeout from settings if not specified + var timeoutSeconds = McpUnitySettings.Instance.TestTimeoutSeconds; + Task completedTask = await Task.WhenAny( completionSource.Task, - Task.Delay(TimeSpan.FromMinutes(timeoutMinutes)) + Task.Delay(TimeSpan.FromSeconds(timeoutSeconds)) ); if (completedTask != completionSource.Task) { completionSource.SetResult(McpUnitySocketHandler.CreateErrorResponse( - $"Test run timed out after {timeoutMinutes} minutes", + $"Test run timed out after {timeoutSeconds} seconds", "test_runner_timeout" )); } diff --git a/Editor/UnityBridge/McpUnityEditorWindow.cs b/Editor/UnityBridge/McpUnityEditorWindow.cs index 86585300..772b57d6 100644 --- a/Editor/UnityBridge/McpUnityEditorWindow.cs +++ b/Editor/UnityBridge/McpUnityEditorWindow.cs @@ -107,6 +107,24 @@ private void DrawServerTab() EditorGUILayout.Space(); + // Test timeout setting + EditorGUILayout.BeginHorizontal(); + int newTimeout = EditorGUILayout.IntField(new GUIContent("Test Timeout (seconds)", "Timeout in seconds for test execution"), settings.TestTimeoutSeconds); + if (newTimeout < 60) + { + newTimeout = 60; + Debug.LogError("Test timeout must be at least 60 seconds."); + } + + if (newTimeout != settings.TestTimeoutSeconds) + { + settings.TestTimeoutSeconds = newTimeout; + settings.SaveSettings(); + } + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.Space(); + // Auto start server toggle bool autoStartServer = EditorGUILayout.Toggle(new GUIContent("Auto Start Server", "Automatically starts the MCP server when Unity opens"), settings.AutoStartServer); if (autoStartServer != settings.AutoStartServer) diff --git a/Editor/UnityBridge/McpUnitySettings.cs b/Editor/UnityBridge/McpUnitySettings.cs index 821101ab..d3c340d6 100644 --- a/Editor/UnityBridge/McpUnitySettings.cs +++ b/Editor/UnityBridge/McpUnitySettings.cs @@ -3,6 +3,7 @@ using McpUnity.Utils; using UnityEngine; using UnityEditor; +using UnityEngine.Serialization; namespace McpUnity.Unity { @@ -27,6 +28,9 @@ public class McpUnitySettings [Tooltip("Whether to show info logs in the Unity console")] public bool EnableInfoLogs = true; + + [Tooltip("Timeout in seconds for test execution")] + public int TestTimeoutSeconds = 60; /// /// Singleton instance of settings From 438ebd5c415217f593393f7154d24e2482aac197 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 26 Apr 2025 14:07:30 +0900 Subject: [PATCH 3/8] Add about timeout settings --- README-ja.md | 32 ++++++++++++++++++++++++++++++++ README.md | 32 ++++++++++++++++++++++++++++++++ README_zh-CN.md | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/README-ja.md b/README-ja.md index 93c0fcb6..106e8751 100644 --- a/README-ja.md +++ b/README-ja.md @@ -211,6 +211,38 @@ MCP Unityサーバーを起動するには2つの方法があります: node Server/build/index.js ``` +## オプション: タイムアウト設定 + +### WebSocketタイムアウト + +デフォルトでは、MCPサーバーとWebSocket間のタイムアウトは 10 秒です。 +MCP構成ファイルで、次のように環境変数 `UNITY_REQUEST_TIMEOUT` として指定できます。 + +```json +{ + "mcpServers": { + "mcp-unity": { + "command": "node", + "args": [ + "ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js" + ], + "env": { + "UNITY_PORT": "8090", + "UNITY_REQUEST_TIMEOUT": "300" + } + } + } +} +``` + +> [!TIP] +> AIコーディングIDE(Claude Desktop、Cursor IDE、Windsurf IDE など)とMCPサーバー間のタイムアウトは、AIコーディングIDEによって異なります。 + +### テスト実行タイムアウト + +デフォルトでは、Unityエディター側の `run_tests` ツールの実行タイムアウトは 60 秒です。 +**Tools > MCP Unity > Server Window** の **Test Timeout (seconds)** で指定できます。 + ## サーバーのデバッグ MCP Unityサーバーをデバッグするには、以下の方法を使用できます: diff --git a/README.md b/README.md index c15a39bf..98d678a1 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,38 @@ By default, the WebSocket server runs on port 8090. You can change this port in +## Optional: Set Timeout + +### WebSocket Timeout + +By default, the timeout between the MCP server and the WebSocket is 10 seconds. +You can specify it as an environment variable `UNITY_REQUEST_TIMEOUT` in your MCP configuration file as follows: + +```json +{ + "mcpServers": { + "mcp-unity": { + "command": "node", + "args": [ + "ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js" + ], + "env": { + "UNITY_PORT": "8090", + "UNITY_REQUEST_TIMEOUT": "300" + } + } + } +} +``` + +> [!TIP] +> The timeout between your AI Coding IDE (e.g., Claude Desktop, Cursor IDE, Windsurf IDE) and the MCP Server depends on the AI coding IDE. + +### Test Execution Timeout + +By default, the execution timeout for the `run_tests` tool in the Unity editor is 60 seconds. +You can specify it in **Test Timeout (seconds)** in the **Tools > MCP Unity > Server Window**. + ## Debugging the Server
diff --git a/README_zh-CN.md b/README_zh-CN.md index be21ec0a..2e6f71e8 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -213,6 +213,38 @@ MCP Unity 通过将 Unity `Library/PackedCache` 文件夹添加到您的工作 node Server/build/index.js ``` +## 可选:设置超时 + +### WebSocket 超时 + +默认情况下,MCP 服务器与 WebSocket 之间的超时时间为 10 秒。 +您可以在 MCP 配置文件中将其指定为环境变量 `UNITY_REQUEST_TIMEOUT`,如下所示: + +```json +{ + "mcpServers": { + "mcp-unity": { + "command": "node", + "args": [ + "ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js" + ], + "env": { + "UNITY_PORT": "8090", + "UNITY_REQUEST_TIMEOUT": "300" + } + } + } +} +``` + +> [!TIP] +> 您的 AI 编码 IDE(例如,Claude Desktop、Cursor IDE、Windsurf IDE)和 MCP 服务器之间的超时取决于 AI 编码 IDE。 + +### 测试执行超时 + +默认情况下,Unity 编辑器中 `run_tests` 工具的执行超时时间为 60 秒。 +您可以在 **Tools > MCP Unity > Server Window** 中的 **Test Timeout (seconds)** 中指定它。 + ## 调试服务器 要调试 MCP Unity 服务器,您可以使用以下方法: From 22cc6780cf67dcca87a6ab5e4b32e7c248c8bc44 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sat, 26 Apr 2025 15:03:43 +0900 Subject: [PATCH 4/8] Update Editor/UnityBridge/McpUnitySettings.cs Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --- Editor/UnityBridge/McpUnitySettings.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Editor/UnityBridge/McpUnitySettings.cs b/Editor/UnityBridge/McpUnitySettings.cs index d3c340d6..0f9514c2 100644 --- a/Editor/UnityBridge/McpUnitySettings.cs +++ b/Editor/UnityBridge/McpUnitySettings.cs @@ -3,7 +3,6 @@ using McpUnity.Utils; using UnityEngine; using UnityEditor; -using UnityEngine.Serialization; namespace McpUnity.Unity { From 3a5d17a99cad6c0165d0f827f09be7ef857d8507 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sun, 27 Apr 2025 00:30:19 +0900 Subject: [PATCH 5/8] Fix to persist WebSocket ports on non-Windows OS --- Editor/UnityBridge/McpUnitySettings.cs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Editor/UnityBridge/McpUnitySettings.cs b/Editor/UnityBridge/McpUnitySettings.cs index 0f9514c2..00778b84 100644 --- a/Editor/UnityBridge/McpUnitySettings.cs +++ b/Editor/UnityBridge/McpUnitySettings.cs @@ -20,6 +20,9 @@ public class McpUnitySettings private static readonly string SettingsPath = "ProjectSettings/McpUnitySettings.json"; // Server settings +#if !UNITY_EDITOR_WIN + [field: SerializeField] // Note: On Windows, this property is persisted in per-user environment variables. +#endif public int Port { get; set; } = 8090; [Tooltip("Whether to automatically start the MCP server when Unity opens")] @@ -69,12 +72,14 @@ public void LoadSettings() JsonUtility.FromJsonOverwrite(json, this); } +#if UNITY_EDITOR_WIN // Check for environment variable PORT string envPort = System.Environment.GetEnvironmentVariable("UNITY_PORT"); if (!string.IsNullOrEmpty(envPort) && int.TryParse(envPort, out int port)) { Port = port; } +#endif } catch (Exception ex) { @@ -93,10 +98,14 @@ public void SaveSettings() // Save settings to McpUnitySettings.json string json = JsonUtility.ToJson(this, true); File.WriteAllText(SettingsPath, json); - + +#if UNITY_EDITOR_WIN // Set environment variable PORT for the Node.js process // Note: This will only affect processes started after this point + // Note: EnvironmentVariableTarget.User should be used on .NET implementations running on Windows systems only. + // see: https://learn.microsoft.com/ja-jp/dotnet/api/system.environmentvariabletarget?view=net-8.0#fields System.Environment.SetEnvironmentVariable("UNITY_PORT", Port.ToString(), System.EnvironmentVariableTarget.User); +#endif } catch (Exception ex) { From fea6e1070fbe3514ee5be76f2f78bba72b7289f0 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sun, 27 Apr 2025 01:08:35 +0900 Subject: [PATCH 6/8] Fix to persist request timeout seconds as an environment variable on Windows OS --- Editor/Services/TestRunnerService.cs | 2 +- Editor/UnityBridge/McpUnityEditorWindow.cs | 8 ++++---- Editor/UnityBridge/McpUnitySettings.cs | 24 +++++++++++++++++----- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/Editor/Services/TestRunnerService.cs b/Editor/Services/TestRunnerService.cs index bfe188e7..6d21e5ae 100644 --- a/Editor/Services/TestRunnerService.cs +++ b/Editor/Services/TestRunnerService.cs @@ -71,7 +71,7 @@ public async void ExecuteTests( _testRunnerApi.Execute(new ExecutionSettings(filter)); // Use timeout from settings if not specified - var timeoutSeconds = McpUnitySettings.Instance.TestTimeoutSeconds; + var timeoutSeconds = McpUnitySettings.Instance.RequestTimeoutSeconds; Task completedTask = await Task.WhenAny( completionSource.Task, diff --git a/Editor/UnityBridge/McpUnityEditorWindow.cs b/Editor/UnityBridge/McpUnityEditorWindow.cs index 772b57d6..59663e28 100644 --- a/Editor/UnityBridge/McpUnityEditorWindow.cs +++ b/Editor/UnityBridge/McpUnityEditorWindow.cs @@ -109,16 +109,16 @@ private void DrawServerTab() // Test timeout setting EditorGUILayout.BeginHorizontal(); - int newTimeout = EditorGUILayout.IntField(new GUIContent("Test Timeout (seconds)", "Timeout in seconds for test execution"), settings.TestTimeoutSeconds); + int newTimeout = EditorGUILayout.IntField(new GUIContent("Request Timeout (seconds)", "Timeout in seconds for tool request"), settings.RequestTimeoutSeconds); if (newTimeout < 60) { newTimeout = 60; - Debug.LogError("Test timeout must be at least 60 seconds."); + Debug.LogError("Request timeout must be at least 60 seconds."); } - if (newTimeout != settings.TestTimeoutSeconds) + if (newTimeout != settings.RequestTimeoutSeconds) { - settings.TestTimeoutSeconds = newTimeout; + settings.RequestTimeoutSeconds = newTimeout; settings.SaveSettings(); } EditorGUILayout.EndHorizontal(); diff --git a/Editor/UnityBridge/McpUnitySettings.cs b/Editor/UnityBridge/McpUnitySettings.cs index 00778b84..37963021 100644 --- a/Editor/UnityBridge/McpUnitySettings.cs +++ b/Editor/UnityBridge/McpUnitySettings.cs @@ -15,6 +15,11 @@ public class McpUnitySettings // Constants public const string ServerVersion = "1.0.0"; public const string PackageName = "com.gamelovers.mcp-unity"; + +#if UNITY_EDITOR_WIN + private const string EnvUnityPort = "UNITY_PORT"; + private const string EnvUnityRequestTimeout = "UNITY_REQUEST_TIMEOUT"; +#endif private static McpUnitySettings _instance; private static readonly string SettingsPath = "ProjectSettings/McpUnitySettings.json"; @@ -25,14 +30,17 @@ public class McpUnitySettings #endif public int Port { get; set; } = 8090; +#if !UNITY_EDITOR_WIN + [field: SerializeField] // Note: On Windows, this property is persisted in per-user environment variables. +#endif + [Tooltip("Timeout in seconds for tool request")] + public int RequestTimeoutSeconds { get; set; } = 60; + [Tooltip("Whether to automatically start the MCP server when Unity opens")] public bool AutoStartServer = true; [Tooltip("Whether to show info logs in the Unity console")] public bool EnableInfoLogs = true; - - [Tooltip("Timeout in seconds for test execution")] - public int TestTimeoutSeconds = 60; /// /// Singleton instance of settings @@ -74,11 +82,16 @@ public void LoadSettings() #if UNITY_EDITOR_WIN // Check for environment variable PORT - string envPort = System.Environment.GetEnvironmentVariable("UNITY_PORT"); + string envPort = System.Environment.GetEnvironmentVariable(EnvUnityPort); if (!string.IsNullOrEmpty(envPort) && int.TryParse(envPort, out int port)) { Port = port; } + string envTimeout = System.Environment.GetEnvironmentVariable(EnvUnityRequestTimeout); + if (!string.IsNullOrEmpty(envTimeout) && int.TryParse(envTimeout, out int timeout)) + { + RequestTimeoutSeconds = timeout; + } #endif } catch (Exception ex) @@ -104,7 +117,8 @@ public void SaveSettings() // Note: This will only affect processes started after this point // Note: EnvironmentVariableTarget.User should be used on .NET implementations running on Windows systems only. // see: https://learn.microsoft.com/ja-jp/dotnet/api/system.environmentvariabletarget?view=net-8.0#fields - System.Environment.SetEnvironmentVariable("UNITY_PORT", Port.ToString(), System.EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable(EnvUnityPort, Port.ToString(), EnvironmentVariableTarget.User); + Environment.SetEnvironmentVariable(EnvUnityRequestTimeout, RequestTimeoutSeconds.ToString(), EnvironmentVariableTarget.User); #endif } catch (Exception ex) From 6b24edf8ccd97ba3eba6af3dcba62736e753f1af Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sun, 27 Apr 2025 01:27:24 +0900 Subject: [PATCH 7/8] Fix minimum timeout --- Editor/UnityBridge/McpUnityEditorWindow.cs | 6 +++--- Editor/UnityBridge/McpUnitySettings.cs | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Editor/UnityBridge/McpUnityEditorWindow.cs b/Editor/UnityBridge/McpUnityEditorWindow.cs index 59663e28..ded9242f 100644 --- a/Editor/UnityBridge/McpUnityEditorWindow.cs +++ b/Editor/UnityBridge/McpUnityEditorWindow.cs @@ -110,10 +110,10 @@ private void DrawServerTab() // Test timeout setting EditorGUILayout.BeginHorizontal(); int newTimeout = EditorGUILayout.IntField(new GUIContent("Request Timeout (seconds)", "Timeout in seconds for tool request"), settings.RequestTimeoutSeconds); - if (newTimeout < 60) + if (newTimeout < McpUnitySettings.RequestTimeoutMinimum) { - newTimeout = 60; - Debug.LogError("Request timeout must be at least 60 seconds."); + newTimeout = McpUnitySettings.RequestTimeoutMinimum; + Debug.LogError($"Request timeout must be at least {McpUnitySettings.RequestTimeoutMinimum} seconds."); } if (newTimeout != settings.RequestTimeoutSeconds) diff --git a/Editor/UnityBridge/McpUnitySettings.cs b/Editor/UnityBridge/McpUnitySettings.cs index 37963021..056cd431 100644 --- a/Editor/UnityBridge/McpUnitySettings.cs +++ b/Editor/UnityBridge/McpUnitySettings.cs @@ -15,6 +15,7 @@ public class McpUnitySettings // Constants public const string ServerVersion = "1.0.0"; public const string PackageName = "com.gamelovers.mcp-unity"; + public const int RequestTimeoutMinimum = 10; #if UNITY_EDITOR_WIN private const string EnvUnityPort = "UNITY_PORT"; @@ -34,7 +35,7 @@ public class McpUnitySettings [field: SerializeField] // Note: On Windows, this property is persisted in per-user environment variables. #endif [Tooltip("Timeout in seconds for tool request")] - public int RequestTimeoutSeconds { get; set; } = 60; + public int RequestTimeoutSeconds { get; set; } = RequestTimeoutMinimum; [Tooltip("Whether to automatically start the MCP server when Unity opens")] public bool AutoStartServer = true; From 59e28918ceec9baa485b952e6263ee63652f3579 Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Sun, 27 Apr 2025 01:57:04 +0900 Subject: [PATCH 8/8] Fix READMEs --- README-ja.md | 63 ++++++++++++++++++++++++++++++------------------- README.md | 63 ++++++++++++++++++++++++++++++------------------- README_zh-CN.md | 63 ++++++++++++++++++++++++++++++------------------- 3 files changed, 117 insertions(+), 72 deletions(-) diff --git a/README-ja.md b/README-ja.md index 106e8751..cc4a75ef 100644 --- a/README-ja.md +++ b/README-ja.md @@ -213,35 +213,50 @@ MCP Unityサーバーを起動するには2つの方法があります: ## オプション: タイムアウト設定 -### WebSocketタイムアウト - デフォルトでは、MCPサーバーとWebSocket間のタイムアウトは 10 秒です。 -MCP構成ファイルで、次のように環境変数 `UNITY_REQUEST_TIMEOUT` として指定できます。 +お使いのOSに応じて変更できます。 -```json -{ - "mcpServers": { - "mcp-unity": { - "command": "node", - "args": [ - "ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js" - ], - "env": { - "UNITY_PORT": "8090", - "UNITY_REQUEST_TIMEOUT": "300" - } - } - } -} -``` +
+Option 1: Windows OS -> [!TIP] -> AIコーディングIDE(Claude Desktop、Cursor IDE、Windsurf IDE など)とMCPサーバー間のタイムアウトは、AIコーディングIDEによって異なります。 +1. Unityエディターを開きます +2. **Tools > MCP Unity > Server Window** に移動します +3. **Request Timeout (seconds)** の値を希望のタイムアウト秒数に変更します +4. Unityはシステム環境変数UNITY_REQUEST_TIMEOUTに新しいタイムアウト値を設定します +5. Node.jsサーバーを再起動します +6. **Start Server** をもう一度クリックして、UnityエディターのWebソケットをNode.js MCPサーバーに再接続します -### テスト実行タイムアウト +
+ +
+Option 2: Windows以外のOS + +Windows 以外の OS の場合は、次の 2 か所で設定する必要があります。 + +### エディター内プロセスのタイムアウト + +1. Unityエディターを開きます +2. **Tools > MCP Unity > Server Window** に移動します +3. **Request Timeout (seconds)** の値を希望のタイムアウト秒数に変更します + +### WebSocketのタイムアウト -デフォルトでは、Unityエディター側の `run_tests` ツールの実行タイムアウトは 60 秒です。 -**Tools > MCP Unity > Server Window** の **Test Timeout (seconds)** で指定できます。 +1. ターミナルで UNITY_REQUEST_TIMEOUT 環境変数を設定します + - Powershell + ```powershell + $env:UNITY_REQUEST_TIMEOUT = "300" + ``` + - Command Prompt/Terminal + ```cmd + set UNITY_REQUEST_TIMEOUT=300 + ``` +2. Node.jsサーバーを再起動します +3. **Start Server** をもう一度クリックして、UnityエディターのWebソケットをNode.js MCPサーバーに再接続します + +
+ +> [!TIP] +> AIコーディングIDE(Claude Desktop、Cursor IDE、Windsurf IDE など)とMCPサーバー間のタイムアウト設定は、IDEによって異なります。 ## サーバーのデバッグ diff --git a/README.md b/README.md index 98d678a1..800ec710 100644 --- a/README.md +++ b/README.md @@ -238,35 +238,50 @@ By default, the WebSocket server runs on port 8090. You can change this port in ## Optional: Set Timeout -### WebSocket Timeout - By default, the timeout between the MCP server and the WebSocket is 10 seconds. -You can specify it as an environment variable `UNITY_REQUEST_TIMEOUT` in your MCP configuration file as follows: +You can change depending on the OS you are using: -```json -{ - "mcpServers": { - "mcp-unity": { - "command": "node", - "args": [ - "ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js" - ], - "env": { - "UNITY_PORT": "8090", - "UNITY_REQUEST_TIMEOUT": "300" - } - } - } -} -``` +
+Option 1: Windows OS -> [!TIP] -> The timeout between your AI Coding IDE (e.g., Claude Desktop, Cursor IDE, Windsurf IDE) and the MCP Server depends on the AI coding IDE. +1. Open the Unity Editor +2. Navigate to Tools > MCP Unity > Server Window +3. Change the "Request Timeout (seconds)" value to your desired timeout seconds +4. Unity will setup the system environment variable UNITY_REQUEST_TIMEOUT to the new timeout value +5. Restart the Node.js server +6. Click again on "Start Server" to reconnect the Unity Editor web socket to the Node.js MCP Server + +
+ +
+Option 2: Non-Windows OS -### Test Execution Timeout +For non-Windows OS, you need to configure two places: -By default, the execution timeout for the `run_tests` tool in the Unity editor is 60 seconds. -You can specify it in **Test Timeout (seconds)** in the **Tools > MCP Unity > Server Window**. +### In Editor Process Timeout + +1. Open the Unity Editor +2. Navigate to Tools > MCP Unity > Server Window +3. Change the "Request Timeout (seconds)" value to your desired timeout seconds + +### WebSocket Timeout + +1. Set the UNITY_REQUEST_TIMEOUT environment variable in the terminal + - Powershell + ```powershell + $env:UNITY_REQUEST_TIMEOUT = "300" + ``` + - Command Prompt/Terminal + ```cmd + set UNITY_REQUEST_TIMEOUT=300 + ``` +2. Restart the Node.js server +3. Click again on "Start Server" to reconnect the Unity Editor web socket to the Node.js MCP Server + +
+ +> [!TIP] +> The timeout between your AI Coding IDE (e.g., Claude Desktop, Cursor IDE, Windsurf IDE) and the MCP Server depends on the IDE. ## Debugging the Server diff --git a/README_zh-CN.md b/README_zh-CN.md index 2e6f71e8..f1839213 100644 --- a/README_zh-CN.md +++ b/README_zh-CN.md @@ -215,35 +215,50 @@ MCP Unity 通过将 Unity `Library/PackedCache` 文件夹添加到您的工作 ## 可选:设置超时 -### WebSocket 超时 - 默认情况下,MCP 服务器与 WebSocket 之间的超时时间为 10 秒。 -您可以在 MCP 配置文件中将其指定为环境变量 `UNITY_REQUEST_TIMEOUT`,如下所示: +您可以根据所使用的操作系统进行更改: -```json -{ - "mcpServers": { - "mcp-unity": { - "command": "node", - "args": [ - "ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js" - ], - "env": { - "UNITY_PORT": "8090", - "UNITY_REQUEST_TIMEOUT": "300" - } - } - } -} -``` +
+Option 1: Windows OS -> [!TIP] -> 您的 AI 编码 IDE(例如,Claude Desktop、Cursor IDE、Windsurf IDE)和 MCP 服务器之间的超时取决于 AI 编码 IDE。 +1. 打开 Unity 编辑器 +2. 导航至 Tools > MCP Unity > Server Window +3. 将 "Request Timeout (seconds)" 值更改为所需的超时秒数 +4. Unity 会将系统环境变量 UNITY_REQUEST_TIMEOUT 设置为新的超时值 +5. 重启 Node.js 服务器 +6. 再次点击“启动服务器”,将 Unity 编辑器 Web 套接字重新连接到 Node.js MCP 服务器 -### 测试执行超时 +
+ +
+Option 2: 非Windows操作系统 + +对于非Windows操作系统,需要配置两个地方: -默认情况下,Unity 编辑器中 `run_tests` 工具的执行超时时间为 60 秒。 -您可以在 **Tools > MCP Unity > Server Window** 中的 **Test Timeout (seconds)** 中指定它。 +### 编辑器进程超时 + +1. 打开 Unity 编辑器 +2. 导航至 Tools > MCP Unity > Server Window +3. 将 "Request Timeout (seconds)" 值更改为所需的超时秒数 + +### WebSocket 超时 + +1. 在终端中设置 UNITY_REQUEST_TIMEOUT 环境变量 + - Powershell + ```powershell + $env:UNITY_REQUEST_TIMEOUT = "300" + ``` + - Command Prompt/Terminal + ```cmd + set UNITY_REQUEST_TIMEOUT=300 + ``` +2. 重启 Node.js 服务器 +3. 再次点击“启动服务器”,将 Unity 编辑器 Web 套接字重新连接到 Node.js MCP 服务器 + +
+ +> [!TIP] +> 您的 AI 编码 IDE(例如,Claude Desktop、Cursor IDE、Windsurf IDE)和 MCP 服务器之间的超时取决于 IDE。 ## 调试服务器