@@ -12,6 +12,14 @@ namespace McpUnity.Services
1212 /// </summary>
1313 public class ConsoleLogsService : IConsoleLogsService
1414 {
15+ // Static mapping for MCP log types to Unity log types
16+ // Some MCP types map to multiple Unity types (e.g., "error" includes Error, Exception and Assert)
17+ private static readonly Dictionary < string , HashSet < string > > LogTypeMapping = new Dictionary < string , HashSet < string > > ( StringComparer . OrdinalIgnoreCase )
18+ {
19+ { "info" , new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) { "Log" } } ,
20+ { "error" , new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) { "Error" , "Exception" , "Assert" } }
21+ } ;
22+
1523 // Structure to store log information
1624 private class LogEntry
1725 {
@@ -76,11 +84,26 @@ public JArray GetAllLogsAsJson(string logType = "")
7684 JArray logsArray = new JArray ( ) ;
7785 bool filter = ! string . IsNullOrEmpty ( logType ) ;
7886
87+ // Map MCP log types to Unity log types outside the loop for better performance
88+ HashSet < string > unityLogTypes = null ;
89+ if ( filter )
90+ {
91+ if ( LogTypeMapping . TryGetValue ( logType , out var mapped ) )
92+ {
93+ unityLogTypes = mapped ;
94+ }
95+ else
96+ {
97+ // If no mapping exists, create a set with the original type for case-insensitive comparison
98+ unityLogTypes = new HashSet < string > ( StringComparer . OrdinalIgnoreCase ) { logType } ;
99+ }
100+ }
101+
79102 lock ( _logEntries )
80103 {
81104 foreach ( var entry in _logEntries )
82105 {
83- if ( filter && ! entry . Type . ToString ( ) . Equals ( logType , System . StringComparison . OrdinalIgnoreCase ) )
106+ if ( filter && ! unityLogTypes . Contains ( entry . Type . ToString ( ) ) )
84107 continue ;
85108 logsArray . Add ( new JObject
86109 {
0 commit comments