Skip to content

read_console returns no entries for compilation errors (CS errors invisible to AI agents) #861

Description

@johnkslg

Description

read_console with types: ["error"] (or even types: ["all"]) returns zero entries when C# compilation errors exist. Compiler diagnostics (error CS####) are written to Editor.log and appear in the Unity Console UI, but are not returned by the read_console tool.

This means AI agents have no MCP-based way to detect compilation failures after editing scripts -- arguably the single most important feedback loop for code-editing agents.

Steps to Reproduce

  1. Introduce a deliberate C# compilation error (e.g., call a method with wrong argument count)
  2. Call refresh_unity with compile: "request", wait_for_ready: true
  3. Wait 15 seconds for compilation to complete
  4. Call read_console with action: "get", types: ["error"], count: 50
  5. Result: Returns {"success": true} with zero entries
  6. Call read_console with types: ["all"] -- still zero entries
  7. Check Editor.log directly -- the error CS#### lines are there

Expected Behavior

read_console should return compilation errors (e.g., error CS1501: No overload for method 'Get' takes 3 arguments) as error-type entries.

Root Cause Analysis

Looking at the ReadConsole.cs source, it uses LogEntries.StartGettingEntries / GetEntryInternal / EndGettingEntries via reflection. This reads Unity's internal console log buffer.

The issue appears to be that when compilation fails, the domain reload does not complete, so:

  • The LogEntries buffer may not contain the compiler diagnostics at all, or
  • The entries exist but the MCP server (running in the editor domain) may be in a state where it can't read them properly

The InferTypeFromMessage method in ReadConsole.cs does have logic to detect "error CS" patterns, so the filtering logic is correct -- the entries simply aren't present in the LogEntries buffer.

Current Workaround

Read the Unity Editor.log file directly:

Get-Content "$env:LOCALAPPDATA\Unity\Editor\Editor.log" -Tail 300 | Select-String -Pattern "error CS\d{4}"

Suggested Fix

Consider using UnityEditor.Compilation.CompilationPipeline to capture compilation results separately. For example:

  • CompilationPipeline.assemblyCompilationFinished event to capture per-assembly results
  • Store compilation diagnostics in a separate buffer that read_console (or a new tool/resource) can query
  • Alternatively, expose compilation status in the editor_state resource (the compilation field is currently always null)

Environment

  • Unity MCP: v9.4.7
  • Unity: 6 (6000.x)
  • OS: Windows 10
  • Client: Cursor IDE

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions