Skip to content

Commit 2ca51d7

Browse files
committed
Merge upstream/main and resolve conflicts in ConsoleLogsService.cs
Resolved conflict by combining pagination functionality with the new log type mapping feature from upstream.
2 parents 6f1ddc0 + b8b9cf8 commit 2ca51d7

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

Editor/Services/ConsoleLogsService.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{
@@ -96,13 +104,28 @@ public JObject GetLogsAsJson(string logType = "", int offset = 0, int limit = 10
96104
int filteredCount = 0;
97105
int currentIndex = 0;
98106

107+
// Map MCP log types to Unity log types outside the loop for better performance
108+
HashSet<string> unityLogTypes = null;
109+
if (filter)
110+
{
111+
if (LogTypeMapping.TryGetValue(logType, out var mapped))
112+
{
113+
unityLogTypes = mapped;
114+
}
115+
else
116+
{
117+
// If no mapping exists, create a set with the original type for case-insensitive comparison
118+
unityLogTypes = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { logType };
119+
}
120+
}
121+
99122
lock (_logEntries)
100123
{
101124
// First pass: count total and filtered entries
102125
foreach (var entry in _logEntries)
103126
{
104127
totalCount++;
105-
if (!filter || entry.Type.ToString().Equals(logType, System.StringComparison.OrdinalIgnoreCase))
128+
if (!filter || unityLogTypes.Contains(entry.Type.ToString()))
106129
{
107130
filteredCount++;
108131
}
@@ -112,7 +135,7 @@ public JObject GetLogsAsJson(string logType = "", int offset = 0, int limit = 10
112135
for (int i = _logEntries.Count - 1; i >= 0; i--)
113136
{
114137
var entry = _logEntries[i];
115-
if (filter && !entry.Type.ToString().Equals(logType, System.StringComparison.OrdinalIgnoreCase))
138+
if (filter && !unityLogTypes.Contains(entry.Type.ToString()))
116139
continue;
117140

118141
if (currentIndex >= offset && logsArray.Count < limit)

0 commit comments

Comments
 (0)