From cabfc0af13d92d8dd5199a07bfd76a50fafb53e8 Mon Sep 17 00:00:00 2001 From: Nathan Broadbent Date: Fri, 4 Dec 2026 10:52:58 +0000 Subject: [PATCH] MCP: delete_project, for organization admins with their own token, with the project's full org/project name as confirm; the web app's soft delete, purged after 7 days, restorable through support --- app/src/domain/project_deletion.rs | 2 +- app/src/mcp/args.rs | 8 +++ app/src/mcp/mod.rs | 43 ++++++++++++++++ .../delete_project-2.json | 15 ++++++ .../delete_project-3.json | 15 ++++++ .../delete_project-4.json | 21 ++++++++ .../delete_project.json | 15 ++++++ .../get_project.json | 14 ++++++ .../tools-list-project-token.json | 30 ++++++++++++ .../tools-list-user-token.json | 30 ++++++++++++ app/tests/mcp.rs | 49 +++++++++++++++++++ docs/design.md | 3 +- frontend/content/docs/agents.md | 2 +- frontend/content/docs/reference/access.md | 2 + frontend/content/llms-header.md | 2 +- skills/visualci-review/SKILL.md | 2 +- 16 files changed, 248 insertions(+), 5 deletions(-) create mode 100644 app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-2.json create mode 100644 app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-3.json create mode 100644 app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-4.json create mode 100644 app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project.json create mode 100644 app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/get_project.json diff --git a/app/src/domain/project_deletion.rs b/app/src/domain/project_deletion.rs index 9d8a7aca..7aa8642f 100644 --- a/app/src/domain/project_deletion.rs +++ b/app/src/domain/project_deletion.rs @@ -1,4 +1,4 @@ -//! Deleting a project (an organization's admins, in the web app), restoring it (staff, the admin MCP server's +//! Deleting a project (an organization's admins, in the web app or with the MCP tool `delete_project`), restoring it (staff, the admin MCP server's //! `restore_project`) and purging it. //! //! - [`delete`] sets `deleted_at`: from then on the project is in no list, its pages, API and MCP answers are 404s, diff --git a/app/src/mcp/args.rs b/app/src/mcp/args.rs index 63130b37..79637e57 100644 --- a/app/src/mcp/args.rs +++ b/app/src/mcp/args.rs @@ -115,6 +115,14 @@ pub struct DeleteTokenArgs { pub token_id: i64, } +#[derive(Debug, Deserialize, JsonSchema)] +pub struct DeleteProjectArgs { + /// `org/project`: the project to delete. + pub project: String, + /// The project's full name, `org/project`, typed again to confirm. + pub confirm: String, +} + #[derive(Debug, Deserialize, JsonSchema)] pub struct ListBuildsArgs { /// `org/project`. Optional with a project token. diff --git a/app/src/mcp/mod.rs b/app/src/mcp/mod.rs index 14578480..d97ab748 100644 --- a/app/src/mcp/mod.rs +++ b/app/src/mcp/mod.rs @@ -43,6 +43,7 @@ baselines, page by page. After a CI run: `list_builds`, then `get_build` for the text diff). Fix the code when a change is a regression. Approve with `review` (or `review_page` for one page) only \ when the person you work for asked for the change. You can also run a comparison yourself (`create_build`, \ `upload_snapshots`, `finalize_build`), manage organizations, projects, settings and tokens, and read each organization's plan and usage. \ +Delete a project (`delete_project`) only when the person you work for asked you to. \ To set VisualCI up in a CI provider or test tool, or write visualci.yml, read the matching skill with `get_skill` first. Choosing a plan and paying are left to a person. Projects are named `org/project`; with a project token you can leave `project` out. \ `whoami` lists the newest builds waiting for a review (`list_builds` with `waiting_for_review` lists a project's): \ on a repository that pushes straight to main, review your push's build there. \ @@ -1034,6 +1035,48 @@ impl VisualCi { Ok(structured(json!({ "deleted": args.token_id }))) } + #[tool( + description = "Delete a project (organization admins, with their own token; never a project token). `confirm` must repeat the project's full name, `org/project`. It's hidden at once: its pages, API and MCP answers are gone, its project tokens stop working and CI uploads to it are refused; the check on each open pull request's latest commit completes as neutral (\"Project deleted\") and its pull request comments say it was deleted. Its name and repository are free straight away. Everything in it is purged after 7 days; until then, VisualCI support can restore it.", + annotations( + title = "Delete project", + read_only_hint = false, + destructive_hint = true, + idempotent_hint = false, + open_world_hint = true + ) + )] + async fn delete_project( + &self, + Parameters(args): Parameters, + rc: RequestContext, + ) -> Result { + let Some(Principal::User { user, .. }) = principal_of(&rc) else { + return Ok(tool_error( + "a project token can't delete a project: an admin of the organization deletes it with their own \ + token, or in the project's Settings tab", + )); + }; + let project = need!(Self::project(&rc, Some(&args.project))); + if let Err(e) = Self::need_role(&rc, &project, Role::Admin, "delete a project").await? { + return Ok(tool_error(e)); + } + let name = format!("{}/{}", Self::organization_of(&project).await?.slug, project.slug); + if args.confirm.trim() != name { + return Ok(tool_error(format!("to delete it, `confirm` must be the project's full name: {name}"))); + } + domain::project_deletion::delete(&project, &user).await.map_err(internal)?; + Ok(structured(json!({ + "deleted": name, + "hidden": true, + "purge_after_days": domain::project_deletion::PURGE_AFTER_DAYS, + "message": format!( + "{name} is deleted and hidden everywhere now. Its builds, snapshots and images are purged after {} \ + days; until then, contact VisualCI support to restore it.", + domain::project_deletion::PURGE_AFTER_DAYS + ), + }))) + } + #[tool( description = "Download a build's images as one tar.zst, for a close look at a big build or for checks of your own: a URL (it lasts an hour) and a summary, never the images themselves. Filter by `state` (changed by default, added, removed, unchanged, all), `sides` (base, head, diff, regions: the head cropped to the changes) and a `glob` on snapshot names. The archive has `[@platform][/page-N]/{base,head,diff,regions}.png` and `manifest.json` (each snapshot's state, pages, changed fraction, regions and files). It's built in the background: when `state` is `building`, call again with the same arguments. Free.", annotations( diff --git a/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-2.json b/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-2.json new file mode 100644 index 00000000..c1f3f6c6 --- /dev/null +++ b/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-2.json @@ -0,0 +1,15 @@ +{ + "arguments": { + "confirm": "/pdfs", + "project": "/pdfs" + }, + "result": { + "content": [ + { + "text": "only an admin of the organization can delete a project; you're member", + "type": "text" + } + ], + "isError": true + } +} diff --git a/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-3.json b/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-3.json new file mode 100644 index 00000000..9e8da5ab --- /dev/null +++ b/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-3.json @@ -0,0 +1,15 @@ +{ + "arguments": { + "confirm": "pdfs", + "project": "/pdfs" + }, + "result": { + "content": [ + { + "text": "to delete it, `confirm` must be the project's full name: /pdfs", + "type": "text" + } + ], + "isError": true + } +} diff --git a/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-4.json b/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-4.json new file mode 100644 index 00000000..bd47f056 --- /dev/null +++ b/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project-4.json @@ -0,0 +1,21 @@ +{ + "arguments": { + "confirm": "/pdfs", + "project": "/pdfs" + }, + "result": { + "content": [ + { + "text": "{\"deleted\":\"/pdfs\",\"hidden\":true,\"message\":\"/pdfs is deleted and hidden everywhere now. Its builds, snapshots and images are purged after 7 days; until then, contact VisualCI support to restore it.\",\"purge_after_days\":7}", + "type": "text" + } + ], + "isError": false, + "structuredContent": { + "deleted": "/pdfs", + "hidden": true, + "message": "/pdfs is deleted and hidden everywhere now. Its builds, snapshots and images are purged after 7 days; until then, contact VisualCI support to restore it.", + "purge_after_days": 7 + } + } +} diff --git a/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project.json b/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project.json new file mode 100644 index 00000000..cba71c44 --- /dev/null +++ b/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/delete_project.json @@ -0,0 +1,15 @@ +{ + "arguments": { + "confirm": "/pdfs", + "project": "/pdfs" + }, + "result": { + "content": [ + { + "text": "a project token can't delete a project: an admin of the organization deletes it with their own token, or in the project's Settings tab", + "type": "text" + } + ], + "isError": true + } +} diff --git a/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/get_project.json b/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/get_project.json new file mode 100644 index 00000000..02da4036 --- /dev/null +++ b/app/tests/golden/mcp/delete_project_takes_an_admin_and_the_projects_full_name/get_project.json @@ -0,0 +1,14 @@ +{ + "arguments": { + "project": "/pdfs" + }, + "result": { + "content": [ + { + "text": "no project /pdfs that you can see", + "type": "text" + } + ], + "isError": true + } +} diff --git a/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-project-token.json b/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-project-token.json index 766e7842..32d25527 100644 --- a/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-project-token.json +++ b/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-project-token.json @@ -307,6 +307,36 @@ }, "name": "delete_comment" }, + { + "annotations": { + "destructiveHint": true, + "idempotentHint": false, + "openWorldHint": true, + "readOnlyHint": false, + "title": "Delete project" + }, + "description": "Delete a project (organization admins, with their own token; never a project token). `confirm` must repeat the project's full name, `org/project`. It's hidden at once: its pages, API and MCP answers are gone, its project tokens stop working and CI uploads to it are refused; the check on each open pull request's latest commit completes as neutral (\"Project deleted\") and its pull request comments say it was deleted. Its name and repository are free straight away. Everything in it is purged after 7 days; until then, VisualCI support can restore it.", + "inputSchema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": false, + "properties": { + "confirm": { + "description": "The project's full name, `org/project`, typed again to confirm.", + "type": "string" + }, + "project": { + "description": "`org/project`: the project to delete.", + "type": "string" + } + }, + "required": [ + "project", + "confirm" + ], + "type": "object" + }, + "name": "delete_project" + }, { "annotations": { "destructiveHint": true, diff --git a/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-user-token.json b/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-user-token.json index 766e7842..32d25527 100644 --- a/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-user-token.json +++ b/app/tests/golden/mcp/lists_the_tools_each_kind_of_token_can_use/tools-list-user-token.json @@ -307,6 +307,36 @@ }, "name": "delete_comment" }, + { + "annotations": { + "destructiveHint": true, + "idempotentHint": false, + "openWorldHint": true, + "readOnlyHint": false, + "title": "Delete project" + }, + "description": "Delete a project (organization admins, with their own token; never a project token). `confirm` must repeat the project's full name, `org/project`. It's hidden at once: its pages, API and MCP answers are gone, its project tokens stop working and CI uploads to it are refused; the check on each open pull request's latest commit completes as neutral (\"Project deleted\") and its pull request comments say it was deleted. Its name and repository are free straight away. Everything in it is purged after 7 days; until then, VisualCI support can restore it.", + "inputSchema": { + "$schema": "https://json-schema.org/draft/2020-12/schema", + "additionalProperties": false, + "properties": { + "confirm": { + "description": "The project's full name, `org/project`, typed again to confirm.", + "type": "string" + }, + "project": { + "description": "`org/project`: the project to delete.", + "type": "string" + } + }, + "required": [ + "project", + "confirm" + ], + "type": "object" + }, + "name": "delete_project" + }, { "annotations": { "destructiveHint": true, diff --git a/app/tests/mcp.rs b/app/tests/mcp.rs index f8b40fac..b0206128 100644 --- a/app/tests/mcp.rs +++ b/app/tests/mcp.rs @@ -1290,3 +1290,52 @@ async fn mcp_links(app: Application) -> laravel::Result<()> { assert_eq!(r["settings"]["forge_app_installed"], true); Ok(()) } + +/// `delete_project`: an admin with their own token deletes a project, typing its full `org/project` name; a project +/// token and a member are refused, and so is a wrong name. Afterwards the project answers like one that isn't there. +#[laravel::test] +async fn delete_project_takes_an_admin_and_the_projects_full_name(app: Application) -> laravel::Result<()> { + const TEST: &str = "delete_project_takes_an_admin_and_the_projects_full_name"; + let f = fixture().await?; + let pdfs = format!("{}/pdfs", f.org); + let project_id = f.project_id; + + let (err, r) = + call(&app, TEST, &f.project_token, "delete_project", json!({ "project": pdfs, "confirm": pdfs })).await; + assert!(err, "a project token never deletes: {r}"); + + let email = format!("{}@example.com", laravel::str::uuid7()); + let member = create!(User { pid: laravel::str::uuid7(), name: "member", email: email, staff: false }).await?; + let org = Organization::find_or_fail(f.organization_id).await?; + app::testing::fixtures::member(&org, &member, "member").await?; + let member_token = token("user_tokens", member.id, "agent", "vcu").await?; + let (err, r) = call(&app, TEST, &member_token, "delete_project", json!({ "project": pdfs, "confirm": pdfs })).await; + assert!(err, "a member never deletes: {r}"); + + let (err, r) = + call(&app, TEST, &f.user_token, "delete_project", json!({ "project": pdfs, "confirm": "pdfs" })).await; + assert!(err, "the bare slug isn't the full name: {r}"); + + let live: Option = + db::query!("SELECT id FROM projects WHERE id = {project_id} AND deleted_at IS NULL").scalar().await?; + assert!(live.is_some(), "refused calls leave the project alone"); + + let (err, r) = call(&app, TEST, &f.user_token, "delete_project", json!({ "project": pdfs, "confirm": pdfs })).await; + assert!(!err, "{r}"); + assert_eq!(r["deleted"], pdfs); + assert_eq!(r["purge_after_days"], 7); + let deleted_by: Option = + db::query!("SELECT deleted_by FROM projects WHERE id = {project_id}").scalar().await?; + assert!(deleted_by.is_some(), "soft-deleted by the admin, as the web app does"); + + let (err, r) = call(&app, TEST, &f.user_token, "get_project", json!({ "project": pdfs })).await; + assert!(err, "gone at once: {r}"); + // Its project token stops authenticating at all. + app.post("/mcp") + .header("authorization", format!("Bearer {}", f.project_token)) + .json(json!({ "jsonrpc": "2.0", "id": 1, "method": "tools/list" })) + .header("accept", "application/json, text/event-stream") + .await + .assert_status(401); + Ok(()) +} diff --git a/docs/design.md b/docs/design.md index 3b1191e0..2d4ceae9 100644 --- a/docs/design.md +++ b/docs/design.md @@ -301,7 +301,8 @@ the same way as a screenshot: a change keeps the GitHub check pending instead of diff numbers remain and the images show as deleted. A diff whose overlay was deleted is computed again if the same pair comes back. -- Deleting a project (`domain::project_deletion`, admins, at the bottom of its Settings tab with its name typed): +- Deleting a project (`domain::project_deletion`, admins, at the bottom of its Settings tab with its name typed, or + with the MCP tool `delete_project` and its full `org/project` name as `confirm`; never a project token): `projects.deleted_at` hides it at once. Every lookup for a person, a token or a webhook reads live projects only (`Project::live`, or `deleted_at IS NULL` in the SQL): its pages, API and MCP answers are 404s, it's in no list, its project tokens don't authenticate (so uploads and new builds are refused), webhooks, the forge sync and the diff --git a/frontend/content/docs/agents.md b/frontend/content/docs/agents.md index 198ecc9c..14324829 100644 --- a/frontend/content/docs/agents.md +++ b/frontend/content/docs/agents.md @@ -228,7 +228,7 @@ failing in the repository instead of sending them. - `whoami` (who the token belongs to, and the newest builds waiting for a review), `list_organizations`, `get_organization` (projects, plan, credits used this month and pack credits). - Out of credits: `whoami` (for each organization) and `get_build` return `blocked`, with what fixes it and a `message` to pass on to your person as it is. Buying credits stays with them. -- `create_organization`, `create_project`, `get_project`, `update_project` (settings and [ignore rules](/docs/reference/api/#project-settings)), `create_project_token`, `delete_project_token`. +- `create_organization`, `create_project`, `get_project`, `update_project` (settings and [ignore rules](/docs/reference/api/#project-settings)), `create_project_token`, `delete_project_token`, `delete_project` (admins, with the full `org/project` name to confirm; support can restore it for 7 days). **Without the MCP server** diff --git a/frontend/content/docs/reference/access.md b/frontend/content/docs/reference/access.md index 186c65f2..ad901b2b 100644 --- a/frontend/content/docs/reference/access.md +++ b/frontend/content/docs/reference/access.md @@ -43,3 +43,5 @@ You can link more than one GitHub account to your VisualCI account on the **Acco ## Deleting a project An admin deletes a project at the bottom of its **Settings** tab, typing its name to confirm. It disappears at once: its pages and API answers are gone, its project tokens stop working, CI uploads to it are refused, and the VisualCI check on each open pull request's latest commit completes as neutral ("Project deleted"), even one that was failing, so those pull requests can merge. Its pull request comments are edited to say it was deleted. If branch protection requires the VisualCI check, remove it there, or new pull requests will wait for a check that never comes. Its name and repository are free straight away, so picking the repository again makes a fresh project. Its builds, snapshots and images are deleted for good 7 days later; until then, VisualCI support can restore it. Credits it used this month still count. + +An agent can delete a project with the MCP tool `delete_project`, using an admin's own token (a project token can't), with the project's full name (`org/project`) as `confirm`. diff --git a/frontend/content/llms-header.md b/frontend/content/llms-header.md index 49f6a193..046c974e 100644 --- a/frontend/content/llms-header.md +++ b/frontend/content/llms-header.md @@ -25,7 +25,7 @@ The tools cover everything the web app and the CI API do, except choosing a plan - Builds: `list_builds`, `get_build`, `get_snapshot` (base, head and diff images of each changed page, scaled with `max_width` or cropped to the changes with `crop: changed`, the changed regions and the page's text diff; for text, JSON and HTML snapshots the changes by JSON path and a unified diff), `contact_sheet` (a grid of thumbnails for many snapshots), `snapshot_history` - Reviews: `review` (approve or reject a build or some of its snapshots), `review_page` (accept one page as a variant, or ignore one change) - Running a comparison: `create_build`, `upload_snapshots` (PDFs, PNG/JPEG/WebP images, or text, JSON and HTML with an optional `format`, base64), `finalize_build` -- Organizations and projects: `whoami`, `list_organizations`, `get_organization` (projects, plan, credits used this month and pack credits), `create_organization`, `create_project`, `get_project`, `update_project` (including `ignore_rules` for text snapshots, each scoped to a snapshot glob), `create_project_token`, `delete_project_token` +- Organizations and projects: `whoami`, `list_organizations`, `get_organization` (projects, plan, credits used this month and pack credits), `create_organization`, `create_project`, `get_project`, `update_project` (including `ignore_rules` for text snapshots, each scoped to a snapshot glob), `create_project_token`, `delete_project_token`, `delete_project` (admins, with the full `org/project` name to confirm; restorable through support for 7 days) ## Snapshot tests: text, JSON and HTML diff --git a/skills/visualci-review/SKILL.md b/skills/visualci-review/SKILL.md index b2ac13bc..bb8f7bf4 100644 --- a/skills/visualci-review/SKILL.md +++ b/skills/visualci-review/SKILL.md @@ -233,7 +233,7 @@ failing in the repository instead of sending them. - `whoami` (who the token belongs to, and the newest builds waiting for a review), `list_organizations`, `get_organization` (projects, plan, credits used this month and pack credits). - Out of credits: `whoami` (for each organization) and `get_build` return `blocked`, with what fixes it and a `message` to pass on to your person as it is. Buying credits stays with them. -- `create_organization`, `create_project`, `get_project`, `update_project` (settings and [ignore rules](https://visualci.com/docs/reference/api.md#project-settings)), `create_project_token`, `delete_project_token`. +- `create_organization`, `create_project`, `get_project`, `update_project` (settings and [ignore rules](https://visualci.com/docs/reference/api.md#project-settings)), `create_project_token`, `delete_project_token`, `delete_project` (admins, with the full `org/project` name to confirm; support can restore it for 7 days). **Without the MCP server**