@@ -417,26 +417,8 @@ private void ShowManualConfigurationInstructions(string configPath)
417417 {
418418 claudeConfigStatus = "Error: Manual configuration required" ;
419419
420- // Get the Python directory path that's likely to exist
421- string pythonDir = "" ;
422- string [ ] possibleDirs = {
423- Path . GetFullPath ( Path . Combine ( Application . dataPath , "unity-mcp" , "Python" ) )
424- } ;
425-
426- foreach ( var dir in possibleDirs )
427- {
428- if ( Directory . Exists ( dir ) && File . Exists ( Path . Combine ( dir , "server.py" ) ) )
429- {
430- pythonDir = dir ;
431- break ;
432- }
433- }
434-
435- // If we couldn't find a Python directory, try to get the Assets path as a fallback
436- if ( string . IsNullOrEmpty ( pythonDir ) )
437- {
438- pythonDir = "/path/to/your/unity-mcp/Python" ;
439- }
420+ // Get the Python directory path using Package Manager API
421+ string pythonDir = FindPackagePythonDirectory ( ) ;
440422
441423 // Create the manual configuration message
442424 var jsonConfig = new MCPConfig
@@ -466,6 +448,68 @@ private void ShowManualConfigurationInstructions(string configPath)
466448 // Show a dedicated configuration window instead of console logs
467449 ManualConfigWindow . ShowWindow ( configPath , manualConfigJson ) ;
468450 }
451+
452+ private string FindPackagePythonDirectory ( )
453+ {
454+ string pythonDir = "/path/to/your/unity-mcp/Python" ;
455+
456+ try
457+ {
458+ // Try to find the package using Package Manager API
459+ var request = UnityEditor . PackageManager . Client . List ( ) ;
460+ while ( ! request . IsCompleted ) { } // Wait for the request to complete
461+
462+ if ( request . Status == UnityEditor . PackageManager . StatusCode . Success )
463+ {
464+ foreach ( var package in request . Result )
465+ {
466+ UnityEngine . Debug . Log ( $ "Package: { package . name } , Path: { package . resolvedPath } ") ;
467+
468+ if ( package . name == "com.justinpbarnett.unity-mcp" )
469+ {
470+ string packagePath = package . resolvedPath ;
471+ string potentialPythonDir = Path . Combine ( packagePath , "Python" ) ;
472+
473+ if ( Directory . Exists ( potentialPythonDir ) &&
474+ File . Exists ( Path . Combine ( potentialPythonDir , "server.py" ) ) )
475+ {
476+ UnityEngine . Debug . Log ( $ "Found package Python directory at: { potentialPythonDir } ") ;
477+ return potentialPythonDir ;
478+ }
479+ }
480+ }
481+ }
482+ else if ( request . Error != null )
483+ {
484+ UnityEngine . Debug . LogError ( "Failed to list packages: " + request . Error . message ) ;
485+ }
486+
487+ // If not found via Package Manager, try manual approaches
488+ // First check for local installation
489+ string [ ] possibleDirs = {
490+ Path . GetFullPath ( Path . Combine ( Application . dataPath , "unity-mcp" , "Python" ) )
491+ } ;
492+
493+ foreach ( var dir in possibleDirs )
494+ {
495+ UnityEngine . Debug . Log ( $ "Checking local directory: { dir } ") ;
496+ if ( Directory . Exists ( dir ) && File . Exists ( Path . Combine ( dir , "server.py" ) ) )
497+ {
498+ UnityEngine . Debug . Log ( $ "Found local Python directory at: { dir } ") ;
499+ return dir ;
500+ }
501+ }
502+
503+ // If still not found, return the placeholder path
504+ UnityEngine . Debug . LogWarning ( "Could not find Python directory, using placeholder path" ) ;
505+ }
506+ catch ( Exception e )
507+ {
508+ UnityEngine . Debug . LogError ( $ "Error finding package path: { e . Message } ") ;
509+ }
510+
511+ return pythonDir ;
512+ }
469513}
470514
471515// Editor window to display manual configuration instructions
0 commit comments