@@ -28,6 +28,7 @@ public GetConsoleLogsResource()
2828 {
2929 Name = "get_console_logs" ;
3030 Description = "Retrieves all logs from the Unity console" ;
31+ Uri = "logs://console" ;
3132
3233 // Register for log messages
3334 Application . logMessageReceived += OnLogMessageReceived ;
@@ -43,36 +44,6 @@ public GetConsoleLogsResource()
4344 Debug . Log ( "[MCP Unity] Console logs resource initialized" ) ;
4445 }
4546
46- /// <summary>
47- /// Check if console was cleared using reflection (for Unity 2022.3)
48- /// </summary>
49- private void CheckConsoleClearViaReflection ( )
50- {
51- try
52- {
53- // Get current log counts using LogEntries (internal Unity API)
54- var logEntriesType = Type . GetType ( "UnityEditor.LogEntries,UnityEditor" ) ;
55- if ( logEntriesType == null ) return ;
56-
57- var getCountMethod = logEntriesType . GetMethod ( "GetCount" ,
58- BindingFlags . Public | BindingFlags . Static | BindingFlags . NonPublic ) ;
59- if ( getCountMethod == null ) return ;
60-
61- int currentTotalCount = ( int ) getCountMethod . Invoke ( null , null ) ;
62-
63- // If we had logs before, but now we don't, console was likely cleared
64- if ( currentTotalCount == 0 && _logEntries . Count > 0 )
65- {
66- ClearLogs ( ) ;
67- }
68- }
69- catch ( Exception ex )
70- {
71- // Just log the error but don't break functionality
72- Debug . LogError ( $ "[MCP Unity] Error checking console clear: { ex . Message } ") ;
73- }
74- }
75-
7647 /// <summary>
7748 /// Fetch all logs from the Unity console
7849 /// </summary>
@@ -105,6 +76,36 @@ public override JObject Fetch(JObject parameters)
10576 [ "logs" ] = logsArray
10677 } ;
10778 }
79+
80+ /// <summary>
81+ /// Check if console was cleared using reflection (for Unity 2022.3)
82+ /// </summary>
83+ private void CheckConsoleClearViaReflection ( )
84+ {
85+ try
86+ {
87+ // Get current log counts using LogEntries (internal Unity API)
88+ var logEntriesType = Type . GetType ( "UnityEditor.LogEntries,UnityEditor" ) ;
89+ if ( logEntriesType == null ) return ;
90+
91+ var getCountMethod = logEntriesType . GetMethod ( "GetCount" ,
92+ BindingFlags . Public | BindingFlags . Static | BindingFlags . NonPublic ) ;
93+ if ( getCountMethod == null ) return ;
94+
95+ int currentTotalCount = ( int ) getCountMethod . Invoke ( null , null ) ;
96+
97+ // If we had logs before, but now we don't, console was likely cleared
98+ if ( currentTotalCount == 0 && _logEntries . Count > 0 )
99+ {
100+ ClearLogs ( ) ;
101+ }
102+ }
103+ catch ( Exception ex )
104+ {
105+ // Just log the error but don't break functionality
106+ Debug . LogError ( $ "[MCP Unity] Error checking console clear: { ex . Message } ") ;
107+ }
108+ }
108109
109110 /// <summary>
110111 /// Callback for when a log message is received
0 commit comments