Skip to content

Commit 3cf516b

Browse files
committed
Enable the rmcp_client feature so it works with Codex CLI
1 parent dbe5f33 commit 3cf516b

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

MCPForUnity/Editor/Helpers/CodexConfigHelper.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ public static string BuildCodexServerBlock(string uvPath)
2929
// HTTP mode: Use url field
3030
string httpUrl = HttpEndpointUtility.GetMcpRpcUrl();
3131
unityMCP["url"] = new TomlString { Value = httpUrl };
32+
33+
// Enable Codex's Rust MCP client for HTTP/SSE transport
34+
EnsureRmcpClientFeature(table);
3235
}
3336
else
3437
{
@@ -71,6 +74,8 @@ public static string UpsertCodexServerBlock(string existingToml, string uvPath)
7174
// Parse existing TOML or create new root table
7275
var root = TryParseToml(existingToml) ?? new TomlTable();
7376

77+
bool useHttpTransport = EditorPrefs.GetBool(MCPForUnity.Editor.Constants.EditorPrefKeys.UseHttpTransport, true);
78+
7479
// Ensure mcp_servers table exists
7580
if (!root.TryGetNode("mcp_servers", out var mcpServersNode) || !(mcpServersNode is TomlTable))
7681
{
@@ -81,6 +86,11 @@ public static string UpsertCodexServerBlock(string existingToml, string uvPath)
8186
// Create or update unityMCP table
8287
mcpServers["unityMCP"] = CreateUnityMcpTable(uvPath);
8388

89+
if (useHttpTransport)
90+
{
91+
EnsureRmcpClientFeature(root);
92+
}
93+
8494
// Serialize back to TOML
8595
using var writer = new StringWriter();
8696
root.WriteTo(writer);
@@ -200,6 +210,22 @@ private static TomlTable CreateUnityMcpTable(string uvPath)
200210
return unityMCP;
201211
}
202212

213+
/// <summary>
214+
/// Ensures the features table contains the rmcp_client flag for HTTP/SSE transport.
215+
/// </summary>
216+
private static void EnsureRmcpClientFeature(TomlTable root)
217+
{
218+
if (root == null) return;
219+
220+
if (!root.TryGetNode("features", out var featuresNode) || featuresNode is not TomlTable features)
221+
{
222+
features = new TomlTable();
223+
root["features"] = features;
224+
}
225+
226+
features["rmcp_client"] = new TomlBoolean { Value = true };
227+
}
228+
203229
private static bool TryGetTable(TomlTable parent, string key, out TomlTable table)
204230
{
205231
table = null;

TestProjects/UnityMCPTests/Assets/Tests/EditMode/Helpers/CodexConfigHelperTests.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,14 @@ public void BuildCodexServerBlock_HttpMode_GeneratesUrlField()
462462
Assert.IsInstanceOf<TomlTable>(unityMcpNode, "unityMCP should be a table");
463463

464464
var unityMcp = unityMcpNode as TomlTable;
465+
466+
// Verify features.rmcp_client is enabled for HTTP transport
467+
Assert.IsTrue(parsed.TryGetNode("features", out var featuresNode), "HTTP mode should include features table");
468+
Assert.IsInstanceOf<TomlTable>(featuresNode, "features should be a table");
469+
var features = featuresNode as TomlTable;
470+
Assert.IsTrue(features.TryGetNode("rmcp_client", out var rmcpNode), "features should include rmcp_client flag");
471+
Assert.IsInstanceOf<TomlBoolean>(rmcpNode, "rmcp_client should be a boolean");
472+
Assert.IsTrue((rmcpNode as TomlBoolean).Value, "rmcp_client should be true");
465473

466474
// Verify url field is present
467475
Assert.IsTrue(unityMcp.TryGetNode("url", out var urlNode), "unityMCP should contain url in HTTP mode");
@@ -536,6 +544,14 @@ public void UpsertCodexServerBlock_HttpMode_GeneratesUrlField()
536544

537545
var unityMcp = unityMcpNode as TomlTable;
538546

547+
// Verify features.rmcp_client is enabled for HTTP transport
548+
Assert.IsTrue(parsed.TryGetNode("features", out var featuresNode), "HTTP mode should include features table");
549+
Assert.IsInstanceOf<TomlTable>(featuresNode, "features should be a table");
550+
var features = featuresNode as TomlTable;
551+
Assert.IsTrue(features.TryGetNode("rmcp_client", out var rmcpNode), "features should include rmcp_client flag");
552+
Assert.IsInstanceOf<TomlBoolean>(rmcpNode, "rmcp_client should be a boolean");
553+
Assert.IsTrue((rmcpNode as TomlBoolean).Value, "rmcp_client should be true");
554+
539555
// Verify url field is present
540556
Assert.IsTrue(unityMcp.TryGetNode("url", out var urlNode), "unityMCP should contain url in HTTP mode");
541557
Assert.IsInstanceOf<TomlString>(urlNode, "url should be a string");

0 commit comments

Comments
 (0)