From 0eed62e32d83e3d87dbaa91b9a45ad84c4cad4b5 Mon Sep 17 00:00:00 2001 From: Andy Xu Date: Thu, 19 Nov 2026 23:57:11 +0000 Subject: [PATCH] fix(codex): forward auth environment for manually added MCP servers Use the existing Codex config writer and auth-name allowlist for stdio registration. Preserve unrelated config and avoid persisting credential values. --- src/ucode/mcp.py | 4 ++-- tests/README.md | 4 +++- tests/integration/README.md | 4 ++++ tests/test_mcp.py | 39 +++++++++++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/src/ucode/mcp.py b/src/ucode/mcp.py index 9a594f39a..5b866a363 100644 --- a/src/ucode/mcp.py +++ b/src/ucode/mcp.py @@ -487,8 +487,8 @@ def configure_client_mcp_server( claude.add_claude_mcp_server(name, argv, MCP_USER_SCOPE, always_load=always_load) return removed_scopes if client == "codex": - removed = remove_codex_mcp_server(name) - add_codex_mcp_server(name, argv) + # Codex filters subprocess env; forward auth names without persisting their values. + removed = codex.write_user_mcp_servers({name: codex.managed_mcp_entry(argv)}, {name}) return [MCP_USER_SCOPE] if removed else [] if client == "gemini": removed = remove_gemini_mcp_server(name) diff --git a/tests/README.md b/tests/README.md index d6c443825..6f9adf4e7 100644 --- a/tests/README.md +++ b/tests/README.md @@ -333,7 +333,9 @@ unit checks mock the sudo write. `integration/test_ug_configure_scope.py` covers `test_mcp.py` and `test_cli.py` cover Claude/Codex MCP setup without their CLIs: finding an existing config, creating one with `--agents`, and reporting status from the file. They also check malformed config errors and stale client choices. -They use temporary files; real desktop apps remain untested. +Codex stdio registration with the CLI installed also forwards authentication variable names, +never their values, while preserving personal settings and replacing obsolete transport fields. +These component checks use temporary files; native desktop coverage is listed below. `test_integration_contract.py` checks that isolated test sessions set Antigravity's `AGY_CLI_DISABLE_AUTO_UPDATE` to the required literal `true`, overriding an inherited `1`. diff --git a/tests/integration/README.md b/tests/integration/README.md index a57a855f7..a8e87ae41 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -365,6 +365,10 @@ accessibility tree captured before the fatal error in command evidence. Automation: each screen gets 60 seconds and the answer four minutes, with no retries, and it saves a screenshot of the app window as evidence. It also requires the app's model picker to list only the managed model, under its readable name (`5.6 Sol`) rather than the raw id. +`../test_mcp.py` checks that Codex stdio registration forwards authentication environment names +without persisting credentials, including with the CLI installed, and preserves unrelated config. +Those are component checks, not native MCP startup proof. + `scripts/run_integration.py` ignores both modules unless `--desktop-app` is passed, which only the desktop CI jobs do, so a local run never drives a developer's installed app. diff --git a/tests/test_mcp.py b/tests/test_mcp.py index f562530e6..ae0168b25 100644 --- a/tests/test_mcp.py +++ b/tests/test_mcp.py @@ -5,6 +5,7 @@ import json import re import threading +import tomllib from unittest.mock import MagicMock import pytest @@ -201,6 +202,44 @@ def test_saved_client_without_cli_or_config_needs_explicit_selection(self, monke class TestAddCodexMcpServer: + def test_registration_forwards_auth_names_without_persisting_credentials( + self, tmp_path, monkeypatch + ): + path = tmp_path / "config.toml" + path.write_text( + 'model = "personal-model"\n[mcp_servers.personal]\ncommand = "personal-tool"\n' + '[mcp_servers.github]\nurl = "https://old.example/mcp"\n' + ) + monkeypatch.setattr(mcp.codex, "user_mcp_config_path", lambda: path) + monkeypatch.setattr(mcp.shutil, "which", lambda binary: f"/tools/{binary}") + monkeypatch.setattr(mcp, "_oauth_http_client", lambda *a, **kw: None) + monkeypatch.setenv("DATABRICKS_BEARER", "secret-bearer-value") + monkeypatch.setenv("DATABRICKS_BEARER_COMMAND", "secret-command-value") + monkeypatch.setenv("DATABRICKS_CONFIG_FILE", "private-config-path") + monkeypatch.setattr( + mcp.subprocess_cross_os, "run", lambda *a, **kw: MagicMock(returncode=0) + ) + + assert mcp.configure_client_mcp_server("codex", "github", GH_URL, WS, "p") == [ + mcp.MCP_USER_SCOPE + ] + + contents = path.read_text() + config = tomllib.loads(contents) + assert config["model"] == "personal-model" + assert config["mcp_servers"]["personal"] == {"command": "personal-tool"} + assert config["mcp_servers"]["github"] == { + "command": "/tools/ug", + "args": PROXY_TAIL, + "env_vars": [ + "DATABRICKS_BEARER", + "DATABRICKS_BEARER_COMMAND", + "DATABRICKS_CONFIG_FILE", + ], + } + for secret in ("secret-bearer-value", "secret-command-value", "private-config-path"): + assert secret not in contents + def test_registers_stdio_proxy_command(self, monkeypatch): calls: list[dict] = []