Skip to content

Commit 2867edf

Browse files
committed
Write out server.env file from C# side.
1 parent ff507b5 commit 2867edf

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

Editor/UnityBridge/McpUnitySettings.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,12 +110,32 @@ public void SaveSettings()
110110
// see: https://learn.microsoft.com/en-us/dotnet/api/system.environmentvariabletarget?view=net-8.0#remarks
111111
Environment.SetEnvironmentVariable(EnvUnityPort, Port.ToString(), EnvironmentVariableTarget.Process);
112112
Environment.SetEnvironmentVariable(EnvUnityRequestTimeout, RequestTimeoutSeconds.ToString(), EnvironmentVariableTarget.Process);
113+
114+
// For non w32 systems.
115+
SaveSettingsToNodeServer();
113116
}
114117
catch (Exception ex)
115118
{
116119
// Can't use LoggerService here as it might create circular dependency
117120
Debug.LogError($"[MCP Unity] Failed to save settings: {ex.Message}");
118121
}
119122
}
123+
124+
125+
public void SaveSettingsToNodeServer() {
126+
try
127+
{
128+
string propertiesPath = GetServerPath() + "/build/server.env";
129+
using (var writer = new StreamWriter(propertiesPath, false))
130+
{
131+
writer.WriteLine($"{EnvUnityPort}={Port}");
132+
writer.WriteLine($"{EnvUnityRequestTimeout}={RequestTimeoutSeconds}");
133+
}
134+
}
135+
catch (Exception ex)
136+
{
137+
Debug.LogError($"[MCP Unity] Failed to write server env properties: {ex.Message}");
138+
}
139+
}
120140
}
121141
}

Editor/Utils/McpConfigUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static string GenerateMcpConfigJson(bool useTabsIndentation)
6060
}
6161

6262
/// <summary>
63-
/// Gets the absolute path to the Server directory containing package.json
63+
/// Gets the absolute path to the Server directory containing package.json (root server dir).
6464
/// Works whether MCP Unity is installed via Package Manager or directly in the Assets folder
6565
/// </summary>
6666
public static string GetServerPath()

0 commit comments

Comments
 (0)