Skip to content

fix(codex): forward auth environment for user MCP registrations - #1788

Open
andy-xu-db wants to merge 1 commit into
mainfrom
andy-xu_data/stack/andy/codex-mcp-auth-env
Open

andy-xu-db wants to merge 1 commit into
mainfrom
andy-xu_data/stack/andy/codex-mcp-auth-env

Conversation

@andy-xu-db

@andy-xu-db andy-xu-db commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

🥞 Stacked PR

Use this link to review incremental changes.


Summary

BEFORE: ug mcp add --agents codex registered stdio servers through codex mcp add without the authentication environment allowlist already used by managed Codex registration. Codex filters subprocess environments, so an MCP proxy depending on an exported bearer, bearer command or custom Databricks config path can lose its authentication context.

AFTER: reuse managed_mcp_entry and write_user_mcp_servers for per-server stdio registration. Forward DATABRICKS_BEARER, DATABRICKS_BEARER_COMMAND and DATABRICKS_CONFIG_FILE by name without saving their values. Preserve unrelated settings and servers, replace stale same-name transport fields, and retain removal reporting.

This fixes environment propagation for callers using exported authentication settings. #1757 now targets main independently and requires real Databricks CLI OAuth login before MCP registration; it no longer contains or depends on this fix. This change has not been established as necessary for an ordinary already-logged-in user.

Coverage

  • Regression test exercises the installed-CLI dispatch path with real temporary TOML files, replaces an HTTP entry with stdio, preserves a personal model/server, and rejects credential-value persistence.
  • Existing MCP/Codex component coverage checks missing CLI/config files, CODEX_HOME, malformed-config fallback, native HTTP OAuth registration, managed registration and removal.
  • The change is limited to Codex stdio registration. The generated proxy command, native HTTP OAuth registration and other agents keep their existing paths.

Validation

  • 556 passed in tests/test_mcp.py and tests/test_agent_codex.py on isolated base commit 0eed62e32d83e3d87dbaa91b9a45ad84c4cad4b5.
  • Ruff check/format and git diff --check: passed.
  • CI completed with failures in the Antigravity and CUJ3 integration lanes; the run is not all-green.
  • The earlier combined branch had the identical Git tree as e6152036, where both macOS desktop cases, both Windows desktop cases and the full Linux/Windows unit suites passed (run). Those historical results are from the combined bearer-authenticated change, not a standalone native run of this base PR or the new OAuth-login tests.

Limitations

The native desktop evidence uses an injected CI bearer, not an already-logged-in CLI user. The OAuth-login version of #1757 was tested without this change. Both native inference cases passed; both skill/MCP cases timed out in databricks auth login before MCP registration (run). MCP execution through an existing user login remains unverified. Results from the earlier bearer-authenticated runs do not establish logged-in-user coverage.

This replaces the installed Codex CLI registration subprocess with UG's existing config writer. Component tests reduce compatibility risk but do not establish compatibility with every historical Codex version or concurrent external config writers. An exported bearer now reaches manually registered servers and takes precedence over profile authentication, matching UG's existing token resolver; a stale or incorrect bearer must be cleared to use the profile. Existing entries require re-registration to gain the allowlist. Malformed TOML retains the existing CLI fallback and its limitations. No credential values or dependency changes are introduced.

Use the existing Codex config writer and auth-name allowlist for stdio registration. Preserve unrelated config and avoid persisting credential values.
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