using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; using MCPForUnity.Editor.Clients; using MCPForUnity.Editor.Constants; using MCPForUnity.Editor.Helpers; using MCPForUnity.Editor.Models; using MCPForUnity.Editor.Services; using UnityEditor; using UnityEngine; using UnityEngine.UIElements; namespace MCPForUnity.Editor.Windows.Components.ClientConfig { /// /// Controller for the Client Configuration section of the MCP For Unity editor window. /// Handles client selection, configuration, status display, and manual configuration details. /// public class McpClientConfigSection { // UI Elements private DropdownField clientDropdown; private Button configureAllButton; private VisualElement clientStatusIndicator; private Label clientStatusLabel; private Button configureButton; private VisualElement claudeCliPathRow; private TextField claudeCliPath; private Button browseClaudeButton; private Foldout manualConfigFoldout; private TextField configPathField; private Button copyPathButton; private Button openFileButton; private TextField configJsonField; private Button copyJsonButton; private Label installationStepsLabel; // Data private readonly List configurators; private readonly Dictionary lastStatusChecks = new(); private readonly HashSet statusRefreshInFlight = new(); private static readonly TimeSpan StatusRefreshInterval = TimeSpan.FromSeconds(45); private int selectedClientIndex = 0; // Events /// /// Fired when the selected client's configured transport is detected/updated. /// The parameter contains the client name and its configured transport. /// public event Action OnClientTransportDetected; /// /// Fired when a config mismatch is detected (e.g., version mismatch). /// The parameter contains the client name and the mismatch message (null if no mismatch). /// public event Action OnClientConfigMismatch; public VisualElement Root { get; private set; } public McpClientConfigSection(VisualElement root) { Root = root; configurators = MCPServiceLocator.Client.GetAllClients().ToList(); CacheUIElements(); InitializeUI(); RegisterCallbacks(); } private void CacheUIElements() { clientDropdown = Root.Q("client-dropdown"); configureAllButton = Root.Q