-
Notifications
You must be signed in to change notification settings - Fork 569
refactor: use Tommy TOML library directly for config file manipulation #328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Before discovering the Tommy library I tried to parse TOML files directly. Some of the methods lingered from that time, which were messing up configuration on Windows. Now we use Tommy more, it should work. Also consolodiated some code with fresh eyes
WalkthroughRefactors TOML configuration handling in CodexConfigHelper from manual string assembly to structured TOML table manipulation using the Tommy library. Updates the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes The refactoring involves logic changes to TOML table manipulation and a breaking API change to Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (2)
MCPForUnity/Editor/Helpers/CodexConfigHelper.cs (2)
42-50: Good move to structured TOML; align key naming and factor constants.Using Tommy tables eliminates fragile string ops. To avoid key typos and keep naming consistent with
UpsertCodexServerBlock, extract constants for"mcpServers","mcp_servers", and"unityMCP". Also consider building viaUpsertCodexServerBlock(string.Empty, uvPath, serverSrc)to keep logic centralized.
125-141: Validate inputs to avoid null TOML values.If
serverSrc(oruvPath) is null/empty,TomlString.Valuemay serialize unexpectedly or throw under some lib versions. Add guards or fail fast.Example:
private static TomlTable CreateUnityMcpTable(string uvPath, string serverSrc) { + if (string.IsNullOrWhiteSpace(uvPath)) throw new ArgumentException("uvPath is required", nameof(uvPath)); + if (string.IsNullOrWhiteSpace(serverSrc)) throw new ArgumentException("serverSrc is required", nameof(serverSrc)); var unityMCP = new TomlTable(); unityMCP["command"] = new TomlString { Value = uvPath }; var argsArray = new TomlArray(); argsArray.Add(new TomlString { Value = "run" }); argsArray.Add(new TomlString { Value = "--directory" }); argsArray.Add(new TomlString { Value = serverSrc }); argsArray.Add(new TomlString { Value = "server.py" }); unityMCP["args"] = argsArray; return unityMCP; }Double‑check that
McpConfigFileHelper.ResolveServerDirectory(...)always returns a non‑empty path across platforms. If not guaranteed, we should compute a safe default upstream and avoid throwing here.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
MCPForUnity/Editor/Helpers/CodexConfigHelper.cs(1 hunks)MCPForUnity/Editor/Helpers/McpConfigurationHelper.cs(1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
MCPForUnity/Editor/Helpers/McpConfigurationHelper.cs (1)
MCPForUnity/Editor/Helpers/CodexConfigHelper.cs (2)
CodexConfigHelper(14-210)UpsertCodexServerBlock(53-72)
🔇 Additional comments (4)
MCPForUnity/Editor/Helpers/CodexConfigHelper.cs (3)
74-97: Robust parser: good coverage of both key styles.Parsing checks both
"mcp_servers"and"mcpServers"and safely handles arrays/singletons for args. LGTM.
99-123: Safe TOML parse path.Gracefully returns null on parse errors without throwing. Solid.
53-72: Use canonicalmcp_serverskey consistently; respect existing keys to avoid config pollution.Per Codex CLI documentation, the canonical key is
mcp_servers(notmcpServers). The current code is correct in using that key, but the risk is real: if a user's config already contains a legacy[mcpServers]section,UpsertCodexServerBlockwill leave both keys present, causing config pollution.The codebase already handles reading from both keys (lines 82–83), which is defensive. However,
UpsertCodexServerBlockshould either:
- Option 1: Detect and update the existing key (prefer
mcp_serversif both exist), as in the suggested diff.- Option 2: Normalize to the canonical
mcp_serversand optionally remove legacymcpServersentries on update.Option 1 aligns with the preference-respecting logic in
UnityMcpBridge/Editor/Helpers/CodexConfigHelper.cs(lines 134–145). If adopting that pattern, apply the suggested diff; otherwise, add a comment explaining the normalization strategy.MCPForUnity/Editor/Helpers/McpConfigurationHelper.cs (1)
208-208: Code asymmetry present but practical risk is lower; Codex CLI consumes onlymcp_servers.The Codex CLI expects the top-level key
mcp_servers(snake_case) in the config file. The currentUpsertCodexServerBlockimplementation reads from both"mcp_servers"and"mcpServers"(lines 82–83) but only writes to"mcp_servers". While this is asymmetric, there's no evidence the CLI accepts the camelCase variant, so the practical risk of configs being ignored is mitigated. However, if both keys exist in a TOML file, the"mcpServers"entry will not be updated, leaving stale data. Consider adopting the casing-preference logic found inUnityMcpBridge/Editor/Helpers/CodexConfigHelper.cs(lines 135–145) to detect and preserve the existing key style, avoiding duplication.
Before discovering the Tommy library I tried to parse TOML files directly. Some of the methods lingered from that time, which were messing up configuration on Windows.
Now we use Tommy more, it should work. Also consolodiated some code with fresh eyes
Summary by CodeRabbit