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
26 changes: 26 additions & 0 deletions MCPForUnity/Editor/Helpers/CodexConfigHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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))
{
Expand All @@ -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);
Expand Down Expand Up @@ -200,6 +210,22 @@ private static TomlTable CreateUnityMcpTable(string uvPath)
return unityMCP;
}

/// <summary>
/// Ensures the features table contains the rmcp_client flag for HTTP/SSE transport.
/// </summary>
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,14 @@ public void BuildCodexServerBlock_HttpMode_GeneratesUrlField()
Assert.IsInstanceOf<TomlTable>(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<TomlTable>(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<TomlBoolean>(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");
Expand Down Expand Up @@ -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<TomlTable>(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<TomlBoolean>(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<TomlString>(urlNode, "url should be a string");
Expand Down