Add verified rollback for failed recipe imports

Co-authored-by: Bumble <bumble@agents.famfallman.com>
Co-authored-by: fredamn76 <fredrik.fallman@gmail.com>
Signed-off-by: fredamn76 <fredrik.fallman@gmail.com>
This commit is contained in:
2026-07-31 09:34:43 +02:00
committed by fredamn76
parent 620d3b4fe2
commit e45156f11b
3 changed files with 76 additions and 0 deletions
+33
View File
@@ -335,6 +335,39 @@ def patch_recipe(slug_or_id: str, patch: dict[str, Any]) -> dict[str, Any]:
return get_recipe(slug_or_id)
@mcp.tool()
def delete_recipe(slug_or_id: str, confirm_slug: str) -> dict[str, Any]:
"""Delete exactly one recipe, with explicit slug confirmation and read-back proof.
This is primarily the rollback path for failed imports and marked test recipes.
The caller must first read the recipe and pass its exact stored slug as
``confirm_slug``. Names and ids are not accepted as confirmation.
"""
recipe = get_recipe(slug_or_id)
stored_slug = recipe.get("slug") or ""
if confirm_slug != stored_slug:
raise ValueError(
f"Deletion confirmation does not match stored slug {stored_slug!r}"
)
with _client() as client:
response = client.delete(f"/api/recipes/{stored_slug}")
_raise_for_status(response)
probe = client.get(f"/api/recipes/{stored_slug}")
if probe.status_code != 404:
raise RuntimeError(
f"Delete returned {response.status_code}, but read-back returned "
f"{probe.status_code} instead of 404"
)
return {
"deleted": True,
"slug": stored_slug,
"name": recipe.get("name"),
"delete_status": response.status_code,
"readback_status": probe.status_code,
}
def _unit_records() -> list[dict[str, Any]]:
"""The instance's own unit table — the authority for what `dl` and `msk` mean."""
data = _request("GET", "/api/units", params={"perPage": 200})