Skip to content

Commit 066d966

Browse files
committed
feat: 초기 Unity MCP 패키지, 경로 확인 서비스 및 서버 구성 요소를 추가합니다.
1 parent ab63b7e commit 066d966

File tree

4 files changed

+49
-19
lines changed

4 files changed

+49
-19
lines changed

MCPForUnity/Editor/Services/PathResolverService.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,13 @@ public void SetPythonPathOverride(string path)
192192
ClearPythonPathOverride();
193193
return;
194194
}
195+
196+
// Allow commands on PATH, but validate explicit paths
197+
if ((Path.IsPathRooted(path) || path.Contains("/") || path.Contains("\\")) && !File.Exists(path))
198+
{
199+
throw new ArgumentException("The selected Python executable does not exist");
200+
}
201+
195202
EditorPrefs.SetString(EditorPrefKeys.PythonPathOverride, path);
196203
}
197204

@@ -207,6 +214,13 @@ public void SetNodePathOverride(string path)
207214
ClearNodePathOverride();
208215
return;
209216
}
217+
218+
// Allow commands on PATH, but validate explicit paths
219+
if ((Path.IsPathRooted(path) || path.Contains("/") || path.Contains("\\")) && !File.Exists(path))
220+
{
221+
throw new ArgumentException("The selected Node executable does not exist");
222+
}
223+
210224
EditorPrefs.SetString(EditorPrefKeys.NodePathOverride, path);
211225
}
212226

MCPForUnity/Server~/src/main.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,17 +410,21 @@ def main():
410410
logger.info("Starting FastMCP with stdio transport")
411411
# 🚨 [핵심] STDIO 모드일 때만 관련 로거를 CRITICAL로 낮춥니다.
412412
# Uvicorn 및 관련 로거들의 입을 막아 stdout 오염을 방지합니다.
413-
logging.getLogger("uvicorn").setLevel(logging.CRITICAL)
414-
logging.getLogger("uvicorn.error").setLevel(logging.CRITICAL)
415-
logging.getLogger("uvicorn.access").setLevel(logging.CRITICAL)
416-
logging.getLogger("starlette").setLevel(logging.CRITICAL)
417-
logging.getLogger("docket").setLevel(logging.CRITICAL)
418-
logging.getLogger("docket.worker").setLevel(logging.CRITICAL)
419-
420-
# FastMCP 본체도 CRITICAL로 낮춰줍니다.
421-
logging.getLogger("fastmcp").setLevel(logging.CRITICAL)
422-
423-
mcp.run(transport='stdio', show_banner=False)
413+
# 🚨 [핵심] STDIO 모드일 때 stdout 오염 방지
414+
for name in (
415+
"uvicorn", "uvicorn.error", "uvicorn.access",
416+
"starlette",
417+
"docket", "docket.worker",
418+
"fastmcp",
419+
):
420+
lg = logging.getLogger(name)
421+
lg.setLevel(logging.WARNING) # ERROR if still too chatty
422+
lg.propagate = False # prevent duplicate root logs
423+
# If the rotating file handler was successfully created, attach it
424+
if '_fh' in globals() and _fh not in lg.handlers:
425+
lg.addHandler(_fh)
426+
427+
mcp.run(transport='stdio')
424428

425429

426430
# Run the server

MCPForUnity/Server~/wrapper.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,22 @@ const serverDir = __dirname;
2020
// Construct updated PATH with common uv locations
2121
const localAppData = process.env.LOCALAPPDATA || "";
2222
const userProfile = process.env.USERPROFILE || "";
23-
const extraPaths = [
24-
path.join(localAppData, "Programs", "uv"), // uv standalone
25-
path.join(localAppData, "uv"), // Alternative
26-
path.join(userProfile, ".cargo", "bin"), // Cargo install
27-
path.join(localAppData, "bin"),
28-
];
23+
const homeDir = process.env.HOME || process.env.USERPROFILE || "";
24+
25+
const extraPaths =
26+
process.platform === "win32"
27+
? [
28+
path.join(localAppData, "Programs", "uv"), // uv standalone
29+
path.join(localAppData, "uv"), // Alternative
30+
path.join(userProfile, ".cargo", "bin"), // Cargo install
31+
path.join(localAppData, "bin"),
32+
]
33+
: [
34+
path.join(homeDir, ".cargo", "bin"),
35+
path.join(homeDir, ".local", "bin"),
36+
"/usr/local/bin",
37+
"/opt/homebrew/bin", // macOS Homebrew
38+
];
2939

3040
const newPath =
3141
extraPaths.join(path.delimiter) + path.delimiter + (process.env.PATH || "");
@@ -43,7 +53,9 @@ const pythonProcess = spawn(
4353
PATH: newPath, // Inject updated PATH
4454
PYTHONUNBUFFERED: "1",
4555
PYTHONIOENCODING: "utf-8",
46-
HOME: userProfile,
56+
...(process.platform === "win32" && userProfile
57+
? { HOME: userProfile }
58+
: {}),
4759
},
4860
}
4961
);

TestProjects/UnityMCPTests/Packages/manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"dependencies": {
3-
"com.coplaydev.unity-mcp": "https://github.com/choej2303/unity-mcp-gg.git?path=/MCPForUnity#main",
3+
"com.coplaydev.unity-mcp": "file:../../../MCPForUnity",
44
"com.unity.ai.navigation": "1.1.4",
55
"com.unity.collab-proxy": "2.5.2",
66
"com.unity.feature.development": "1.0.1",

0 commit comments

Comments
 (0)