Skip to content

fix: Map 'info' log type to Unity's 'Log' type for console log retrieval #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

Saqoosha
Copy link
Contributor

@Saqoosha Saqoosha commented May 31, 2025

Summary

• Fix info log type mapping issue in ConsoleLogsService where MCP's "info" parameter didn't match Unity's "Log" type
• Add mapping logic to convert "info" to "Log" before filtering log entries in GetAllLogsAsJson method

Environment Details

  • Unity Version: Unity 6 (6000.0.26f1) - tested and confirmed
  • Platform: macOS 15.5 (Sequoia)
  • MCP Unity Version: v1.1.0+
  • Affected Tool: get_console_logs with logType: "info" parameter

Problem Description

The get_console_logs MCP tool was unable to retrieve info-level logs when using the "info" logType parameter. This occurred because:

  1. Unity Internal Logging: Debug.Log() messages are stored as LogType.Log (string: "Log")
  2. MCP Parameter: Client requests use logType: "info"
  3. Filtering Logic: Direct string comparison "info" \!= "Log" caused info logs to be filtered out

Reproduction Steps

// This would return empty array before the fix
get_console_logs({ logType: "info" })

Root Cause

In ConsoleLogsService.cs line 83, the filtering logic:

if (filter && \!entry.Type.ToString().Equals(logType, System.StringComparison.OrdinalIgnoreCase))

Would compare "info" (MCP parameter) with "Log" (Unity's LogType.Log.ToString()), causing a mismatch.

Solution

Added type mapping logic before filtering:

// Map MCP log types to Unity log types
string unityLogType = logType;
if (logType.Equals("info", System.StringComparison.OrdinalIgnoreCase))
    unityLogType = "Log";

Test Plan

  • Send info log via send_console_log tool with type: "info"
  • Retrieve info logs via get_console_logs tool with logType: "info"
  • Verify warning and error logs still work correctly
  • Test in Unity 6 (6000.0.26f1) on macOS 15.5 (Sequoia)
  • Confirm no regression in existing functionality

Impact

This fix enables proper info log retrieval through MCP tools, making debugging and monitoring more effective for MCP Unity users.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Improved log filtering by correctly mapping external log types to internal types, ensuring more accurate display of log entries when filtering by log type.

The get_console_logs tool was unable to retrieve info logs because MCP's "info"
parameter didn't match Unity's internal "Log" type string. Added mapping logic
to convert "info" to "Log" before filtering log entries.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link

cubic-dev-ai bot commented May 31, 2025

Your cubic subscription is currently inactive. Please reactivate your subscription to receive AI reviews and use cubic.

Copy link
Contributor

coderabbitai bot commented May 31, 2025

📝 Walkthrough

"""

Walkthrough

The method responsible for returning logs as JSON was updated to normalize the input log type string using a static dictionary that maps external MCP log types (e.g., "info") to Unity's internal log types (e.g., "Log"). This mapping occurs once before filtering to ensure consistent log type comparisons.

Changes

File Change Summary
Editor/Services/ConsoleLogsService.cs Added static dictionary to map external to internal log types; mapped input logType before filtering in GetAllLogsAsJson

Poem

In the warren where the logs all hop,
"info" now knows where to stop—
It wears its "Log" disguise with pride,
So every entry’s classified!
Hopping through code, neat and spry,
Consistency keeps our carrots dry. 🥕
"""


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1ecfd45 and 1f28ea4.

📒 Files selected for processing (1)
  • Editor/Services/ConsoleLogsService.cs (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • Editor/Services/ConsoleLogsService.cs
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb4b03c and cc2cb1a.

📒 Files selected for processing (1)
  • Editor/Services/ConsoleLogsService.cs (1 hunks)

Move log type mapping logic outside the loop to avoid repeated processing.
Added static Dictionary for MCP-to-Unity log type mappings with case-insensitive
comparison. This improves performance and provides better extensibility for
future log type mappings.

Addresses CodeRabbit review feedback for performance optimization.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@CoderGamester
Copy link
Owner

interesting solution but this only accepts "info" requests
@Saqoosha please add for error, warning, log entries to the dictionary for those use case requests

Per PR review feedback, expanded the log type mapping to handle multi-value
mappings. The "error" filter now returns all error-related log types.

We found that filtering by "error" was not comprehensive enough for
development purposes - Exception and Assert logs are also error conditions
that developers need to see.

Changes:
- Changed LogTypeMapping from Dictionary<string, string> to
  Dictionary<string, HashSet<string>> to support 1-to-many mappings
- Added "error" → {"Error", "Exception", "Assert"} mapping
- Updated GetAllLogsAsJson filtering logic to use HashSet.Contains()

This ensures developers can see all error-related logs when filtering
by "error" type, making debugging more effective.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@Saqoosha
Copy link
Contributor Author

Saqoosha commented Jun 1, 2025

@CoderGamester Thank you for the review!

After reviewing the code and considering MCP's standard naming conventions, I realized:

  • "info""Log" mapping is already in place
  • "warning" doesn't need explicit mapping due to case-insensitive comparison
  • "error" needed special handling to map to multiple Unity log types

I've updated the implementation to support multi-value mappings. The "error" filter now returns all error-related logs:

  • Error (from Debug.LogError())
  • Exception (from thrown exceptions)
  • Assert (from Debug.Assert())

This makes the tool more useful for developers since all error conditions are captured with a single filter.

Changes made:

  • Changed LogTypeMapping to use Dictionary<string, HashSet<string>> for 1-to-many mappings
  • Updated filtering logic to use HashSet.Contains() for efficient lookups
  • Tested with all log types to ensure proper functionality

The implementation maintains backward compatibility while providing more comprehensive error filtering.

Copy link
Owner

@CoderGamester CoderGamester left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@CoderGamester CoderGamester merged commit b8b9cf8 into CoderGamester:main Jun 1, 2025
1 check passed
@Saqoosha Saqoosha deleted the fix/info-log-type-mapping branch June 2, 2025 02:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants