Skip to content

Commit 5b43242

Browse files
committed
Removed the dependency to set the UNITY_PORT environment on the MCP configuration, now all can be set in the Unity Editor or in the terminal
1 parent 5680c61 commit 5b43242

38 files changed

+2207
-70
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,5 @@ GvhProjectSettings.xml
116116
.codeiumignore
117117
Server/log.txt
118118
Server/log.txt.meta
119+
log.txt
120+
log.txt.meta

Editor/Tools/RunTestsTool.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public void RunFinished(ITestResultAdaptor result)
161161
// Set the test run completion result
162162
try
163163
{
164-
_testRunCompletionSource.SetResult(new JObject
164+
_testRunCompletionSource?.SetResult(new JObject
165165
{
166166
["success"] = true,
167167
["type"] = "text",
@@ -171,7 +171,7 @@ public void RunFinished(ITestResultAdaptor result)
171171
catch (Exception ex)
172172
{
173173
Debug.LogError($"[MCP Unity] Failed to set test results: {ex.Message}");
174-
_testRunCompletionSource.TrySetException(ex);
174+
_testRunCompletionSource?.TrySetException(ex);
175175
}
176176
finally
177177
{

Editor/UnityBridge/McpUnityEditorWindow.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ private void DrawServerTab()
9999
settings.Port = newPort;
100100
settings.SaveSettings();
101101
mcpUnityServer.StopServer();
102+
EditorUtility.DisplayDialog("Restart MCP Client",
103+
"Please restart your MCP Client (Windsurf, Cursor, Calude Destktop, etc.) to apply the changes.",
104+
"OK");
102105
}
103106
EditorGUILayout.EndHorizontal();
104107

Editor/UnityBridge/McpUnitySettings.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public void SaveSettings()
8686

8787
// Set environment variable PORT for the Node.js process
8888
// Note: This will only affect processes started after this point
89-
System.Environment.SetEnvironmentVariable("UNITY_PORT", Port.ToString(), System.EnvironmentVariableTarget.Process);
89+
System.Environment.SetEnvironmentVariable("UNITY_PORT", Port.ToString(), System.EnvironmentVariableTarget.User);
9090
}
9191
catch (Exception ex)
9292
{

Editor/Utils/McpConfigUtils.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,7 @@ public static string GenerateMcpConfigJson(bool useTabsIndentation)
2626
{ "mcp-unity", new Dictionary<string, object>
2727
{
2828
{ "command", "node" },
29-
{ "args", new[] { Path.Combine(GetServerPath(), "build", "index.js") } },
30-
{ "env", new Dictionary<string, string>
31-
{
32-
{ "UNITY_PORT", McpUnitySettings.Instance.Port.ToString() }
33-
}
34-
}
29+
{ "args", new[] { Path.Combine(GetServerPath(), "build", "index.js") } }
3530
}
3631
}
3732
}

README-ja.md

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,34 +173,23 @@ MCP Unityは、Unityの`Library/PackedCache`フォルダーをワークスペー
173173
</details>
174174

175175
<details>
176-
<summary><span style="font-size: 1.1em; font-weight: bold;">オプション2: Smithery経由で設定</span></summary>
177-
178-
[Smithery](https://smithery.ai/server/@CoderGamester/mcp-unity)経由でMCP Unityをインストール:
179-
180-
```
181-
現在利用不可
182-
```
183-
</details>
184-
185-
<details>
186-
<summary><span style="font-size: 1.1em; font-weight: bold;">オプション3: 手動設定</span></summary>
176+
<summary><span style="font-size: 1.1em; font-weight: bold;">オプション2: 手動設定</span></summary>
187177

188178
AIクライアントのMCP設定ファイル(例:Claude Desktopのclaude_desktop_config.json)を開き、以下のテキストをコピー:
189179

190180
> `ABSOLUTE/PATH/TO`をMCP Unityインストールの絶対パスに置き換えるか、UnityエディターMCPサーバーウィンドウ(Tools > MCP Unity > Server Window)からテキストをコピー
191181
192182
```json
193183
{
194-
"mcpServers": {
195-
"mcp-unity": {
184+
"mcpServers": {
185+
"mcp-unity": {
196186
"command": "node",
197187
"args": [
198-
"ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js"
199-
],
200-
"env": {
201-
"UNITY_PORT": "8090"
202-
}
203-
}
188+
"ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js"
189+
]
190+
}
191+
}
192+
}
204193
```
205194

206195
</details>

README-ja.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 9 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -173,17 +173,7 @@ Installing this MCP Unity Server is a multi-step process:
173173
</details>
174174

175175
<details>
176-
<summary><span style="font-size: 1.1em; font-weight: bold;">Option 2: Configure via Smithery</span></summary>
177-
178-
To install MCP Unity via [Smithery](https://smithery.ai/server/@CoderGamester/mcp-unity):
179-
180-
```
181-
Currently not available
182-
```
183-
</details>
184-
185-
<details>
186-
<summary><span style="font-size: 1.1em; font-weight: bold;">Option 3: Configure Manually</span></summary>
176+
<summary><span style="font-size: 1.1em; font-weight: bold;">Option 2: Configure Manually</span></summary>
187177

188178
Open the MCP configuration file of your AI client (e.g. claude_desktop_config.json in Claude Desktop) and copy the following text:
189179

@@ -192,15 +182,12 @@ Open the MCP configuration file of your AI client (e.g. claude_desktop_config.js
192182
```json
193183
{
194184
"mcpServers": {
195-
"mcp-unity": {
196-
"command": "node",
197-
"args": [
198-
"ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js"
199-
],
200-
"env": {
201-
"UNITY_PORT": "8090"
202-
}
203-
}
185+
"mcp-unity": {
186+
"command": "node",
187+
"args": [
188+
"ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js"
189+
]
190+
}
204191
}
205192
}
206193
```
@@ -285,11 +272,11 @@ To build the server, open a terminal and:
285272
Debug the server with [@modelcontextprotocol/inspector](https://github.com/modelcontextprotocol/inspector):
286273
- Powershell
287274
```powershell
288-
$env:UNITY_PORT=8090; npx @modelcontextprotocol/inspector node Server/build/index.js
275+
npx @modelcontextprotocol/inspector node Server/build/index.js
289276
```
290277
- Command Prompt/Terminal
291278
```cmd
292-
set UNITY_PORT=8090 && npx @modelcontextprotocol/inspector node Server/build/index.js
279+
npx @modelcontextprotocol/inspector node Server/build/index.js
293280
```
294281

295282
Don't forget to shutdown the server with `Ctrl + C` before closing the terminal or debugging it with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector).

README_zh-CN.md

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,6 @@ MCP Unity 通过将 Unity `Library/PackedCache` 文件夹添加到您的工作
174174

175175
</details>
176176

177-
<details>
178-
<summary><span style="font-size: 1.1em; font-weight: bold;">选项 2: 通过 Smithery 配置</span></summary>
179-
180-
要通过 [Smithery](https://smithery.ai/server/@CoderGamester/mcp-unity) 安装 MCP Unity:
181-
182-
```
183-
当前不可用
184-
```
185-
</details>
186-
187177
<details>
188178
<summary><span style="font-size: 1.1em; font-weight: bold;">选项 3: 手动配置</span></summary>
189179

@@ -193,16 +183,15 @@ MCP Unity 通过将 Unity `Library/PackedCache` 文件夹添加到您的工作
193183
194184
```json
195185
{
196-
"mcpServers": {
197-
"mcp-unity": {
186+
"mcpServers": {
187+
"mcp-unity": {
198188
"command": "node",
199189
"args": [
200-
"ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js"
201-
],
202-
"env": {
203-
"UNITY_PORT": "8090"
204-
}
205-
}
190+
"ABSOLUTE/PATH/TO/mcp-unity/Server/build/index.js"
191+
]
192+
}
193+
}
194+
}
206195
```
207196

208197
</details>

README_zh-CN.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)