@@ -1145,11 +1145,20 @@ private string WriteToConfig(string pythonDir, string configPath, McpClient mcpC
11451145 && System . IO . File . Exists ( System . IO . Path . Combine ( serverSrc , "server.py" ) ) ;
11461146 if ( ! serverValid )
11471147 {
1148- serverSrc = ResolveServerSrc ( ) ;
1148+ // Prefer the provided pythonDir if valid; fall back to resolver
1149+ if ( ! string . IsNullOrEmpty ( pythonDir ) && System . IO . File . Exists ( System . IO . Path . Combine ( pythonDir , "server.py" ) ) )
1150+ {
1151+ serverSrc = pythonDir ;
1152+ }
1153+ else
1154+ {
1155+ serverSrc = ResolveServerSrc ( ) ;
1156+ }
11491157 }
11501158
11511159 // Hard-block PackageCache on Windows unless dev override is set
11521160 if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows )
1161+ && ! string . IsNullOrEmpty ( serverSrc )
11531162 && serverSrc . IndexOf ( @"\Library\PackageCache\" , StringComparison . OrdinalIgnoreCase ) >= 0
11541163 && ! UnityEditor . EditorPrefs . GetBool ( "MCPForUnity.UseEmbeddedServer" , false ) )
11551164 {
@@ -1616,7 +1625,8 @@ private void CheckMcpConfiguration(McpClient mcpClient)
16161625 // Common logic for checking configuration status
16171626 if ( configExists )
16181627 {
1619- bool matches = pythonDir != null && Array . Exists ( args , arg => arg . Contains ( pythonDir , StringComparison . Ordinal ) ) ;
1628+ string configuredDir = ExtractDirectoryArg ( args ) ;
1629+ bool matches = ! string . IsNullOrEmpty ( configuredDir ) && PathsEqual ( configuredDir , pythonDir ) ;
16201630 if ( matches )
16211631 {
16221632 mcpClient . SetStatus ( McpStatus . Configured ) ;
@@ -1799,31 +1809,7 @@ private void UnregisterWithClaudeCode()
17991809 }
18001810 }
18011811
1802- private bool ParseTextOutput ( string claudePath , string projectDir , string pathPrepend )
1803- {
1804- if ( ExecPath . TryRun ( claudePath , "mcp list" , projectDir , out var listStdout , out var listStderr , 10000 , pathPrepend ) )
1805- {
1806- UnityEngine . Debug . Log ( $ "Claude MCP servers (text): { listStdout } ") ;
1807-
1808- // Check if output indicates no servers or contains "UnityMCP" variants
1809- if ( listStdout . Contains ( "No MCP servers configured" ) ||
1810- listStdout . Contains ( "no servers" ) ||
1811- listStdout . Contains ( "No servers" ) ||
1812- string . IsNullOrWhiteSpace ( listStdout ) ||
1813- listStdout . Trim ( ) . Length == 0 )
1814- {
1815- return false ;
1816- }
1817-
1818- // Look for "UnityMCP" variants in the output
1819- return listStdout . Contains ( "UnityMCP" ) ||
1820- listStdout . Contains ( "unityMCP" ) ||
1821- listStdout . Contains ( "unity-mcp" ) ;
1822- }
1823-
1824- // If command failed, assume no servers
1825- return false ;
1826- }
1812+ // Removed unused ParseTextOutput
18271813
18281814 private string FindUvPath ( )
18291815 {
@@ -2105,93 +2091,7 @@ private string FindWindowsUvPath()
21052091 return null ; // Will fallback to using 'uv' from PATH
21062092 }
21072093
2108- private string FindClaudeCommand ( )
2109- {
2110- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) )
2111- {
2112- // Common locations for Claude CLI on Windows
2113- string [ ] possiblePaths = {
2114- Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . ApplicationData ) , "npm" , "claude.cmd" ) ,
2115- Path . Combine ( Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) , "npm" , "claude.cmd" ) ,
2116- "claude.cmd" , // Fallback to PATH
2117- "claude" // Final fallback
2118- } ;
2119-
2120- foreach ( string path in possiblePaths )
2121- {
2122- if ( path . Contains ( "\\ " ) && File . Exists ( path ) )
2123- {
2124- return path ;
2125- }
2126- }
2127-
2128- // Try to find via where command (PowerShell compatible)
2129- try
2130- {
2131- var psi = new ProcessStartInfo
2132- {
2133- FileName = "where.exe" ,
2134- Arguments = "claude" ,
2135- UseShellExecute = false ,
2136- RedirectStandardOutput = true ,
2137- RedirectStandardError = true ,
2138- CreateNoWindow = true
2139- } ;
2140-
2141- using var process = Process . Start ( psi ) ;
2142- string output = process . StandardOutput . ReadToEnd ( ) . Trim ( ) ;
2143- process . WaitForExit ( ) ;
2144-
2145- if ( process . ExitCode == 0 && ! string . IsNullOrEmpty ( output ) )
2146- {
2147- string [ ] lines = output . Split ( '\n ' ) ;
2148- foreach ( string line in lines )
2149- {
2150- string cleanPath = line . Trim ( ) ;
2151- if ( File . Exists ( cleanPath ) )
2152- {
2153- return cleanPath ;
2154- }
2155- }
2156- }
2157- }
2158- catch
2159- {
2160- // If where.exe fails, try PowerShell's Get-Command as fallback
2161- try
2162- {
2163- var psi = new ProcessStartInfo
2164- {
2165- FileName = "powershell.exe" ,
2166- Arguments = "-Command \" (Get-Command claude -ErrorAction SilentlyContinue).Source\" " ,
2167- UseShellExecute = false ,
2168- RedirectStandardOutput = true ,
2169- RedirectStandardError = true ,
2170- CreateNoWindow = true
2171- } ;
2172-
2173- using var process = Process . Start ( psi ) ;
2174- string output = process . StandardOutput . ReadToEnd ( ) . Trim ( ) ;
2175- process . WaitForExit ( ) ;
2176-
2177- if ( process . ExitCode == 0 && ! string . IsNullOrEmpty ( output ) && File . Exists ( output ) )
2178- {
2179- return output ;
2180- }
2181- }
2182- catch
2183- {
2184- // Ignore PowerShell errors too
2185- }
2186- }
2187-
2188- return "claude" ; // Final fallback to PATH
2189- }
2190- else
2191- {
2192- return "/usr/local/bin/claude" ;
2193- }
2194- }
2094+ // Removed unused FindClaudeCommand
21952095
21962096 private void CheckClaudeCodeConfiguration ( McpClient mcpClient )
21972097 {
0 commit comments