Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: two ways past the stdio MCP UI-session gate (#8551)

Daniel Han6d4a9ff4be73
diff --git a/studio/backend/mcp_server.py b/studio/backend/mcp_server.py
index 2f4e63da7bb..9df7bb6324b 100644
--- a/studio/backend/mcp_server.py
+++ b/studio/backend/mcp_server.py
@@ -170,7 +170,10 @@ def create_studio_mcp() -> FastMCP:
from models.data_recipe import RecipePayload
from routes.data_recipe.validate import validate
- return _dump(validate(RecipePayload(recipe = recipe)))
+ # Direct call, so the ViaApiKey dependency never runs and its `= False`
+ # default would read as a UI session. This surface is a remote static
+ # bearer, so say so explicitly.
+ return _dump(validate(RecipePayload(recipe = recipe), via_api_key = True))
@mcp.tool
def get_recipe_job_status(job_id: str) -> dict[str, Any]:
diff --git a/studio/backend/routes/mcp_servers.py b/studio/backend/routes/mcp_servers.py
index eca2b9a72b0..2653d902a49 100644
--- a/studio/backend/routes/mcp_servers.py
+++ b/studio/backend/routes/mcp_servers.py
@@ -132,8 +132,16 @@ def _row_to_response(row: dict) -> McpServerResponse:
@router.get("/", response_model = list[McpServerResponse])
-async def list_mcp_servers(current_subject: str = Depends(get_current_subject)):
- return [_row_to_response(row) for row in mcp_servers_db.list_servers()]
+async def list_mcp_servers(
+ current_subject: str = Depends(get_current_subject), via_api_key: ViaApiKey = False
+):
+ rows = mcp_servers_db.list_servers()
+ if via_api_key:
+ # Drop the row, not just its fields: `url` is the argv (carries
+ # credentials), `headers` is the subprocess env, and a blanked url would
+ # round-trip into update as a bogus command.
+ rows = [row for row in rows if not is_stdio(row["url"])]
+ return [_row_to_response(row) for row in rows]
@router.post("/", response_model = McpServerResponse, status_code = 201)
diff --git a/studio/backend/tests/test_mcp_stdio_api_key_gate.py b/studio/backend/tests/test_mcp_stdio_api_key_gate.py
index 888f8bd361e..feed07791a2 100644
--- a/studio/backend/tests/test_mcp_stdio_api_key_gate.py
+++ b/studio/backend/tests/test_mcp_stdio_api_key_gate.py
@@ -415,3 +415,63 @@ def test_data_recipe_validate_refuses_stdio_recipe_from_api_key():
with pytest.raises(HTTPException) as exc:
validate(payload, via_api_key = True)
assert exc.value.status_code == 403
+
+
+# ── reading back a command the gate would not let a key define ──────
+
+
+def test_list_hides_stdio_rows_from_api_keys(tmp_path, monkeypatch, stdio_on):
+ """A key that may not define a command may not read one back: `url` is the
+ argv (carries credentials) and `headers` is the subprocess env."""
+ import routes.mcp_servers as routes_mcp
+
+ _reset_db(tmp_path, monkeypatch)
+ mcp_servers_db.create_server(
+ id = "stdio1",
+ display_name = "FS",
+ url = "npx server --token sk-argv-secret",
+ headers_json = '{"API_KEY": "sk-env-secret"}',
+ )
+ mcp_servers_db.create_server(
+ id = "http1",
+ display_name = "R",
+ url = "https://example.com/mcp",
+ headers_json = '{"Authorization": "Bearer t"}',
+ )
+
+ keyed = asyncio.run(routes_mcp.list_mcp_servers(current_subject = "u", via_api_key = True))
+ assert [row.id for row in keyed] == ["http1"]
+ serialized = repr([row.model_dump() for row in keyed])
+ assert "sk-argv-secret" not in serialized
+ assert "sk-env-secret" not in serialized
+ # http(s) MCP stays fully usable from a key, headers included.
+ assert keyed[0].headers == {"Authorization": "Bearer t"}
+
+
+def test_list_shows_stdio_rows_to_a_ui_session(tmp_path, monkeypatch, stdio_on):
+ import routes.mcp_servers as routes_mcp
+
+ _reset_db(tmp_path, monkeypatch)
+ mcp_servers_db.create_server(
+ id = "stdio1",
+ display_name = "FS",
+ url = "npx server --token sk-argv-secret",
+ headers_json = '{"API_KEY": "sk-env-secret"}',
+ )
+ rows = asyncio.run(routes_mcp.list_mcp_servers(current_subject = "u", via_api_key = False))
+ assert [row.id for row in rows] == ["stdio1"]
+ assert rows[0].url == "npx server --token sk-argv-secret"
+ assert rows[0].headers == {"API_KEY": "sk-env-secret"}
+
+
+def test_studio_mcp_surface_refuses_stdio_recipes():
+ """mcp_server.py calls the validate route function directly, so the ViaApiKey
+ dependency never runs and its `= False` default would read as a UI session.
+ That remote static bearer surface must pass True itself or the gate is dead."""
+ import inspect
+
+ import mcp_server
+
+ assert "validate(RecipePayload(recipe = recipe), via_api_key = True)" in inspect.getsource(
+ mcp_server
+ )