From 3cf516bbea985651a1bfc6df12b4f5c6076797c6 Mon Sep 17 00:00:00 2001 From: Marcus Sanatan Date: Tue, 25 Nov 2025 15:40:40 -0400 Subject: [PATCH] Enable the `rmcp_client` feature so it works with Codex CLI --- .../Editor/Helpers/CodexConfigHelper.cs | 26 +++++++++++++++++++ .../Helpers/CodexConfigHelperTests.cs | 16 ++++++++++++ 2 files changed, 42 insertions(+) diff --git a/MCPForUnity/Editor/Helpers/CodexConfigHelper.cs b/MCPForUnity/Editor/Helpers/CodexConfigHelper.cs index b4f786ee..786bc7f9 100644 --- a/MCPForUnity/Editor/Helpers/CodexConfigHelper.cs +++ b/MCPForUnity/Editor/Helpers/CodexConfigHelper.cs @@ -29,6 +29,9 @@ public static string BuildCodexServerBlock(string uvPath) // HTTP mode: Use url field string httpUrl = HttpEndpointUtility.GetMcpRpcUrl(); unityMCP["url"] = new TomlString { Value = httpUrl }; + + // Enable Codex's Rust MCP client for HTTP/SSE transport + EnsureRmcpClientFeature(table); } else { @@ -71,6 +74,8 @@ public static string UpsertCodexServerBlock(string existingToml, string uvPath) // Parse existing TOML or create new root table var root = TryParseToml(existingToml) ?? new TomlTable(); + bool useHttpTransport = EditorPrefs.GetBool(MCPForUnity.Editor.Constants.EditorPrefKeys.UseHttpTransport, true); + // Ensure mcp_servers table exists if (!root.TryGetNode("mcp_servers", out var mcpServersNode) || !(mcpServersNode is TomlTable)) { @@ -81,6 +86,11 @@ public static string UpsertCodexServerBlock(string existingToml, string uvPath) // Create or update unityMCP table mcpServers["unityMCP"] = CreateUnityMcpTable(uvPath); + if (useHttpTransport) + { + EnsureRmcpClientFeature(root); + } + // Serialize back to TOML using var writer = new StringWriter(); root.WriteTo(writer); @@ -200,6 +210,22 @@ private static TomlTable CreateUnityMcpTable(string uvPath) return unityMCP; } + /// + /// Ensures the features table contains the rmcp_client flag for HTTP/SSE transport. + /// + private static void EnsureRmcpClientFeature(TomlTable root) + { + if (root == null) return; + + if (!root.TryGetNode("features", out var featuresNode) || featuresNode is not TomlTable features) + { + features = new TomlTable(); + root["features"] = features; + } + + features["rmcp_client"] = new TomlBoolean { Value = true }; + } + private static bool TryGetTable(TomlTable parent, string key, out TomlTable table) { table = null; diff --git a/TestProjects/UnityMCPTests/Assets/Tests/EditMode/Helpers/CodexConfigHelperTests.cs b/TestProjects/UnityMCPTests/Assets/Tests/EditMode/Helpers/CodexConfigHelperTests.cs index 92f85866..a186e115 100644 --- a/TestProjects/UnityMCPTests/Assets/Tests/EditMode/Helpers/CodexConfigHelperTests.cs +++ b/TestProjects/UnityMCPTests/Assets/Tests/EditMode/Helpers/CodexConfigHelperTests.cs @@ -462,6 +462,14 @@ public void BuildCodexServerBlock_HttpMode_GeneratesUrlField() Assert.IsInstanceOf(unityMcpNode, "unityMCP should be a table"); var unityMcp = unityMcpNode as TomlTable; + + // Verify features.rmcp_client is enabled for HTTP transport + Assert.IsTrue(parsed.TryGetNode("features", out var featuresNode), "HTTP mode should include features table"); + Assert.IsInstanceOf(featuresNode, "features should be a table"); + var features = featuresNode as TomlTable; + Assert.IsTrue(features.TryGetNode("rmcp_client", out var rmcpNode), "features should include rmcp_client flag"); + Assert.IsInstanceOf(rmcpNode, "rmcp_client should be a boolean"); + Assert.IsTrue((rmcpNode as TomlBoolean).Value, "rmcp_client should be true"); // Verify url field is present Assert.IsTrue(unityMcp.TryGetNode("url", out var urlNode), "unityMCP should contain url in HTTP mode"); @@ -536,6 +544,14 @@ public void UpsertCodexServerBlock_HttpMode_GeneratesUrlField() var unityMcp = unityMcpNode as TomlTable; + // Verify features.rmcp_client is enabled for HTTP transport + Assert.IsTrue(parsed.TryGetNode("features", out var featuresNode), "HTTP mode should include features table"); + Assert.IsInstanceOf(featuresNode, "features should be a table"); + var features = featuresNode as TomlTable; + Assert.IsTrue(features.TryGetNode("rmcp_client", out var rmcpNode), "features should include rmcp_client flag"); + Assert.IsInstanceOf(rmcpNode, "rmcp_client should be a boolean"); + Assert.IsTrue((rmcpNode as TomlBoolean).Value, "rmcp_client should be true"); + // Verify url field is present Assert.IsTrue(unityMcp.TryGetNode("url", out var urlNode), "unityMCP should contain url in HTTP mode"); Assert.IsInstanceOf(urlNode, "url should be a string");