Skip to content

Require a preview token to apply the MCP clean tool - #29

Open
mattt wants to merge 3 commits into
mainfrom
mattt/preview-token
Open

mattt wants to merge 3 commits into
mainfrom
mattt/preview-token

Conversation

@mattt

@mattt mattt commented Nov 16, 2026

Copy link
Copy Markdown
Owner

The MCP clean tool asks agents to show a dry run and get the user's approval before apply: true, but the server did not enforce it. An agent could call apply directly, or apply a selection different from the one the user saw.

A dry run now returns a preview_token. apply requires the token and the same arguments, scans again, and deletes nothing unless the new selection matches the dry run: the same project cache paths with the same rules, projects, sizes, and modification times, or the same global rules with the same paths, actions, and targets. Otherwise it returns an error that lists each added, removed, or changed entry. Global cache sizes are not compared, because every build changes them; the Xcode rule's folders and their size are compared.

The server keeps up to 16 previews in memory under random tokens. A token works for one apply call and expires 30 minutes after its dry run, because the dry run the user approved is probably out of date by then. The comparison runs on the same scan that apply deletes from, through a new Confirm hook in the engine, and every existing safety check still runs before each deletion. The command-line clean --apply is unchanged, because the README does not promise this guarantee there.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant