Skip to content

Commit a7e6822

Browse files
committed
fix: handle TOML inline comments in section headers during parsing
1 parent 345c06a commit a7e6822

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,22 @@ public void TryParseCodexServer_MultiLineArgsWithComments_IgnoresComments()
6565
Assert.AreEqual("uv", command);
6666
CollectionAssert.AreEqual(new[] { "run", "--directory", "/abs/path", "server.py" }, args);
6767
}
68+
69+
[Test]
70+
public void TryParseCodexServer_HeaderWithComment_StillDetected()
71+
{
72+
string toml = string.Join("\n", new[]
73+
{
74+
"[mcp_servers.unityMCP] # annotated header",
75+
"command = \"uv\"",
76+
"args = [\"run\", \"--directory\", \"/abs/path\", \"server.py\"]"
77+
});
78+
79+
bool result = CodexConfigHelper.TryParseCodexServer(toml, out string command, out string[] args);
80+
81+
Assert.IsTrue(result, "Parser should recognize section headers even with inline comments");
82+
Assert.AreEqual("uv", command);
83+
CollectionAssert.AreEqual(new[] { "run", "--directory", "/abs/path", "server.py" }, args);
84+
}
6885
}
6986
}
70-

UnityMcpBridge/Editor/Helpers/CodexConfigHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ public static bool TryParseCodexServer(string toml, out string command, out stri
114114
string trimmed = line.Trim();
115115
if (string.IsNullOrEmpty(trimmed) || trimmed.StartsWith("#")) continue;
116116

117-
bool isSection = trimmed.StartsWith("[") && trimmed.EndsWith("]") && !trimmed.StartsWith("[[");
117+
string headerCandidate = StripTomlComment(trimmed).Trim();
118+
bool isSection = headerCandidate.StartsWith("[") && headerCandidate.EndsWith("]") && !headerCandidate.StartsWith("[[");
118119
if (isSection)
119120
{
120-
inTarget = string.Equals(trimmed, "[mcp_servers.unityMCP]", StringComparison.OrdinalIgnoreCase);
121+
inTarget = string.Equals(headerCandidate, "[mcp_servers.unityMCP]", StringComparison.OrdinalIgnoreCase);
121122
continue;
122123
}
123124

0 commit comments

Comments
 (0)