Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions MCPForUnity/Editor/Clients/IMcpClientConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ public interface IMcpClientConfigurator
/// <summary>Current status cached by the configurator.</summary>
McpStatus Status { get; }

/// <summary>
/// The transport type the client is currently configured for.
/// Returns Unknown if the client is not configured or the transport cannot be determined.
/// </summary>
ConfiguredTransport ConfiguredTransport { get; }

/// <summary>True if this client supports auto-configure.</summary>
bool SupportsAutoConfigure { get; }

Expand Down
72 changes: 72 additions & 0 deletions MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ protected McpClientConfiguratorBase(McpClient client)
public string Id => client.name.Replace(" ", "").ToLowerInvariant();
public virtual string DisplayName => client.name;
public McpStatus Status => client.status;
public ConfiguredTransport ConfiguredTransport => client.configuredTransport;
public virtual bool SupportsAutoConfigure => true;
public virtual string GetConfigureActionLabel() => "Configure";

Expand Down Expand Up @@ -94,6 +95,7 @@ public override McpStatus CheckStatus(bool attemptAutoRewrite = true)
if (!File.Exists(path))
{
client.SetStatus(McpStatus.NotConfigured);
client.configuredTransport = Models.ConfiguredTransport.Unknown;
return client.status;
}

Expand Down Expand Up @@ -135,16 +137,32 @@ public override McpStatus CheckStatus(bool attemptAutoRewrite = true)
if (standardConfig?.mcpServers?.unityMCP != null)
{
args = standardConfig.mcpServers.unityMCP.args;
configuredUrl = standardConfig.mcpServers.unityMCP.url;
configExists = true;
}
}

if (!configExists)
{
client.SetStatus(McpStatus.MissingConfig);
client.configuredTransport = Models.ConfiguredTransport.Unknown;
return client.status;
}

// Determine and set the configured transport type
if (args != null && args.Length > 0)
{
client.configuredTransport = Models.ConfiguredTransport.Stdio;
}
else if (!string.IsNullOrEmpty(configuredUrl))
{
client.configuredTransport = Models.ConfiguredTransport.Http;
}
else
{
client.configuredTransport = Models.ConfiguredTransport.Unknown;
}

bool matches = false;
if (args != null && args.Length > 0)
{
Expand All @@ -171,6 +189,9 @@ public override McpStatus CheckStatus(bool attemptAutoRewrite = true)
if (result == "Configured successfully")
{
client.SetStatus(McpStatus.Configured);
// Update transport after rewrite based on current server setting
bool useHttp = EditorPrefs.GetBool(EditorPrefKeys.UseHttpTransport, true);
client.configuredTransport = useHttp ? Models.ConfiguredTransport.Http : Models.ConfiguredTransport.Stdio;
}
else
{
Expand All @@ -185,6 +206,7 @@ public override McpStatus CheckStatus(bool attemptAutoRewrite = true)
catch (Exception ex)
{
client.SetStatus(McpStatus.Error, ex.Message);
client.configuredTransport = Models.ConfiguredTransport.Unknown;
}

return client.status;
Expand All @@ -198,6 +220,9 @@ public override void Configure()
if (result == "Configured successfully")
{
client.SetStatus(McpStatus.Configured);
// Set transport based on current server setting
bool useHttp = EditorPrefs.GetBool(EditorPrefKeys.UseHttpTransport, true);
client.configuredTransport = useHttp ? Models.ConfiguredTransport.Http : Models.ConfiguredTransport.Stdio;
}
else
{
Expand Down Expand Up @@ -237,12 +262,27 @@ public override McpStatus CheckStatus(bool attemptAutoRewrite = true)
if (!File.Exists(path))
{
client.SetStatus(McpStatus.NotConfigured);
client.configuredTransport = Models.ConfiguredTransport.Unknown;
return client.status;
}

string toml = File.ReadAllText(path);
if (CodexConfigHelper.TryParseCodexServer(toml, out _, out var args, out var url))
{
// Determine and set the configured transport type
if (!string.IsNullOrEmpty(url))
{
client.configuredTransport = Models.ConfiguredTransport.Http;
}
else if (args != null && args.Length > 0)
{
client.configuredTransport = Models.ConfiguredTransport.Stdio;
}
else
{
client.configuredTransport = Models.ConfiguredTransport.Unknown;
}

bool matches = false;
if (!string.IsNullOrEmpty(url))
{
Expand All @@ -262,13 +302,20 @@ public override McpStatus CheckStatus(bool attemptAutoRewrite = true)
return client.status;
}
}
else
{
client.configuredTransport = Models.ConfiguredTransport.Unknown;
}

if (attemptAutoRewrite)
{
string result = McpConfigurationHelper.ConfigureCodexClient(path, client);
if (result == "Configured successfully")
{
client.SetStatus(McpStatus.Configured);
// Update transport after rewrite based on current server setting
bool useHttp = EditorPrefs.GetBool(EditorPrefKeys.UseHttpTransport, true);
client.configuredTransport = useHttp ? Models.ConfiguredTransport.Http : Models.ConfiguredTransport.Stdio;
}
else
{
Expand All @@ -283,6 +330,7 @@ public override McpStatus CheckStatus(bool attemptAutoRewrite = true)
catch (Exception ex)
{
client.SetStatus(McpStatus.Error, ex.Message);
client.configuredTransport = Models.ConfiguredTransport.Unknown;
}

return client.status;
Expand All @@ -296,6 +344,9 @@ public override void Configure()
if (result == "Configured successfully")
{
client.SetStatus(McpStatus.Configured);
// Set transport based on current server setting
bool useHttp = EditorPrefs.GetBool(EditorPrefKeys.UseHttpTransport, true);
client.configuredTransport = useHttp ? Models.ConfiguredTransport.Http : Models.ConfiguredTransport.Stdio;
}
else
{
Expand Down Expand Up @@ -363,6 +414,7 @@ internal McpStatus CheckStatusWithProjectDir(string projectDir, bool useHttpTran
if (string.IsNullOrEmpty(claudePath))
{
client.SetStatus(McpStatus.NotConfigured, "Claude CLI not found");
client.configuredTransport = Models.ConfiguredTransport.Unknown;
return client.status;
}

Expand Down Expand Up @@ -415,6 +467,20 @@ internal McpStatus CheckStatusWithProjectDir(string projectDir, bool useHttpTran
bool registeredWithHttp = getStdout.Contains("Type: http", StringComparison.OrdinalIgnoreCase);
bool registeredWithStdio = getStdout.Contains("Type: stdio", StringComparison.OrdinalIgnoreCase);

// Set the configured transport based on what we detected
if (registeredWithHttp)
{
client.configuredTransport = Models.ConfiguredTransport.Http;
}
else if (registeredWithStdio)
{
client.configuredTransport = Models.ConfiguredTransport.Stdio;
}
else
{
client.configuredTransport = Models.ConfiguredTransport.Unknown;
}

// Check for transport mismatch
bool hasTransportMismatch = (currentUseHttp && registeredWithStdio) || (!currentUseHttp && registeredWithHttp);

Expand Down Expand Up @@ -479,10 +545,12 @@ internal McpStatus CheckStatusWithProjectDir(string projectDir, bool useHttpTran
}

client.SetStatus(McpStatus.NotConfigured);
client.configuredTransport = Models.ConfiguredTransport.Unknown;
}
catch (Exception ex)
{
client.SetStatus(McpStatus.Error, ex.Message);
client.configuredTransport = Models.ConfiguredTransport.Unknown;
}

return client.status;
Expand Down Expand Up @@ -558,6 +626,7 @@ private void RegisterWithCapturedValues(

McpLog.Info($"Successfully registered with Claude Code using {(useHttpTransport ? "HTTP" : "stdio")} transport.");
client.SetStatus(McpStatus.Configured);
client.configuredTransport = useHttpTransport ? Models.ConfiguredTransport.Http : Models.ConfiguredTransport.Stdio;
}

/// <summary>
Expand All @@ -577,6 +646,7 @@ private void UnregisterWithCapturedValues(string projectDir, string claudePath,

McpLog.Info("MCP server successfully unregistered from Claude Code.");
client.SetStatus(McpStatus.NotConfigured);
client.configuredTransport = Models.ConfiguredTransport.Unknown;
}

private void Register()
Expand Down Expand Up @@ -645,6 +715,7 @@ private void Register()
// Set status to Configured immediately after successful registration
// The UI will trigger an async verification check separately to avoid blocking
client.SetStatus(McpStatus.Configured);
client.configuredTransport = useHttpTransport ? Models.ConfiguredTransport.Http : Models.ConfiguredTransport.Stdio;
}

private void Unregister()
Expand Down Expand Up @@ -675,6 +746,7 @@ private void Unregister()

McpLog.Info("MCP server successfully unregistered from Claude Code.");
client.SetStatus(McpStatus.NotConfigured);
client.configuredTransport = Models.ConfiguredTransport.Unknown;
}

public override string GetManualSnippet()
Expand Down
14 changes: 14 additions & 0 deletions MCPForUnity/Editor/Constants/HealthStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace MCPForUnity.Editor.Constants
{
/// <summary>
/// Constants for health check status values.
/// Used for coordinating health state between Connection and Advanced sections.
/// </summary>
public static class HealthStatus
{
public const string Unknown = "Unknown";
public const string Healthy = "Healthy";
public const string PingFailed = "Ping Failed";
public const string Unhealthy = "Unhealthy";
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions MCPForUnity/Editor/Helpers/GameObjectLookup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,9 @@ public static GameObject FindByTarget(JToken target, string searchMethod, bool i
/// </summary>
public static GameObject FindById(int instanceId)
{
#pragma warning disable CS0618 // Type or member is obsolete
return EditorUtility.InstanceIDToObject(instanceId) as GameObject;
#pragma warning restore CS0618
}

/// <summary>
Expand Down Expand Up @@ -103,7 +105,9 @@ public static List<int> SearchGameObjects(SearchMethod method, string searchTerm
case SearchMethod.ById:
if (int.TryParse(searchTerm, out int instanceId))
{
#pragma warning disable CS0618 // Type or member is obsolete
var obj = EditorUtility.InstanceIDToObject(instanceId) as GameObject;
#pragma warning restore CS0618
if (obj != null && (includeInactive || obj.activeInHierarchy))
{
results.Add(instanceId);
Expand Down
4 changes: 4 additions & 0 deletions MCPForUnity/Editor/Models/MCPConfigServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ public class McpConfigServer
// VSCode expects a transport type; include only when explicitly set
[JsonProperty("type", NullValueHandling = NullValueHandling.Ignore)]
public string type;

// URL for HTTP transport mode
[JsonProperty("url", NullValueHandling = NullValueHandling.Ignore)]
public string url;
}
}
1 change: 1 addition & 0 deletions MCPForUnity/Editor/Models/McpClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class McpClient
public string linuxConfigPath;
public string configStatus;
public McpStatus status = McpStatus.NotConfigured;
public ConfiguredTransport configuredTransport = ConfiguredTransport.Unknown;

// Capability flags/config for JSON-based configurators
public bool IsVsCodeLayout; // Whether the config file follows VS Code layout (env object at root)
Expand Down
11 changes: 11 additions & 0 deletions MCPForUnity/Editor/Models/McpStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,16 @@ public enum McpStatus
UnsupportedOS, // OS is not supported
Error, // General error state
}

/// <summary>
/// Represents the transport type a client is configured to use.
/// Used to detect mismatches between server and client transport settings.
/// </summary>
public enum ConfiguredTransport
{
Unknown, // Could not determine transport type
Stdio, // Client configured for stdio transport
Http // Client configured for HTTP transport
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading