using System;
using System.Threading.Tasks;
using MCPForUnity.Editor.Constants;
using MCPForUnity.Editor.Helpers;
using MCPForUnity.Editor.Services;
using MCPForUnity.Editor.Services.Transport;
using UnityEditor;
using UnityEditor.UIElements;
using UnityEngine;
using UnityEngine.UIElements;
namespace MCPForUnity.Editor.Windows.Components.Connection
{
///
/// Controller for the Connection section of the MCP For Unity editor window.
/// Handles transport protocol, HTTP/stdio configuration, connection status, and health checks.
///
public class McpConnectionSection
{
// Transport protocol enum
private enum TransportProtocol
{
HTTP,
Stdio
}
// UI Elements
private EnumField transportDropdown;
private VisualElement httpUrlRow;
private VisualElement httpServerCommandSection;
private TextField httpServerCommandField;
private Button copyHttpServerCommandButton;
private Label httpServerCommandHint;
private TextField httpUrlField;
private Button startHttpServerButton;
private Button stopHttpServerButton;
private VisualElement unitySocketPortRow;
private TextField unityPortField;
private VisualElement statusIndicator;
private Label connectionStatusLabel;
private Button connectionToggleButton;
private VisualElement healthIndicator;
private Label healthStatusLabel;
private Button testConnectionButton;
private bool connectionToggleInProgress;
// Events
public event Action OnManualConfigUpdateRequested;
public VisualElement Root { get; private set; }
public McpConnectionSection(VisualElement root)
{
Root = root;
CacheUIElements();
InitializeUI();
RegisterCallbacks();
}
private void CacheUIElements()
{
transportDropdown = Root.Q("transport-dropdown");
httpUrlRow = Root.Q("http-url-row");
httpServerCommandSection = Root.Q("http-server-command-section");
httpServerCommandField = Root.Q("http-server-command");
copyHttpServerCommandButton = Root.Q