Editor tool method exposed to the MCP that opens the publish wizard or inspects publish metadata headlessly. It returns JSON tool outcomes, validates there is a loaded Project, optionally invokes an editor runtime static method to open Editor.Wizards.PublishWizard, and handles errors.
#nullable enable
using System;
using Sandbox;
namespace Editor.Mcp
{
public static partial class SboxMcpAssistant
{
[McpTool( "pocketknife_open_publish_wizard" )]
public static string OpenPublishWizard( [System.ComponentModel.Description( "Set to true only if you explicitly want to open the modal UI window in the editor. Defaults to false for safe headless inspection." )] bool launchInteractiveUi = false )
{
try
{
var project = Project.Current;
if ( project is null )
{
return McpJson.Write( ToolOutcome<object>.Failure( null, ToolStatus.Unavailable, "publish.no_active_project", "No active project is loaded in the editor." ) );
}
if ( !launchInteractiveUi )
{
return McpJson.Write( ToolOutcome<object>.Ready(
new
{
Project = project.Config.Ident,
ProjectTitle = project.Config.Title,
FullIdent = $"{project.Config.Org}.{project.Config.Ident}",
PackageType = project.Config.Type,
InteractiveUiLaunched = false,
HeadlessStatus = "Publish metadata inspected headlessly. To launch the interactive UI dialog, set launchInteractiveUi = true."
} ) );
}
var wizard = EditorRuntime.InvokeStatic( "Editor.Wizards.PublishWizard", "Open", project, null );
if ( wizard is null )
{
return McpJson.Write( ToolOutcome<object>.Failure( new { Project = project.Config.Ident, ProjectTitle = project.Config.Title }, ToolStatus.Unavailable, "publish.wizard_unavailable", "The loaded editor build does not expose Editor.Wizards.PublishWizard.Open." ) );
}
return McpJson.Write( ToolOutcome<object>.Degraded(
new { Project = project.Config.Ident, ProjectTitle = project.Config.Title, FullIdent = $"{project.Config.Org}.{project.Config.Ident}", WizardOpened = true },
"publish.requires_user_confirmation",
"The publish wizard is open. Account login, org selection, metadata review, and the final upload/publish confirmation must be completed in the editor UI." ) );
}
catch ( Exception ex )
{
return McpJson.Write( ToolOutcome<object>.Failure( null, ToolStatus.Failed, "publish.open_failed", "Opening the publish wizard failed.", ex ) );
}
}
}
}