From eeaa7a2c554cdfa0fae8f6fe4959489d7e6cd702 Mon Sep 17 00:00:00 2001 From: Justin Barnett Date: Tue, 18 Mar 2025 13:47:33 -0400 Subject: [PATCH] updated to find correct directory when installing to claude desktop automatically --- Editor/MCPEditorWindow.cs | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/Editor/MCPEditorWindow.cs b/Editor/MCPEditorWindow.cs index 27b4da7..89353a2 100644 --- a/Editor/MCPEditorWindow.cs +++ b/Editor/MCPEditorWindow.cs @@ -273,9 +273,41 @@ public class MCPEditorWindow : EditorWindow // Create directory if it doesn't exist Directory.CreateDirectory(Path.GetDirectoryName(configPath)); - // Get the absolute path to the Python directory - string pythonDir = Path.GetFullPath(Path.Combine(Application.dataPath, "unity-mcp", "Python")); - UnityEngine.Debug.Log($"Python directory path: {pythonDir}"); + // Find the server.py file location + string serverPath = null; + string pythonDir = null; + + // First try to find it in the current project's Assets folder + string localServerPath = Path.GetFullPath(Path.Combine(Application.dataPath, "unity-mcp", "Python", "server.py")); + if (File.Exists(localServerPath)) + { + serverPath = localServerPath; + pythonDir = Path.GetDirectoryName(serverPath); + } + else + { + // If not found locally, try to find it in the package cache + string packageName = "com.justinpbarnett.unitymcpserver"; + string packageCachePath = Path.Combine(Application.dataPath, "..", "Library", "PackageCache", packageName); + if (Directory.Exists(packageCachePath)) + { + serverPath = Path.GetFullPath(Path.Combine(packageCachePath, "Python", "server.py")); + if (File.Exists(serverPath)) + { + pythonDir = Path.GetDirectoryName(serverPath); + } + } + } + + if (serverPath == null || !File.Exists(serverPath)) + { + claudeConfigStatus = "Error: Could not find server.py"; + UnityEngine.Debug.LogError("Could not find server.py in either local project or package cache"); + return; + } + + UnityEngine.Debug.Log($"Found server.py at: {serverPath}"); + UnityEngine.Debug.Log($"Python directory: {pythonDir}"); // Create configuration object var config = new MCPConfig