diff --git a/MCPForUnity/Editor/Helpers/CodexConfigHelper.cs b/MCPForUnity/Editor/Helpers/CodexConfigHelper.cs index 45ae5a39e..4ed1b8811 100644 --- a/MCPForUnity/Editor/Helpers/CodexConfigHelper.cs +++ b/MCPForUnity/Editor/Helpers/CodexConfigHelper.cs @@ -36,7 +36,7 @@ public static string BuildCodexServerBlock(string uvPath) if (useHttpTransport) { // HTTP mode: Use url field - string httpUrl = HttpEndpointUtility.GetMcpRpcUrl(); + string httpUrl = GetCodexHttpUrl(); unityMCP["url"] = new TomlString { Value = httpUrl }; // Enable Codex's Rust MCP client for HTTP/SSE transport @@ -191,7 +191,7 @@ private static TomlTable CreateUnityMcpTable(string uvPath) if (useHttpTransport) { // HTTP mode: Use url field - string httpUrl = HttpEndpointUtility.GetMcpRpcUrl(); + string httpUrl = GetCodexHttpUrl(); unityMCP["url"] = new TomlString { Value = httpUrl }; } else @@ -229,6 +229,17 @@ private static TomlTable CreateUnityMcpTable(string uvPath) return unityMCP; } + private static string GetCodexHttpUrl() + { + // Codex has intermittently failed the MCP handshake when configured with hostname-based + // loopback URLs such as localhost/::1, even though Unity MCP itself is reachable. + // Keep normalizing loopback hosts to 127.0.0.1 for Codex until the client routes them + // reliably again. If Codex fixes that behavior in the future, this is the workaround + // to revisit or remove before changing shared endpoint generation. + return HttpEndpointUtility.GetMcpRpcUrl() + .Replace("http://localhost:", "http://127.0.0.1:"); + } + /// /// Ensures the features table contains the rmcp_client flag for HTTP/SSE transport. ///