Skip to content

feat: Add search_console_logs tool for Unity log searching #51

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

Conversation

Saqoosha
Copy link
Contributor

@Saqoosha Saqoosha commented Jun 16, 2025

Summary

Add comprehensive Unity console log search functionality as an MCP tool, providing powerful search capabilities for Unity developers using Claude Code and other MCP clients.

🔍 Features Added

Core Search Capabilities

  • Keyword Search: Partial text matching with configurable case sensitivity
  • Regular Expression Search: Full regex pattern support for advanced queries
  • Log Type Filtering: Filter by error, warning, or info log types
  • Stack Trace Control: Optional inclusion/exclusion for token optimization
  • Pagination: Offset and limit support for handling large result sets

Implementation Details

  • SearchConsoleLogsTool.cs: Unity-side tool implementation
  • searchConsoleLogsTool.ts: Node.js MCP server integration with Zod validation
  • Integrated Architecture: Works with existing ConsoleLogsService infrastructure
  • Dual Compatibility: Supports both Unity 2022.3 and Unity 6 implementations
  • Tool-based Approach: Optimized for Claude Code compatibility over resource-based approach

Enhanced Console Log Service

  • Configurable Service Types: Added ConsoleLogServiceType enum with EventBased (default, safe) and Unity6Enhanced (experimental) options
  • Unity 6 Support: Implemented specialized service using internal Unity APIs for better reliability in Unity 6
  • UI Configuration: Added settings in McpUnityEditorWindow with appropriate warnings about internal API usage
  • Automatic Fallback: Falls back to safe implementation on pre-Unity 6 versions

LogEntry Mode Flags Support

  • Comprehensive Flag Mapping: Added LogEntryModeFlags.cs with Unity's internal mode flag constants
  • Improved Classification: Better handling of compiler errors, shader errors, and runtime exceptions
  • Documentation: Added detailed Unity6InternalAPIReference.md with complete API documentation

🧪 Testing Results

All search functionality has been thoroughly tested:

  • Keyword search: shader, texture, Player
  • Regex search: GameObject.*not found, ^\[MCP\].*
  • Log type filtering: error, warning, info
  • Case sensitivity: both sensitive and insensitive modes
  • Stack trace: inclusion/exclusion options
  • Pagination: offset and limit parameters
  • Error handling: invalid regex patterns handled gracefully
  • Service types: Both EventBased and Unity6Enhanced implementations

📋 Usage Examples

// Search for shader-related errors
{
  "tool": "search_console_logs",
  "parameters": {
    "keyword": "shader",
    "logType": "error",
    "limit": 10,
    "includeStackTrace": false
  }
}

// Advanced regex search
{
  "tool": "search_console_logs", 
  "parameters": {
    "regex": "GameObject.*not found",
    "caseSensitive": false,
    "limit": 20
  }
}

🎯 Benefits

  • Developer Productivity: Quickly find specific log entries without manual scrolling
  • Debug Efficiency: Use regex patterns for complex log analysis
  • Token Optimization: Control stack trace inclusion to manage LLM token usage
  • Scalability: Pagination handles projects with thousands of log entries
  • Flexibility: Multiple search modes for different debugging scenarios
  • Enhanced Reliability: Unity 6 implementation captures logs that might be missed by event-based approach

This tool significantly enhances the Unity development experience when using Claude Code for debugging and log analysis.

🤖 Generated with Claude Code

Created with Palmier

Summary by CodeRabbit

  • New Features

    • Added advanced search functionality for Unity console logs, allowing keyword or regex searches, log type filtering, case sensitivity, stack trace inclusion, and pagination.
    • Introduced a new tool for searching console logs with configurable options and structured results.
    • Added support for an enhanced console log service in Unity 6+, providing more reliable log retrieval via internal Unity APIs.
    • Users can now select the console log service implementation from the server tab in the MCP Unity Editor window.
  • Improvements

    • Settings now include an option to choose between standard and enhanced console log services (requires server restart).
    • Enhanced visibility of available resources and improved debug logging for server resource handling.
  • Documentation

    • Added internal API reference documentation for Unity 6 log entry structure and mode flags.
  • Chores

    • Updated ignore rules to exclude Claude settings from version control.

Saqoosha and others added 6 commits June 7, 2025 18:01
…ementation

- Add ConsoleLogServiceType enum with EventBased and Unity6Enhanced options
- Implement ConsoleLogsServiceUnity6 using internal LogEntries API for better reliability
- Add command line argument support (-mcpConsoleLogService) for runtime switching
- Update McpUnityServer to dynamically select service based on settings and Unity version
- Add UI controls in McpUnityEditorWindow with warning dialogs for internal API usage
- Default to safe EventBased implementation, Unity6Enhanced only when explicitly selected
- Add clear startup logging to identify which implementation is active

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

Co-Authored-By: Claude <[email protected]>
…ered values

- Create LogEntryModeFlags.cs with Unity's internal mode flag constants
- Add support for observed mode values from debugging:
  * Compiler warnings: 266240 (0x41000)
  * Compiler errors: 272384 (0x42800)
  * Shader errors: 262212 (0x40044)
  * Runtime warnings: 8405504 (0x804200)
  * Runtime errors: 8405248 (0x804100)
- Update Unity6InternalAPIReference.md with complete documentation
- Add conditional debug logging for future mode value discovery
- Improve error/warning classification accuracy in Unity 6 implementation

This enables proper filtering of shader errors, compile errors, and runtime
exceptions that were previously misclassified as "Log" type.

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

Co-Authored-By: Claude <[email protected]>
- Removed GetEffectiveConsoleLogService() method
- Console log service now only configurable via Unity Editor settings UI
- Simplified configuration as command-line args are not practical for Unity Hub users

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

Co-Authored-By: Claude <[email protected]>
🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
Keep file locally but stop tracking it in git

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

Co-Authored-By: Claude <[email protected]>
- Add SearchConsoleLogsTool.cs with keyword/regex search support
- Support case-sensitive/insensitive search with logType filtering
- Include pagination (offset/limit) and optional stack trace inclusion
- Implement both C# (Unity) and TypeScript (Node.js) components
- Register tool in McpUnityServer and Node.js MCP server
- Remove previous resource-based implementation in favor of tool-based approach
- Add comprehensive search capabilities:
  - Keyword search with partial matching
  - Regular expression pattern matching
  - Log type filtering (error/warning/info)
  - Configurable case sensitivity
  - Stack trace inclusion/exclusion for token optimization
  - Pagination support for large result sets

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

Co-Authored-By: Claude <[email protected]>
Copy link
Contributor

coderabbitai bot commented Jun 16, 2025

Caution

Review failed

The pull request is closed.

📝 Walkthrough

Walkthrough

This update introduces an advanced search capability for Unity console logs, allowing searches by keyword or regular expression with options for log type filtering, case sensitivity, stack trace inclusion, and pagination. It adds a Unity 6-specific log service, new tool registration, UI for service selection, and supporting documentation and metadata.

Changes

File(s) Change Summary
.gitignore Added .claude/settings.local.json to ignore list.
Editor/Services/ConsoleLogsService.cs Added SearchLogsAsJson method for keyword/regex log search with filtering and pagination.
Editor/Services/ConsoleLogsServiceUnity6.cs, .meta New Unity 6-specific log service using internal APIs; supports advanced search and log retrieval.
Editor/Services/IConsoleLogsService.cs Added SearchLogsAsJson to interface for log search functionality.
Editor/Services/LogEntryModeFlags.cs, .meta New static class/constants for Unity log mode flags and log type inference.
Editor/Services/Unity6InternalAPIReference.md, .meta New documentation describing Unity 6 internal log entry structure and mode flags.
Editor/Tools/SearchConsoleLogsTool.cs, .meta New tool for searching logs by keyword/regex with filtering and pagination.
Editor/UnityBridge/McpUnityEditorWindow.cs Added UI element for selecting console log service implementation in server tab.
Editor/UnityBridge/McpUnityServer.cs Uses IConsoleLogsService for polymorphism; registers new search tool; supports service selection logic.
Editor/UnityBridge/McpUnitySettings.cs Added ConsoleLogServiceType enum and field for selecting log service implementation.
Editor/UnityBridge/McpUnitySocketHandler.cs Added debug logging for resource/method resolution in OnMessage.
Server~/build/index.js, Server~/src/index.ts Registered new search console logs tool in server setup.
Server~/build/utils/errors.js, Server~/build/utils/logger.js Changed enum initialization order for ErrorType and LogLevel.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant MCP Unity Editor
    participant McpUnityServer
    participant IConsoleLogsService
    participant ConsoleLogsServiceUnity6

    User->>MCP Unity Editor: Selects log service type (UI)
    MCP Unity Editor->>McpUnityServer: Save setting, prompt for restart

    User->>McpUnityServer: Request searchConsoleLogs tool
    McpUnityServer->>IConsoleLogsService: SearchLogsAsJson(keyword, regex, logType, ...)
    alt Unity6Enhanced selected and Unity 6+
        IConsoleLogsService->>ConsoleLogsServiceUnity6: Perform internal API search
        ConsoleLogsServiceUnity6-->>IConsoleLogsService: Return search results as JSON
    else EventBased or fallback
        IConsoleLogsService->>ConsoleLogsService: Perform event-based search
        ConsoleLogsService-->>IConsoleLogsService: Return search results as JSON
    end
    IConsoleLogsService-->>McpUnityServer: Return search results
    McpUnityServer-->>User: Return search results
Loading

Possibly related PRs

  • CoderGamester/mcp-unity#33: Adds a simpler tool for retrieving console logs filtered by type; related as both extend console log access tools.
  • CoderGamester/mcp-unity#42: Adds paginated log retrieval; related through pagination and log access but focuses on fetching rather than searching.
  • CoderGamester/mcp-unity#44: Adds includeStackTrace to log retrieval; directly related as both extend log search/retrieval APIs with stack trace options.

Suggested reviewers

  • CoderGamester

Poem

In the warren of logs, the rabbit did hop,
Searching with regex, it never would stop.
From Unity’s depths, with filters and flair,
Stack traces or not, the answers are there.
Now with enhanced tools, the search is a breeze—
Console logs found with the greatest of ease!
🐇🔍


📜 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 219eccc and 5b2ebf4.

📒 Files selected for processing (19)
  • .gitignore (1 hunks)
  • Editor/Services/ConsoleLogsService.cs (2 hunks)
  • Editor/Services/ConsoleLogsServiceUnity6.cs (1 hunks)
  • Editor/Services/ConsoleLogsServiceUnity6.cs.meta (1 hunks)
  • Editor/Services/IConsoleLogsService.cs (1 hunks)
  • Editor/Services/LogEntryModeFlags.cs (1 hunks)
  • Editor/Services/LogEntryModeFlags.cs.meta (1 hunks)
  • Editor/Services/Unity6InternalAPIReference.md (1 hunks)
  • Editor/Services/Unity6InternalAPIReference.md.meta (1 hunks)
  • Editor/Tools/SearchConsoleLogsTool.cs (1 hunks)
  • Editor/Tools/SearchConsoleLogsTool.cs.meta (1 hunks)
  • Editor/UnityBridge/McpUnityEditorWindow.cs (1 hunks)
  • Editor/UnityBridge/McpUnityServer.cs (5 hunks)
  • Editor/UnityBridge/McpUnitySettings.cs (2 hunks)
  • Editor/UnityBridge/McpUnitySocketHandler.cs (1 hunks)
  • Server~/build/index.js (2 hunks)
  • Server~/build/utils/errors.js (1 hunks)
  • Server~/build/utils/logger.js (1 hunks)
  • Server~/src/index.ts (2 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Commit Unit Tests in branch feature/search-console-logs-tool-for-fork
  • Post Copyable Unit Tests in Comment

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 auto-generate unit tests to generate unit tests for 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.

@Saqoosha Saqoosha closed this Jun 16, 2025
@Saqoosha Saqoosha deleted the feature/search-console-logs-tool-for-fork branch June 16, 2025 21:33
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.

1 participant