Editor/Tools/SyntheticPlayerTools.Ui.cs

Editor tool method that exposes a MCP command pocketknife_ui_interact. It calls SyntheticUiDriver.InteractAsync with a selector, action, value and button, returning the result as MCP JSON and catching exceptions to return a failure outcome.

Process Execution
#nullable enable
using System;
using System.ComponentModel;
using System.Threading.Tasks;
using Sandbox;

namespace Editor.Mcp
{
	public static partial class SboxMcpAssistant
	{
		[McpTool( "pocketknife_ui_interact" )]
		public static async Task<string> UiInteract(
			[Description( "CSS selector (e.g. '.mainmenu button.start') or numeric index path ('0/1/2')" )] string selector,
			[Description( "Action: click, mousedown, mouseup, hover, type" )] string action = "click",
			[Description( "Text value when action is type" )] string? value = null,
			[Description( "Mouse button: left, right, middle" )] string button = "left" )
		{
			try
			{
				var result = await SyntheticUiDriver.InteractAsync( selector, action, value, button );
				return McpJson.Write( result );
			}
			catch ( Exception ex )
			{
				return McpJson.Write( ToolOutcome<object>.Failure( null, ToolStatus.Failed, "ui.interact_exception", "UI interaction failed.", ex ) );
			}
		}
	}
}