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
12 changes: 11 additions & 1 deletion scripts/install_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,18 @@ def _codex_config_path(config_root: Path) -> Path:
) / "config.toml"


def _codex_cli_path() -> Optional[str]:
"""Resolve the usable Codex CLI, including the Desktop-provided path."""
desktop_cli = os.environ.get("CODEX_CLI_PATH")
if desktop_cli:
candidate = Path(desktop_cli).expanduser()
if candidate.is_file():
return str(candidate)
return shutil.which("codex")


def _install_codex(config_root: Path) -> None:
codex = shutil.which("codex")
codex = _codex_cli_path()
if codex is None:
raise InstallError("Codex CLI is not on PATH.")
_run_quiet([codex, "mcp", "remove", SERVER_NAME])
Expand Down
25 changes: 25 additions & 0 deletions test/test_install_mcp_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,28 @@ def test_codex_config_path_honors_codex_home(monkeypatch, tmp_path):
monkeypatch.setenv("CODEX_HOME", str(custom_home))

assert installer._codex_config_path(tmp_path) == custom_home / "config.toml"


def test_codex_cli_path_prefers_desktop_environment(monkeypatch, tmp_path):
installer = _load_installer()
desktop_cli = tmp_path / "codex.exe"
desktop_cli.touch()
monkeypatch.setenv("CODEX_CLI_PATH", str(desktop_cli))
monkeypatch.setattr(
installer.shutil,
"which",
lambda command: "C:/Program Files/WindowsApps/codex.exe",
)

assert installer._codex_cli_path() == str(desktop_cli)


def test_codex_cli_path_falls_back_to_path(monkeypatch, tmp_path):
installer = _load_installer()
monkeypatch.setenv(
"CODEX_CLI_PATH",
str(tmp_path / "missing-codex.exe"),
)
monkeypatch.setattr(installer.shutil, "which", lambda command: "codex")

assert installer._codex_cli_path() == "codex"
Loading