updated to find correct directory when installing to claude desktop automatically

main
Justin Barnett 2025-03-18 13:47:33 -04:00
parent 46db62bfaa
commit eeaa7a2c55
1 changed files with 35 additions and 3 deletions

View File

@ -273,9 +273,41 @@ public class MCPEditorWindow : EditorWindow
// Create directory if it doesn't exist // Create directory if it doesn't exist
Directory.CreateDirectory(Path.GetDirectoryName(configPath)); Directory.CreateDirectory(Path.GetDirectoryName(configPath));
// Get the absolute path to the Python directory // Find the server.py file location
string pythonDir = Path.GetFullPath(Path.Combine(Application.dataPath, "unity-mcp", "Python")); string serverPath = null;
UnityEngine.Debug.Log($"Python directory path: {pythonDir}"); 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 // Create configuration object
var config = new MCPConfig var config = new MCPConfig