Skip to content

Commit 1eb4b76

Browse files
committed
Refactor MCP and non-MCP connects in Dash
1 parent 0b1409b commit 1eb4b76

File tree

4 files changed

+46
-40
lines changed

4 files changed

+46
-40
lines changed

dash/pages/external_connections.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def layout():
8181
dbc.CardBody([
8282
dbc.Row([
8383
dbc.Col([
84-
dbc.Label("Connection Name", className="form-label"),
84+
dbc.Label("Unity Catalog Connection name:", className="form-label"),
8585
dcc.Input(
8686
id="connection-select",
8787
placeholder="Enter connection name...",
@@ -91,7 +91,7 @@ def layout():
9191
]),
9292
dbc.Row([
9393
dbc.Col([
94-
dbc.Label("Auth Type", className="form-label"),
94+
dbc.Label("Authentication mode:", className="form-label"),
9595
dcc.Dropdown(
9696
id="auth-type-select",
9797
options=[
@@ -104,7 +104,7 @@ def layout():
104104
)
105105
], md=6),
106106
dbc.Col([
107-
dbc.Label("HTTP Method", className="form-label"),
107+
dbc.Label("HTTP method:", className="form-label"),
108108
dcc.Dropdown(
109109
id="method-select",
110110
options=[
@@ -118,7 +118,7 @@ def layout():
118118
]),
119119
dbc.Row([
120120
dbc.Col([
121-
html.Label("Path", className="form-label"),
121+
html.Label("Path:", className="form-label"),
122122
dcc.Input(
123123
id="path-input",
124124
type="text",
@@ -128,7 +128,7 @@ def layout():
128128
], md=6),
129129
# Request Body (JSON)
130130
dbc.Col([
131-
dbc.Label("JSON", className="form-label"),
131+
dbc.Label("Request data:", className="form-label"),
132132
dcc.Textarea(
133133
id="body-input",
134134
placeholder='{"key": "value"}',
@@ -139,7 +139,7 @@ def layout():
139139
]),
140140
dbc.Row([
141141
dbc.Col([
142-
html.Label("Headers", className="form-label"),
142+
html.Label("Request headers:", className="form-label"),
143143
dcc.Textarea(
144144
id="headers-input",
145145
placeholder='{"Content-Type": "application/json"}',
@@ -307,6 +307,8 @@ def send_external_request(n_clicks, connection, method, path, headers, body, aut
307307
if not all([connection, method]):
308308
return html.Div([html.P("Please fill in all required fields: Connection and Method", className="text-danger")])
309309

310+
connection = connection.replace(" ", "")
311+
310312
try:
311313
# Parse headers JSON
312314
headers_dict = {}

dash/pages/mcp_connect.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def layout():
113113
dbc.CardBody([
114114
dbc.Row([
115115
dbc.Col([
116-
dbc.Label("Unity Catalog Connection name", className="form-label"),
116+
dbc.Label("Unity Catalog Connection name:", className="form-label"),
117117
dcc.Input(
118118
id="connection-mcp-select",
119119
placeholder="Enter HTTP connection name...",
@@ -123,20 +123,20 @@ def layout():
123123
]),
124124
dbc.Row([
125125
dbc.Col([
126-
dbc.Label("Auth Type", className="form-label"),
126+
dbc.Label("Authentication mode:", className="form-label"),
127127
dcc.Dropdown(
128128
id="auth-type-mcp-select",
129129
options=[
130130
{"label": "Bearer token", "value": "bearer_token"},
131131
{"label": "OAuth User to Machine Per User", "value": "oauth_user_machine_per_user"},
132132
{"label": "OAuth Machine to Machine", "value": "oauth_machine_machine"}
133133
],
134-
value="bearer_token",
134+
value="oauth_user_machine_per_user",
135135
className="mb-2"
136136
)
137137
], md=6),
138138
dbc.Col([
139-
dbc.Label("HTTP Method", className="form-label"),
139+
dbc.Label("HTTP method:", className="form-label"),
140140
dcc.Dropdown(
141141
id="method-mcp-select",
142142
options=[
@@ -351,6 +351,8 @@ def send_external_request(n_clicks, connection, method, body, auth_type):
351351
if not all([connection, method]):
352352
return html.Div([html.P("Please fill in all required fields: Connection and Method", className="text-danger")])
353353

354+
connection = connection.replace(" ", "")
355+
354356
try:
355357
request_headers = {"Content-Type": "application/json"}
356358

streamlit/views/external_connections.py

Lines changed: 30 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,21 @@ def get_client_obo() -> WorkspaceClient:
3232
icon="ℹ️",
3333
)
3434

35-
connection_name = st.text_input("Unity Catalog Connection Name", placeholder="Enter connection name...", help="See [this guide](https://docs.databricks.com/aws/en/query-federation/http)")
35+
connection_name = st.text_input("Unity Catalog Connection name:", placeholder="Enter connection name...", help="See [this guide](https://docs.databricks.com/aws/en/query-federation/http)")
3636
auth_mode = st.radio(
37-
"Authentication Mode:",
38-
["Bearer token", "OAuth User to Machine Per User (On-behalf-of-user)", "OAuth Machine to Machine"],
37+
"Authentication mode:",
38+
["OAuth User to Machine Per User (On-behalf-of-user)", "Bearer token", "OAuth Machine to Machine"],
3939
)
40-
http_method = st.selectbox("HTTP Method", options=["GET", "POST", "PUT", "DELETE", "PATCH"], )
41-
path = st.text_input("Path", placeholder="/api/endpoint")
42-
request_headers = st.text_area("Request headers", placeholder='{"Content-Type": "application/json"}') or {}
43-
request_data = st.text_area("Request data", placeholder='{"key": "value"}')
40+
http_method = st.selectbox("HTTP method:", options=["GET", "POST", "PUT", "DELETE", "PATCH"], )
41+
path = st.text_input("Path:", placeholder="/api/endpoint")
42+
request_headers = st.text_area("Request headers:", placeholder='{"Content-Type": "application/json"}') or {}
43+
request_data = st.text_area("Request data:", placeholder='{"key": "value"}')
4444

45-
all_fields_filled = path and connection_name != ""
45+
all_fields_filled = path and connection_name
4646
if not all_fields_filled:
4747
st.info("Please fill in all required fields to run a query.")
4848

49+
connection_name = connection_name.replace(" ", "") if connection_name else ""
4950

5051
if st.button("Send Request"):
5152
if auth_mode == "Bearer token":
@@ -84,27 +85,6 @@ def get_client_obo() -> WorkspaceClient:
8485

8586
with tab_code:
8687
table = [
87-
{
88-
"type": "Bearer token",
89-
"code": """
90-
```python
91-
import streamlit as st
92-
from databricks.sdk import WorkspaceClient
93-
from databricks.sdk.service.serving import ExternalFunctionRequestHttpMethod
94-
95-
w = WorkspaceClient()
96-
97-
response = w.serving_endpoints.http_request(
98-
conn="github_connection",
99-
method=ExternalFunctionRequestHttpMethod.GET,
100-
path="/traffic/views",
101-
headers={"Accept": "application/vnd.github+json"},
102-
)
103-
104-
st.json(response.json())
105-
```
106-
""",
107-
},
10888
{
10989
"type": "OAuth User to Machine Per User (On-behalf-of-user)",
11090
"code": """
@@ -156,6 +136,27 @@ def init_mcp_session(w: WorkspaceClient, connection_name: str):
156136
```
157137
""",
158138
},
139+
{
140+
"type": "Bearer token",
141+
"code": """
142+
```python
143+
import streamlit as st
144+
from databricks.sdk import WorkspaceClient
145+
from databricks.sdk.service.serving import ExternalFunctionRequestHttpMethod
146+
147+
w = WorkspaceClient()
148+
149+
response = w.serving_endpoints.http_request(
150+
conn="github_connection",
151+
method=ExternalFunctionRequestHttpMethod.GET,
152+
path="/traffic/views",
153+
headers={"Accept": "application/vnd.github+json"},
154+
)
155+
156+
st.json(response.json())
157+
```
158+
""",
159+
}
159160
]
160161

161162
for i, row in enumerate(table):

streamlit/views/mcp_connect.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,9 @@ def is_connection_login_error(error: str):
9595
if not all_fields_filled:
9696
st.info("Please fill in all required fields to run a query.")
9797

98+
connection_name = connection_name.replace(" ", "") if connection_name else ""
9899

99-
if st.button("Send request"):
100+
if st.button("Send Request"):
100101
if auth_mode == "Bearer token":
101102
w = WorkspaceClient()
102103
elif auth_mode == "OAuth User to Machine Per User (On-behalf-of-user)":

0 commit comments

Comments
 (0)