55using MCPForUnity . Editor . Dependencies . Models ;
66using MCPForUnity . Editor . Dependencies . PlatformDetectors ;
77using MCPForUnity . Editor . Helpers ;
8+ using MCPForUnity . Editor . Services ;
89using UnityEditor ;
910using UnityEngine ;
1011
1112namespace MCPForUnity . Editor . Dependencies
1213{
14+ /// <summary>
15+ /// Context object containing all necessary paths and settings for dependency checking.
16+ /// This allows the check to run on a background thread without accessing Unity APIs.
17+ /// </summary>
18+ public class DependencyContext
19+ {
20+ public string PackageRootPath { get ; set ; }
21+ public string PythonOverridePath { get ; set ; }
22+ public string NodeOverridePath { get ; set ; }
23+ public string UvOverridePath { get ; set ; }
24+ }
25+
1326 /// <summary>
1427 /// Main orchestrator for dependency validation and management
1528 /// </summary>
@@ -41,9 +54,31 @@ public static IPlatformDetector GetCurrentPlatformDetector()
4154 }
4255
4356 /// <summary>
44- /// Perform a comprehensive dependency check
57+ /// Perform a comprehensive dependency check (Synchronous - Main Thread Only)
4558 /// </summary>
4659 public static DependencyCheckResult CheckAllDependencies ( )
60+ {
61+ // Gather context on main thread
62+ var context = new DependencyContext
63+ {
64+ PackageRootPath = AssetPathUtility . GetMcpPackageRootPath ( ) , // Changed to match local API
65+ PythonOverridePath = MCPServiceLocator . Paths . GetPythonPath ( ) ,
66+ NodeOverridePath = MCPServiceLocator . Paths . GetNodePath ( ) ,
67+ UvOverridePath = MCPServiceLocator . Paths . GetUvxPath ( )
68+ } ;
69+
70+ return CheckAllDependenciesInternal ( context ) ;
71+ }
72+
73+ /// <summary>
74+ /// Perform a comprehensive dependency check (Thread-Safe)
75+ /// </summary>
76+ public static DependencyCheckResult CheckAllDependenciesAsync ( DependencyContext context )
77+ {
78+ return CheckAllDependenciesInternal ( context ) ;
79+ }
80+
81+ private static DependencyCheckResult CheckAllDependenciesInternal ( DependencyContext context )
4782 {
4883 var result = new DependencyCheckResult ( ) ;
4984
@@ -53,13 +88,52 @@ public static DependencyCheckResult CheckAllDependencies()
5388 McpLog . Info ( $ "Checking dependencies on { detector . PlatformName } ...", always : false ) ;
5489
5590 // Check Python
56- var pythonStatus = detector . DetectPython ( ) ;
91+ var pythonStatus = detector . DetectPython ( context . PythonOverridePath ) ;
5792 result . Dependencies . Add ( pythonStatus ) ;
5893
5994 // Check uv
60- var uvStatus = detector . DetectUv ( ) ;
95+ var uvStatus = detector . DetectUv ( context . UvOverridePath ) ;
6196 result . Dependencies . Add ( uvStatus ) ;
6297
98+ // Check Node.js
99+ // Note: If detector doesn't support DetectNode yet, we might need to update detectors too.
100+ // Assuming detectors are being updated or have default interface implementation.
101+ var nodeStatus = detector . DetectNode ( context . NodeOverridePath ) ;
102+ result . Dependencies . Add ( nodeStatus ) ;
103+
104+ // Check Server Environment
105+ // We assume ServerEnvironmentSetup.IsEnvironmentReady exists.
106+ // If not, we'll need to update that too.
107+ // Note: IsEnvironmentReady might access Unity API. If so, this "Async" flavor is risky.
108+ // But CheckAllDependencies() is called on main thread in our UI usage.
109+
110+ // For now, we use a try-catch block specifically for server check to avoid blocking the whole result
111+ try
112+ {
113+ // We use the path gathered on the main thread to ensure thread safety
114+ bool isServerReady = MCPForUnity . Editor . Setup . ServerEnvironmentSetup . IsEnvironmentReady ( context . PackageRootPath ) ;
115+
116+ result . Dependencies . Add ( new DependencyStatus ( "Server Environment" , true )
117+ {
118+ Version = isServerReady ? "Installed" : "Missing" ,
119+ IsAvailable = isServerReady ,
120+ Details = isServerReady ? "Virtual Environment Ready" : "Run 'Install Server Environment'" ,
121+ ErrorMessage = isServerReady ? null : "Virtual environment not set up"
122+ } ) ;
123+ }
124+ catch ( Exception ex )
125+ {
126+ McpLog . Warn ( $ "Server environment check failed: { ex . Message } ") ;
127+ result . Dependencies . Add ( new DependencyStatus ( "Server Environment" , true )
128+ {
129+ Version = "Error" ,
130+ IsAvailable = false ,
131+ Details = "Check failed" ,
132+ ErrorMessage = ex . Message
133+ } ) ;
134+ }
135+
136+
63137 // Generate summary and recommendations
64138 result . GenerateSummary ( ) ;
65139 GenerateRecommendations ( result , detector ) ;
@@ -122,12 +196,16 @@ private static void GenerateRecommendations(DependencyCheckResult result, IPlatf
122196 {
123197 if ( dep . Name == "Python" )
124198 {
125- result . RecommendedActions . Add ( $ "Install Python 3.10 + from: { detector . GetPythonInstallUrl ( ) } ") ;
199+ result . RecommendedActions . Add ( $ "Install python 3.11 + from: { detector . GetPythonInstallUrl ( ) } ") ;
126200 }
127201 else if ( dep . Name == "uv Package Manager" )
128202 {
129203 result . RecommendedActions . Add ( $ "Install uv package manager from: { detector . GetUvInstallUrl ( ) } ") ;
130204 }
205+ else if ( dep . Name == "Node.js" )
206+ {
207+ result . RecommendedActions . Add ( "Install Node.js (LTS) from: https://nodejs.org/" ) ;
208+ }
131209 else if ( dep . Name == "MCP Server" )
132210 {
133211 result . RecommendedActions . Add ( "MCP Server will be installed automatically when needed." ) ;
0 commit comments