From eb1b8be57738ff5d2a8a973c55416ac8c8056a3b Mon Sep 17 00:00:00 2001 From: Brandon Kvarda Date: Thu, 21 May 2026 15:27:30 -0700 Subject: [PATCH] Pass --profile to databricks CLI listing commands MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CLI v1.0.0 no longer resolves credentials from DATABRICKS_HOST alone — it requires an explicit --profile flag. list_databricks_connections, list_genie_spaces, and list_databricks_apps now call find_profile_name_for_host and append --profile when a match is found, matching the same pattern already used in get_databricks_token. Without this fix, ucode configure mcp silently skips external connections, Genie spaces, and Databricks apps with "Skipped" warnings. Co-authored-by: Isaac --- src/ucode/databricks.py | 28 +++++++++++++++++++--------- tests/test_databricks.py | 11 +++++++++++ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/src/ucode/databricks.py b/src/ucode/databricks.py index 0f82059..27c4575 100644 --- a/src/ucode/databricks.py +++ b/src/ucode/databricks.py @@ -380,6 +380,7 @@ def _extract_connection_page(payload: object) -> tuple[list[dict], str | None]: def list_databricks_connections(workspace: str) -> list[dict]: env = build_databricks_cli_env(workspace) + profile_name = find_profile_name_for_host(workspace) connections: list[dict] = [] page_token: str | None = None seen_page_tokens: set[str] = set() @@ -395,6 +396,8 @@ def list_databricks_connections(workspace: str) -> list[dict]: "--output", "json", ] + if profile_name: + cmd.extend(["--profile", profile_name]) if page_token: cmd.extend(["--page-token", page_token]) @@ -442,6 +445,7 @@ def _extract_genie_spaces_page(payload: object) -> tuple[list[dict], str | None] def list_genie_spaces(workspace: str) -> list[dict]: env = build_databricks_cli_env(workspace) + profile_name = find_profile_name_for_host(workspace) spaces: list[dict] = [] page_token: str | None = None seen_page_tokens: set[str] = set() @@ -457,6 +461,8 @@ def list_genie_spaces(workspace: str) -> list[dict]: "--output", "json", ] + if profile_name: + cmd.extend(["--profile", profile_name]) if page_token: cmd.extend(["--page-token", page_token]) @@ -501,17 +507,21 @@ def _extract_apps_payload(payload: object) -> list[dict]: def list_databricks_apps(workspace: str) -> list[dict]: env = build_databricks_cli_env(workspace) + profile_name = find_profile_name_for_host(workspace) + cmd = [ + "databricks", + "apps", + "list", + "--limit", + "1000", + "--output", + "json", + ] + if profile_name: + cmd.extend(["--profile", profile_name]) try: result = run( - [ - "databricks", - "apps", - "list", - "--limit", - "1000", - "--output", - "json", - ], + cmd, capture_output=True, text=True, env=env, diff --git a/tests/test_databricks.py b/tests/test_databricks.py index 1c21e70..2d3d10f 100644 --- a/tests/test_databricks.py +++ b/tests/test_databricks.py @@ -206,6 +206,7 @@ def fake_run(args, **kwargs): return subprocess.CompletedProcess(args, 0, stdout=json.dumps(payload)) monkeypatch.setattr(db_mod, "run", fake_run) + monkeypatch.setattr(db_mod, "find_profile_name_for_host", lambda ws: "test-profile") assert list_databricks_connections(WS) == [ {"name": "confluence-mcp", "connection_type": "HTTP"}, @@ -219,6 +220,8 @@ def fake_run(args, **kwargs): "0", "--output", "json", + "--profile", + "test-profile", ] assert calls[0]["kwargs"]["env"]["DATABRICKS_HOST"] == WS assert calls[1]["args"][-2:] == ["--page-token", "next-page"] @@ -228,6 +231,7 @@ def fake_run(args, **kwargs): return subprocess.CompletedProcess(args, 0, stdout="not-json") monkeypatch.setattr(db_mod, "run", fake_run) + monkeypatch.setattr(db_mod, "find_profile_name_for_host", lambda ws: None) with pytest.raises(RuntimeError, match="invalid JSON"): list_databricks_connections(WS) @@ -249,6 +253,7 @@ def fake_run(args, **kwargs): return subprocess.CompletedProcess(args, 0, stdout=json.dumps(payload)) monkeypatch.setattr(db_mod, "run", fake_run) + monkeypatch.setattr(db_mod, "find_profile_name_for_host", lambda ws: "test-profile") assert list_genie_spaces(WS) == [ {"space_id": "space-1", "title": "First"}, @@ -262,6 +267,8 @@ def fake_run(args, **kwargs): "100", "--output", "json", + "--profile", + "test-profile", ] assert calls[0]["kwargs"]["env"]["DATABRICKS_HOST"] == WS assert calls[1]["args"][-2:] == ["--page-token", "next-page"] @@ -271,6 +278,7 @@ def fake_run(args, **kwargs): return subprocess.CompletedProcess(args, 0, stdout="not-json") monkeypatch.setattr(db_mod, "run", fake_run) + monkeypatch.setattr(db_mod, "find_profile_name_for_host", lambda ws: None) with pytest.raises(RuntimeError, match="invalid JSON"): list_genie_spaces(WS) @@ -291,6 +299,7 @@ def fake_run(args, **kwargs): return subprocess.CompletedProcess(args, 0, stdout=json.dumps(payload)) monkeypatch.setattr(db_mod, "run", fake_run) + monkeypatch.setattr(db_mod, "find_profile_name_for_host", lambda ws: "test-profile") assert list_databricks_apps(WS) == [ { @@ -306,6 +315,8 @@ def fake_run(args, **kwargs): "1000", "--output", "json", + "--profile", + "test-profile", ] assert calls[0]["kwargs"]["env"]["DATABRICKS_HOST"] == WS