Skip to content

[HIGH] fast-path JSON-RPC methods bypass main-thread dispatch without a safety contract #79

Description

@Daliys

Problem

Several JSON-RPC methods intentionally execute on the listener/current thread instead of being marshaled to the Unity main thread, but the code does not enforce or document that those handlers must avoid Unity APIs.

Evidence

  • Editor/MCPServerMethods.cs:116-122 fast-paths get_server_status, attach_existing_session, wait_for_asset_import_idle, and wait_for_editor_idle through ExecuteMethod on the current thread.
  • Editor/MCPServerMethods.Status.cs:28-69 implements get_server_status and currently reads Application.unityVersion as part of the response.
  • Editor/MCPServerMethods.Sync.cs:42-90 implements the wait methods off-thread using cached state and sleep loops.

Impact

Unity APIs are generally main-thread-only. A future edit to one of these handlers can accidentally add unsafe UnityEditor/UnityEngine calls that run on the listener thread, causing exceptions or racey editor behavior. The current get_server_status already mixes cached state with Application.unityVersion, so the contract is not obvious.

Suggested fix

Make the fast-path contract explicit and enforce it: keep handlers limited to thread-safe cached state, move unsafe fields behind main-thread dispatch, or split fast health checks from rich editor status. Add comments/tests around the allowed off-thread surface.

Source report

Imported from audit report item: security (8) / Editor/MCPServerMethods.cs:117.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingneeds-triageImported or reported issue awaiting owner reviewpriority: highMajor broken workflow or broad compatibility failuresurface: json-rpcRaw JSON-RPC methods, schemas, or dispatch surfacesurface: unity-editorUnity Editor package, windows, menus, or C# server surfacetype: correctnessIncorrect result, bad validation, or misleading success/failure behaviortype: threadingThread-affinity, race, or main-thread dispatch issue

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions