Skip to content
Closed
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
6 changes: 5 additions & 1 deletion src/ucode/agents/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,11 @@ def managed_mcp_uses_managed_file() -> bool:

def managed_mcp_entry(argv: list[str]) -> dict:
"""A ``[mcp_servers.<name>]`` stdio entry from the ``ug mcp-proxy`` argv (same as user scope)."""
return {"command": argv[0], "args": list(argv[1:])}
return {
"command": argv[0],
"args": list(argv[1:]),
"env_vars": ["DATABRICKS_BEARER", "DATABRICKS_BEARER_COMMAND"],
}


def managed_mcp_http_entry(url: str, client_id: str) -> dict:
Expand Down
15 changes: 15 additions & 0 deletions tests/test_agent_codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -1929,6 +1929,10 @@ def test_writes_mcp_servers_preserving_model_keys(self, monkeypatch):
assert doc["model_provider"] == "Databricks"
assert doc["mcp_servers"]["system-ai-github"]["command"] == "/opt/ug"
assert doc["mcp_servers"]["system-ai-github"]["args"][:2] == ["mcp-proxy", "--url"]
assert doc["mcp_servers"]["system-ai-github"]["env_vars"] == [
"DATABRICKS_BEARER",
"DATABRICKS_BEARER_COMMAND",
]
assert captured["owned_paths"] == [["mcp_servers"]]
assert captured["tool"] == "codex"

Expand Down Expand Up @@ -2041,6 +2045,16 @@ def test_token_provider_uses_custom_oauth_when_configured(self, monkeypatch):
class TestWriteUserMcpServers:
"""Batched user-scope `[mcp_servers]` writes for the workspace-managed reconcile path."""

def test_passes_external_auth_by_name_without_persisting_credentials(self, monkeypatch):
monkeypatch.setenv("DATABRICKS_BEARER", "test-bearer-not-for-persistence")
monkeypatch.setenv("DATABRICKS_BEARER_COMMAND", "test-token-command")

assert codex.managed_mcp_entry(["ug", "mcp-proxy", "https://ws/svc"]) == {
"command": "ug",
"args": ["mcp-proxy", "https://ws/svc"],
"env_vars": ["DATABRICKS_BEARER", "DATABRICKS_BEARER_COMMAND"],
}

def test_adds_and_preserves_other_tables(self, tmp_path, monkeypatch):
path = tmp_path / "config.toml"
path.write_text('model = "gpt-5"\n\n[mcp_servers.mine]\ncommand = "x"\nargs = []\n')
Expand All @@ -2058,6 +2072,7 @@ def test_adds_and_preserves_other_tables(self, tmp_path, monkeypatch):
assert dict(doc["mcp_servers"]["system-ai-github"]) == {
"command": "ug",
"args": ["mcp-proxy", "https://ws/svc"],
"env_vars": ["DATABRICKS_BEARER", "DATABRICKS_BEARER_COMMAND"],
}

def test_removes_named_entries_only(self, tmp_path, monkeypatch):
Expand Down
Loading