Skip to content

Commit 92ff8ec

Browse files
committed
revert
1 parent 806f45a commit 92ff8ec

2 files changed

Lines changed: 10 additions & 36 deletions

File tree

src/databricks_ai_bridge/genie.py

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,9 @@ def __init__(
182182
self.genie = workspace_client.genie
183183
self.description = self.genie.get_space(space_id).description
184184

185-
# Store workspace client for lazy MCP client initialization
186-
self._workspace_client = workspace_client
187-
self._mcp_client = None # Lazy initialization
185+
# Initialize MCP client for communication with Genie backend
186+
server_url = f"{workspace_client.config.host}/api/2.0/mcp/genie/{space_id}"
187+
self._mcp_client = DatabricksMCPClient(server_url, workspace_client)
188188
self._tool_name = f"query_space_{space_id}"
189189

190190
# Keep headers for deprecated REST methods (backwards compatibility)
@@ -393,20 +393,6 @@ def poll_result():
393393

394394
return poll_result()
395395

396-
def _get_mcp_client(self):
397-
"""Lazy initialization of MCP client.
398-
399-
Creates the MCP client on first use to avoid issues with mocked
400-
workspace clients in tests and to defer initialization until needed.
401-
402-
Returns:
403-
DatabricksMCPClient: The initialized MCP client
404-
"""
405-
if self._mcp_client is None:
406-
server_url = f"{self._workspace_client.config.host}/api/2.0/mcp/genie/{self.space_id}"
407-
self._mcp_client = DatabricksMCPClient(server_url, self._workspace_client)
408-
return self._mcp_client
409-
410396
@mlflow.trace()
411397
def ask_question(self, question, conversation_id: Optional[str] = None):
412398
"""Ask a question to the Genie space using MCP protocol.
@@ -422,7 +408,7 @@ def ask_question(self, question, conversation_id: Optional[str] = None):
422408
if conversation_id:
423409
args["conversation_id"] = conversation_id
424410

425-
mcp_result = self._get_mcp_client().call_tool(self._tool_name, args)
411+
mcp_result = self._mcp_client.call_tool(self._tool_name, args)
426412

427413
if not mcp_result.content or len(mcp_result.content) == 0:
428414
return GenieResponse(

tests/databricks_ai_bridge/test_genie.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,7 @@ def test_ask_question(genie, mock_workspace_client):
131131
]
132132
)
133133

134-
mock_mcp_client = MagicMock()
135-
mock_mcp_client.call_tool.return_value = mock_mcp_result
136-
137-
with patch.object(genie, "_get_mcp_client", return_value=mock_mcp_client):
134+
with patch.object(genie._mcp_client, "call_tool", return_value=mock_mcp_result):
138135
genie_result = genie.ask_question("What is the meaning of life?")
139136
assert genie_result.result == "Answer"
140137
assert genie_result.conversation_id == "123"
@@ -150,10 +147,7 @@ def test_ask_question_continued_conversation(genie, mock_workspace_client):
150147
]
151148
)
152149

153-
mock_mcp_client = MagicMock()
154-
mock_mcp_client.call_tool.return_value = mock_mcp_result
155-
156-
with patch.object(genie, "_get_mcp_client", return_value=mock_mcp_client):
150+
with patch.object(genie._mcp_client, "call_tool", return_value=mock_mcp_result):
157151
genie_result = genie.ask_question("What is the meaning of life?", "123")
158152
assert genie_result.result == "42"
159153
assert genie_result.conversation_id == "123"
@@ -169,14 +163,11 @@ def test_ask_question_calls_mcp_without_conversation_id(genie, mock_workspace_cl
169163
]
170164
)
171165

172-
mock_mcp_client = MagicMock()
173-
mock_mcp_client.call_tool.return_value = mock_mcp_result
174-
175-
with patch.object(genie, "_get_mcp_client", return_value=mock_mcp_client):
166+
with patch.object(genie._mcp_client, "call_tool", return_value=mock_mcp_result) as mock_call:
176167
genie.ask_question("What is the meaning of life?")
177168

178169
# Verify MCP client was called with correct args (no conversation_id)
179-
mock_mcp_client.call_tool.assert_called_once_with(
170+
mock_call.assert_called_once_with(
180171
"query_space_test_space_id", {"query": "What is the meaning of life?"}
181172
)
182173

@@ -192,14 +183,11 @@ def test_ask_question_calls_mcp_with_conversation_id(genie, mock_workspace_clien
192183
]
193184
)
194185

195-
mock_mcp_client = MagicMock()
196-
mock_mcp_client.call_tool.return_value = mock_mcp_result
197-
198-
with patch.object(genie, "_get_mcp_client", return_value=mock_mcp_client):
186+
with patch.object(genie._mcp_client, "call_tool", return_value=mock_mcp_result) as mock_call:
199187
genie.ask_question("What is the meaning of life?", "123")
200188

201189
# Verify MCP client was called with conversation_id included
202-
mock_mcp_client.call_tool.assert_called_once_with(
190+
mock_call.assert_called_once_with(
203191
"query_space_test_space_id",
204192
{"query": "What is the meaning of life?", "conversation_id": "123"},
205193
)

0 commit comments

Comments
 (0)