Skip to content

fix(server): agents can no longer delete a project's threads or No project through MCP - #33790

Closed
riskneutral00 wants to merge 1 commit into
pingdotgg:mainfrom
riskneutral00:fix/mcp-project-delete-guard
Closed

riskneutral00 wants to merge 1 commit into
pingdotgg:mainfrom
riskneutral00:fix/mcp-project-delete-guard

Conversation

@riskneutral00

Copy link
Copy Markdown

Problem

One MCP call from an agent hid 1,872 threads on a real install, with no confirmation and no undo (#33766).

The agent was cleaning up after a test. It called t3_project_delete with force: true on the built-in "No project", because the test's threads had been launched with t3_thread_launch { scratch: true } and lived there. T3 deleted the project and every thread in it: 436 threads and their subagent threads, 1,872 thread.deleted events in 63 seconds. Pinned threads went too, and three runs that were still working were cancelled. The tool returned success. The agent never saw a count or a confirmation step. T3 has no restore command, so getting the threads back meant editing statev2.sqlite by hand, and the attachment files of the deleted threads are removed at once (attachment.cleanup in ThreadDeletion.ts), so 22 of 108 attachments were lost for good.

The unpatched tool also invites this. A delete without force is refused with "The project is not empty; force=true is required to delete it.", so an agent that hits the refusal is told to retry with force.

Expected: deleting a project together with its threads is the user's decision. The app already treats it that way. Settings → Projects → Remove project asks for a destructive confirmation, with a message that counts the project's threads, before it sends force: true (removeMembers in apps/web/src/components/settings/ProjectSettingsPanel.tsx, message from planProjectRemoval). An agent should not be able to skip that step.

Change

All changes are in the MCP project toolkit; the agent path is the only one that changes.

  • t3_project_delete no longer takes force (apps/server/src/mcp/toolkits/project/tools.ts). The handler builds the delete from projectId alone, so an agent can delete only a project with no threads. New description: "Delete one empty project. Folder on disk stays. Only the user deletes a project with threads."

  • For a project with threads the agent gets invalid_request, which says what the delete would have taken and where the user does it (apps/server/src/mcp/toolkits/project/handlers.ts):

    The project has 3 threads (1 pinned). Only the user can delete a project with its threads, from the project's settings in the app. Archive it to keep everything.

    The count reads the same snapshot ProjectService.deleteChildThreads deletes from (getShellSnapshot({ projectId }), threads plus archived threads). It counts them as the app's own removal confirmation does, listed threads only (isListedThreadLineage), so subagent threads and side chats are left out of the number, though they go with their parents. If the read fails or finds no listed thread, the refusal goes out without a count.

  • The built-in "No project" is refused outright, using the existing ManagedProjectFolders.isScratchProject:

    "No project" (the built-in scratch project) cannot be deleted; it holds every thread started without a project.

    With force gone, a No project that still has threads is already refused by the rule above. This check gives that project a clearer message, also covers it when empty (T3 recreates it on the next scratch launch anyway), and keeps holding if force is ever brought back.

  • apps/server/src/provider/agentContextBudget.json: mcpToolListJsonBytes goes from 48217 to 48212. The shorter description and the removed parameter shrink the advertised tool list by 5 bytes.

Deliberately not changed:

  • ProjectService, the WebSocket and HTTP project mutation routes, the t3 project remove --force CLI and the web and mobile clients. The user's own deletes work exactly as before.
  • Agents can still delete an empty project, and can still archive or delete single threads.
  • No new approval UI. An in-app approval card for an agent's forced delete, like the request_secret card, was considered. It would touch contracts, server, web and mobile, and the app already has the confirmation this sends users to. A confirming second call from the same agent was also considered and rejected: the agent confirming its own call is not the user's consent.

Compatibility: an agent that still sends force: true has the extra key dropped by the tool's schema. An empty project is still deleted. A project with threads gets the refusal above instead of losing its threads. A search of docs, evals and agent instructions finds nothing else that calls this tool with force.

Scope and approval

Fixes #33766.

The issue is not triaged yet, and removing a tool parameter changes behavior, so this needs a maintainer to agree with the direction (CONTRIBUTING.md, "Establish the problem and scope first"). I'm opening it now so the fix and its evidence are in one place. I'll reshape it however you prefer. If you would rather keep force and only refuse "No project", the smaller change is the isScratchProject check, its message and its test. If you want the agent path to ask the user instead of refusing, I can do that.

It solves one problem: an agent can delete a project's threads without the user.

Verification

Live, on a sandboxed dev server. I ran vp run dev:server --home-dir <throwaway dir> --no-seed. An outside MCP client signed in through the server's own OAuth flow (register, approve with a code from t3 auth pairing create, PKCE token exchange, full access). It then called the tools over /mcp. Threads were launched with t3_thread_launch on the devReplay provider. Results on this PR's head:

Call Result
t3_project_delete with force: true, project with 3 threads refused: "The project has 3 threads. Only the user can delete a project with its threads, …"; all 3 threads still listed
same, without force same refusal
t3_project_delete with force: true on "No project" (1 thread) refused: ""No project" (the built-in scratch project) cannot be deleted; …"; its thread still listed
t3_project_delete on an empty project deleted
user path: t3 project remove <id> --force on the 3-thread project "Removed project …"; the project and its 3 threads are gone

Before, with main's handlers.ts and tools.ts swapped in (the server reloads on save), the same server and calls:

  • Delete without force on a 2-thread project: "The project is not empty; force=true is required to delete it."
  • Delete with force: true: deleted the project and both threads.
  • Delete with force: true on "No project": deleted it.

Tests. apps/server/src/mcp/toolkits/project/handlers.test.ts gets two tests. Their mocked ProjectService.delete refuses a project with threads unless force is true, as the real one does.

  • "an agent cannot force-delete a project that still has threads": the project has 3 listed threads, 1 pinned, plus a subagent thread that is not counted. The test sends force: true and asserts that nothing was deleted and that the message begins "The project has 3 threads (1 pinned). Only the user can delete a project with its threads".
  • "an agent cannot delete the No project scratch project": same call against a project isScratchProject reports as scratch.
  • With main's handlers.ts and tools.ts, both fail with expected [ 'project:client-target' ] to deeply equal [], meaning the project was deleted. With the change, all 13 tests in the file pass.

Checks, run locally on Node 26.12.1:

  • CI's lint job steps all pass: vp check (0 errors; its 4 warnings are in files this PR does not touch), vp run knip:check, and both generate --check.
  • vp run check:changed passes every step, including typecheck of 41 packages and AgentContextBudget.test.ts.
  • vp test run src/mcp src/project src/provider/AgentContextBudget.test.ts in apps/server: 511 of 512 pass. The failure, AgentSessionScanner "excludes sandboxes reached through a symlink into the worktrees dir", fails the same way on main on this machine.

Eval. The description change is covered by mcp-tool-use --case archive-project-not-delete --samples 2 (claude-sonnet-5-5): 2 of 2 pass, cost $0.15.

Not checked:

  • The full 8-shard server suite, build and release smoke. I left those to CI.
  • The settings page button itself, clicked in a browser. This PR does not change that route.
  • Windows.

Written with Claude Opus 5.5 (claude-opus-5-5) in Claude Code.

🤖 Generated with Claude Code

@macroscopeapp

macroscopeapp Bot commented Nov 10, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved at dfd0dbb

Macroscope's review found this PR approvable — MCP agents can now delete only empty, non-scratch projects, with clearer refusals for projects containing threads. The change reduces destructive exposure while leaving app-based deletion unchanged.

You can add or adjust custom eligibility rules. Learn more.

Copy link
Copy Markdown
Member

Thanks @riskneutral00 for the detailed investigation and regression coverage. #33773, by @juliusmarminge, covers the same scratch-project deletion defect with a smaller, tested change. I’m closing this as a duplicate; if the broader restriction on deleting other nonempty projects still matters, please propose that separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:unvouched Author is not yet trusted in the VOUCHED list.

Projects

None yet

2 participants