diff --git a/Editor/Services/ConsoleLogsService.cs b/Editor/Services/ConsoleLogsService.cs index 74c00c15..b0fac8b0 100644 --- a/Editor/Services/ConsoleLogsService.cs +++ b/Editor/Services/ConsoleLogsService.cs @@ -12,6 +12,14 @@ namespace McpUnity.Services /// public class ConsoleLogsService : IConsoleLogsService { + // Static mapping for MCP log types to Unity log types + // Some MCP types map to multiple Unity types (e.g., "error" includes Error, Exception and Assert) + private static readonly Dictionary> LogTypeMapping = new Dictionary>(StringComparer.OrdinalIgnoreCase) + { + { "info", new HashSet(StringComparer.OrdinalIgnoreCase) { "Log" } }, + { "error", new HashSet(StringComparer.OrdinalIgnoreCase) { "Error", "Exception", "Assert" } } + }; + // Structure to store log information private class LogEntry { @@ -76,11 +84,26 @@ public JArray GetAllLogsAsJson(string logType = "") JArray logsArray = new JArray(); bool filter = !string.IsNullOrEmpty(logType); + // Map MCP log types to Unity log types outside the loop for better performance + HashSet unityLogTypes = null; + if (filter) + { + if (LogTypeMapping.TryGetValue(logType, out var mapped)) + { + unityLogTypes = mapped; + } + else + { + // If no mapping exists, create a set with the original type for case-insensitive comparison + unityLogTypes = new HashSet(StringComparer.OrdinalIgnoreCase) { logType }; + } + } + lock (_logEntries) { foreach (var entry in _logEntries) { - if (filter && !entry.Type.ToString().Equals(logType, System.StringComparison.OrdinalIgnoreCase)) + if (filter && !unityLogTypes.Contains(entry.Type.ToString())) continue; logsArray.Add(new JObject {