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: let MCP run_recipe set a row count (#17427)

Nilayce96e7825014
diff --git a/studio/backend/studio_mcp/tools/jobs.py b/studio/backend/studio_mcp/tools/jobs.py
index 02c96597f34..5ac8e0a336d 100644
--- a/studio/backend/studio_mcp/tools/jobs.py
+++ b/studio/backend/studio_mcp/tools/jobs.py
@@ -75,7 +75,16 @@ async def get_job(
async def run_recipe(
- recipe: dict[str, Any], mode: Literal["validate", "preview", "full"] = "validate"
+ recipe: dict[str, Any],
+ mode: Literal["validate", "preview", "full"] = "validate",
+ rows: Annotated[
+ Optional[int],
+ Field(
+ ge = 1,
+ le = 200_000,
+ description = "Rows to generate; default 5 for a preview, 1000 for a full run.",
+ ),
+ ] = None,
) -> RecipeResult:
"""Validate a Data Recipe, or run it. "validate" checks it and returns any errors; "preview" generates a few rows; "full" generates the whole dataset and saves it. A run returns a job id at once: follow it with get_job(kind="recipe"). Recipes that define a local (stdio) MCP server, or take a provider key from a server environment variable (api_key_env), can only be run from the Unsloth Studio UI."""
if mode == "validate":
@@ -89,10 +98,13 @@ async def run_recipe(
if isinstance(e, dict)
]
return RecipeResult(mode = mode, valid = payload.get("valid") is True, errors = errors)
+ if rows is None:
+ rows = 5 if mode == "preview" else 1000
+ run = {"execution_type": mode, "rows": rows, "run_config": {"buffer_size": rows}}
created = await route_json(
"POST",
f"{RECIPE_ROUTES}/jobs",
- json_body = {"recipe": recipe, "run": {"execution_type": mode}},
+ json_body = {"recipe": recipe, "run": run},
)
job_id = opt_text(created.get("job_id")) if isinstance(created, dict) else None
if job_id is None:
diff --git a/studio/backend/tests/test_mcp_tool_contract.py b/studio/backend/tests/test_mcp_tool_contract.py
index cc325e4fa46..0e4e90cfb10 100644
--- a/studio/backend/tests/test_mcp_tool_contract.py
+++ b/studio/backend/tests/test_mcp_tool_contract.py
@@ -104,6 +104,7 @@ REFUSED = [
],
("get_job", {"kind": "recipe", "id": "job-1", "rows": 0}, None),
("get_job", {"kind": "recipe", "id": "job-1", "rows": 501}, None),
+ *[("run_recipe", {"recipe": {}, "mode": "full", "rows": rows}, None) for rows in (0, 200_001)],
("datasets", {"action": "check_format"}, "check_format needs name"),
("datasets", {"action": "download"}, None),
("datasets", {"action": "status"}, None),
diff --git a/studio/backend/tests/test_mcp_tools_recipe.py b/studio/backend/tests/test_mcp_tools_recipe.py
index b72806958a1..2321612f36d 100644
--- a/studio/backend/tests/test_mcp_tools_recipe.py
+++ b/studio/backend/tests/test_mcp_tools_recipe.py
@@ -34,11 +34,17 @@ PAYLOADS = {
}
+def _run(mode, rows):
+ return {"execution_type": mode, "rows": rows, "run_config": {"buffer_size": rows}}
+
+
@pytest.mark.parametrize("mode", [None, "preview", "full"])
def test_validate_checks_and_preview_or_full_starts_a_job(monkeypatch, mode):
args = {"recipe": RECIPE, **({"mode": mode} if mode else {})}
result, studio = run_tool(monkeypatch, PAYLOADS, "run_recipe", args)
- started = [{"recipe": RECIPE, "run": {"execution_type": mode}}] if mode else []
+ started = (
+ [{"recipe": RECIPE, "run": _run(mode, 5 if mode == "preview" else 1000)}] if mode else []
+ )
assert result["structuredContent"] == {
"mode": mode or "validate",
"valid": None if mode else False,
@@ -49,6 +55,14 @@ def test_validate_checks_and_preview_or_full_starts_a_job(monkeypatch, mode):
assert bodies(studio, "/api/data-recipe/validate") == ([] if mode else [{"recipe": RECIPE}])
[email protected]("mode,rows", [("preview", 12), ("full", 50)])
+def test_a_run_generates_the_rows_asked_for(monkeypatch, mode, rows):
+ args = {"recipe": RECIPE, "mode": mode, "rows": rows}
+ result, studio = run_tool(monkeypatch, PAYLOADS, "run_recipe", args)
+ assert result["structuredContent"]["job_id"] == "job-1"
+ assert bodies(studio, "/api/data-recipe/jobs") == [{"recipe": RECIPE, "run": _run(mode, rows)}]
+
+
def test_a_job_reports_its_dataset_by_name_never_its_path(monkeypatch):
result, studio = run_tool(monkeypatch, PAYLOADS, "get_job", {"kind": "recipe", "id": "job-1"})
out = result["structuredContent"]