Skip to content

Fix Codex config detection scope#1214

Open
kpkhxlgy0 wants to merge 1 commit into
CoplayDev:betafrom
kpkhxlgy0:codex/codex-project-config-scope
Open

Fix Codex config detection scope#1214
kpkhxlgy0 wants to merge 1 commit into
CoplayDev:betafrom
kpkhxlgy0:codex/codex-project-config-scope

Conversation

@kpkhxlgy0

@kpkhxlgy0 kpkhxlgy0 commented Jun 21, 2026

Copy link
Copy Markdown

Summary

  • Check Codex project config before user config.
  • Avoid auto-writing Codex MCP config when UnityMCP is missing.
  • Add Codex TOML removal support for unregister.

Test Plan

  • git diff --check HEAD
  • Unity EditMode tests not run locally

Summary by CodeRabbit

  • New Features

    • Added support to unregister Codex clients from configuration
    • Expanded configuration to support both project-level and user-level locations
  • Improvements

    • Enhanced configuration status detection and verification logic
    • Optimized startup rewrite process to activate only when necessary

@coderabbitai

coderabbitai Bot commented Jun 21, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

CodexMcpConfigurator is refactored from a single config path to a two-location "candidate" model (project-local via EditorPrefs, user-level OS default). IsInstalled, CheckStatus, Configure, and a new Unregister all operate across candidate paths. A new RemoveCodexServerBlock TOML helper is added to CodexConfigHelper. StartupConfigRewrite.RunOnce is narrowed to rewrite only on VersionMismatch or IncorrectPath disk states.

Changes

Codex Multi-Path Config, Unregistration, and Startup Rewrite

Layer / File(s) Summary
Config path helpers and candidate enumeration
MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs
Adds GetProjectConfigPath() (EditorPrefs-backed), GetUserConfigPath() (OS default), GetPreferredWriteConfigPath(), GetCandidateConfigPaths() (deduplicating yield), PathsEqual() (normalized case-insensitive), and GetClientProjectDir() (EditorPrefs override or Application.dataPath parent).
TOML unityMCP block removal helper
MCPForUnity/Editor/Helpers/CodexConfigHelper.cs
Adds public RemoveCodexServerBlock that parses TOML, locates mcp_servers/mcpServers, delegates to private RemoveUnityMcpServer for case-insensitive unityMCP key deletion, and returns serialized result with out bool removed.
IsInstalled, CheckStatus, and CheckParsedCodexServer
MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs
IsInstalled checks parent-directory existence across all candidates. CheckStatus iterates candidates, sets MissingConfig when a file exists but nothing matches. New CheckParsedCodexServer resolves transport type, matches URL or stdio --from source with beta/stable mismatch detection, and auto-rewrites via McpConfigurationHelper.ConfigureCodexClient.
Configure write path and Unregister
MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs
Configure() writes to GetPreferredWriteConfigPath(). New Unregister() iterates candidate paths, calls CodexConfigHelper.RemoveCodexServerBlock, writes back updated TOML on removal, then sets status to NotConfigured.
Startup rewrite narrowed to drift states
MCPForUnity/Editor/Services/StartupConfigRewrite.cs
RunOnce performs an initial CheckStatus(attemptAutoRewrite: false) and only proceeds to a rewrite pass for VersionMismatch or IncorrectPath; XML doc updated to reflect drift-refresh semantics.

Sequence Diagram(s)

sequenceDiagram
  participant StartupConfigRewrite
  participant CodexMcpConfigurator
  participant CodexConfigHelper
  participant McpConfigurationHelper

  StartupConfigRewrite->>CodexMcpConfigurator: CheckStatus(attemptAutoRewrite: false)
  CodexMcpConfigurator->>CodexMcpConfigurator: GetCandidateConfigPaths()
  CodexMcpConfigurator-->>StartupConfigRewrite: diskStatus

  alt diskStatus is VersionMismatch or IncorrectPath
    StartupConfigRewrite->>CodexMcpConfigurator: CheckStatus(attemptAutoRewrite: true)
    CodexMcpConfigurator->>McpConfigurationHelper: ConfigureCodexClient(path, client)
    McpConfigurationHelper-->>CodexMcpConfigurator: result
    CodexMcpConfigurator-->>StartupConfigRewrite: updated status
  end

  Note over StartupConfigRewrite: Unregister flow (user-driven)
  StartupConfigRewrite->>CodexMcpConfigurator: Unregister()
  CodexMcpConfigurator->>CodexConfigHelper: RemoveCodexServerBlock(toml)
  CodexConfigHelper-->>CodexMcpConfigurator: updated TOML, removed=true
  CodexMcpConfigurator->>CodexMcpConfigurator: write updated TOML, set NotConfigured
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

  • CoplayDev/unity-mcp#375: Modifies CodexConfigHelper.cs with TOML server-block parsing/upsert logic that the new RemoveCodexServerBlock method directly complements.
  • CoplayDev/unity-mcp#671: Updates Codex/Claude status-validation logic with beta-aware --from/package-source mismatch detection, which this PR extends within CheckParsedCodexServer.
  • CoplayDev/unity-mcp#682: Refactors McpClientConfiguratorBase.cs status checking with beta-aware transport comparison and mismatch-driven auto-rewrite, the same pattern applied here to Codex.

Suggested reviewers

  • msanatan

Poem

🐇 Hop, hop — two paths to sniff, not one!
The project config or the user's home,
We check them all before we're done.
Remove that block when the client's gone,
And skip the rewrite if nothing's wrong.
✨ Two-path configs, fresh as morning dew —
This bunny's TOML dreams have all come true!

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete compared to the template. While it summarizes the three main changes, it lacks required sections including Type of Change, detailed Changes Made list, Compatibility/Package Source information (Unity version tested, package source, commit hash), and Testing checkboxes. Complete the PR description by adding: Type of Change selection, expanded Changes Made section, Compatibility details (Unity version, package source, commit hash), and Testing section with checked items or explanation of why not run.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Fix Codex config detection scope' directly relates to the main change: updating configuration detection logic to check project-level config before user-level config, which is a key part of the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs (1)

695-701: 💤 Low value

Consider extracting GetClientProjectDir() to the base class.

This method is nearly identical to ClaudeCliMcpConfigurator.GetClientProjectDir() (lines 724-730). Both use the same EditorPrefs override pattern with the same fallback.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs` around lines 695 -
701, The GetClientProjectDir() method exists as a duplicate in both the
McpClientConfiguratorBase class and the ClaudeCliMcpConfigurator class with
identical implementations using the same EditorPrefs override pattern. Remove
the duplicate GetClientProjectDir() method from ClaudeCliMcpConfigurator class
(around lines 724-730) and ensure the base class version in
McpClientConfiguratorBase is accessible to derived classes by making it
protected instead of private, so the derived class can inherit and use the same
implementation without duplication.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs`:
- Around line 695-701: The GetClientProjectDir() method exists as a duplicate in
both the McpClientConfiguratorBase class and the ClaudeCliMcpConfigurator class
with identical implementations using the same EditorPrefs override pattern.
Remove the duplicate GetClientProjectDir() method from ClaudeCliMcpConfigurator
class (around lines 724-730) and ensure the base class version in
McpClientConfiguratorBase is accessible to derived classes by making it
protected instead of private, so the derived class can inherit and use the same
implementation without duplication.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2a70fad1-8aad-4dae-a3e6-8695134c991a

📥 Commits

Reviewing files that changed from the base of the PR and between dccecd6 and 7345694.

📒 Files selected for processing (3)
  • MCPForUnity/Editor/Clients/McpClientConfiguratorBase.cs
  • MCPForUnity/Editor/Helpers/CodexConfigHelper.cs
  • MCPForUnity/Editor/Services/StartupConfigRewrite.cs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant