Skip to content

Commit 0b1409b

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

File tree

3 files changed

+12
-14
lines changed

3 files changed

+12
-14
lines changed

dash/pages/mcp_connect.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,13 @@ def send_external_request(n_clicks, connection, method, body, auth_type):
352352
return html.Div([html.P("Please fill in all required fields: Connection and Method", className="text-danger")])
353353

354354
try:
355-
headers = {}
355+
request_headers = {"Content-Type": "application/json"}
356356

357357
# Parse body JSON
358-
body_data = None
358+
request_data = None
359359
if body and body.strip():
360360
try:
361-
body_data = json.loads(body)
361+
request_data = json.loads(body)
362362
except json.JSONDecodeError:
363363
return html.Div([html.P("❌ Invalid JSON in body", className="text-danger")])
364364
w = get_workspace_client(auth_type)
@@ -399,18 +399,19 @@ def send_external_request(n_clicks, connection, method, body, auth_type):
399399
return html.Div([html.P(f"❌ MCP Initialization Error: {error}", className="text-danger")])
400400
else:
401401
return html.Div([html.P(f"❌ MCP Initialization Error: {error}", className="text-danger")])
402+
402403
mcp_session_id = session_id
403404

404405
# Add MCP session ID to headers
405-
headers["Mcp-Session-Id"] = mcp_session_id
406+
request_headers["Mcp-Session-Id"] = mcp_session_id
406407

407408
# Use json parameter for MCP requests
408409
response = w.serving_endpoints.http_request(
409410
conn=connection,
410411
method=method_enum,
411412
path=request_path,
412-
headers=headers,
413-
json=body_data
413+
headers=request_headers if request_headers else None,
414+
json=request_data if request_data else {},
414415
)
415416
else:
416417
# Regular requests
@@ -419,15 +420,16 @@ def send_external_request(n_clicks, connection, method, body, auth_type):
419420
conn=connection,
420421
method=method_enum,
421422
path=request_path,
422-
headers=headers,
423-
json=body_data
423+
headers=request_headers if request_headers else None,
424+
json=request_data if request_data else {},
424425
)
425426
else:
426427
response = w.serving_endpoints.http_request(
427428
conn=connection,
428429
method=method_enum,
429430
path=request_path,
430-
headers=headers
431+
headers=request_headers if request_headers else None,
432+
json=request_data if request_data else {},
431433
)
432434

433435
response_json = response.json()

streamlit/views/external_connections.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,6 @@ def get_client_obo() -> WorkspaceClient:
7070

7171
http_method = getattr(ExternalFunctionRequestHttpMethod, http_method)
7272

73-
request_data = request_data if request_data else None
74-
7573
response = w.serving_endpoints.http_request(
7674
conn=connection_name,
7775
method=http_method,

streamlit/views/mcp_connect.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def is_connection_login_error(error: str):
105105
# TODO: Add OAuth Machine-to-Machine logic
106106
w = WorkspaceClient()
107107

108-
request_headers = {}
108+
request_headers = {"Content-Type": "application/json"}
109109

110110
if request_data and request_data.strip():
111111
try:
@@ -135,8 +135,6 @@ def is_connection_login_error(error: str):
135135

136136
request_headers["Mcp-Session-Id"] = st.session_state.mcp_session_id
137137

138-
request_data = request_data if request_data else None
139-
140138
response = w.serving_endpoints.http_request(
141139
conn=connection_name,
142140
method=http_method,

0 commit comments

Comments
 (0)