Skip to content

fix(plugin-mcp): allow deleteDocuments to delete trashed documents - #19051

Merged
AlessioGr merged 1 commit into
payloadcms:mainfrom
lazerg:fix/issue-19050-mcp-delete-trash
Nov 9, 2026
Merged

AlessioGr merged 1 commit into
payloadcms:mainfrom
lazerg:fix/issue-19050-mcp-delete-trash

Conversation

@lazerg

@lazerg lazerg commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

What?

The MCP deleteDocuments tool can't delete a document that is already in the trash. Calling it with just id returns NotFound, and passing trash: true is rejected by the input schema.

Why?

deleteDocumentsInputShape has no trash option and the tool calls payload.delete without one, so the delete operation always filters out trashed documents. The find, count and update tools already accept trash.

How?

Added trash to the shared delete input schema and passed it through to both payload.delete calls in the MCP tool, like updateTool.ts does. The CLI deleteDocuments command uses the same schema, so it now passes trash too. Added an int test that calls deleteDocuments with trash: true.

Fixes #19050

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between aebbf75 and fd91cc6.

Files selected for processing: 4
  • packages/payload/src/cli/commands/collections/deleteDocuments.ts
  • packages/payload/src/collections/operations/inputSchemas.ts
  • packages/plugin-mcp/src/mcp/builtin/collections/deleteTool.ts
  • test/plugin-mcp/int.spec.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The deletion input schema now accepts trash. The CLI command and MCP deleteDocuments tool forward this option to payload.delete for ID-based and where-based deletion. An MCP integration test checks the forwarded arguments.

Changes: Trash-aware document deletion

Layer / File(s) Summary
Accept and forward the trash option
packages/payload/src/collections/operations/inputSchemas.ts, packages/payload/src/cli/commands/collections/deleteDocuments.ts, packages/plugin-mcp/src/mcp/builtin/collections/deleteTool.ts, test/plugin-mcp/int.spec.ts
The deletion input schema accepts trash. The CLI command and MCP tool pass the option to both deletion paths. The MCP integration test checks the success text and forwarded arguments.

Priority: Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related issues

  • The MCP deletion changes address the reported inability to delete trashed documents: the input accepts trash, and the tool forwards it to payload.delete.

Suggested reviewers: alessiogr

Merge Risk: Minimal · up to fd91c

The change appears ready to merge after normal checks; no actionable deletion risk remains identified.

Architecture risk: Low · up to fd91c

The change affects 3 systems.

Changed systems: packages/payload, packages/plugin-mcp, test

Architecture concerns
No architecture-level concerns identified.

Review details

Systems and components

  • observed — packages/payload (library) was modified; 2 changed files map to changed impact.
  • observed — packages/plugin-mcp (library) was modified; 1 changed file maps to changed impact.
  • observed — test (service) was modified; 1 changed file maps to changed impact.

Before / after behavior

  • observed — Modified behavior in packages/payload/src/cli/commands/collections/deleteDocuments.ts: The ID-based deletion call now passes args.trash to payload.delete.
  • observed — Modified behavior in packages/payload/src/cli/commands/collections/deleteDocuments.ts: The where-based deletion call now passes args.trash to payload.delete.
  • observed — Modified behavior in packages/payload/src/collections/operations/inputSchemas.ts: deleteDocumentsInputShape adds the trash field, validated with trashSchema; deletion inputs can now specify trash behavior.
  • observed — Modified behavior in packages/plugin-mcp/src/mcp/builtin/collections/deleteTool.ts: The input destructuring now includes trash.
Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title names the MCP plugin, the deleteDocuments tool, and the trashed-document fix. The raw summary shows the change adds a trash option to the shared delete schema and passes it to payload.delete…
Description check Passed The description states the problem (MCP deleteDocuments cannot delete trashed documents), the cause (no trash option in deleteDocumentsInputShape and no trash passed to payload.delete), and the fix (t…
Linked Issues check Passed Issue #19050 requires the MCP deleteDocuments tool to accept trash: true and pass it to payload.delete, so trashed documents can be deleted. At head fd91cc6:

- Schema: packages/payload/src/collection…
Out of Scope Changes check Passed All changes map to the #19050 objective:

- inputSchemas.ts (+1): adds the trash option to the shared delete input shape. This is the change the issue requests.
- deleteTool.ts (+3/-1): passes trash t…
Docstring Coverage Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4…
Full details: Title check

Explanation

The title names the MCP plugin, the deleteDocuments tool, and the trashed-document fix. The raw summary shows the change adds a trash option to the shared delete schema and passes it to payload.delete in the MCP tool and CLI command, so the title matches the main change.

Full details: Description check

Explanation

The description states the problem (MCP deleteDocuments cannot delete trashed documents), the cause (no trash option in deleteDocumentsInputShape and no trash passed to payload.delete), and the fix (trash added to the shared schema and passed to both delete calls, plus an int test). This directly matches the changeset.

Full details: Linked Issues check

Explanation

Issue #19050 requires the MCP deleteDocuments tool to accept trash: true and pass it to payload.delete, so trashed documents can be deleted. At head fd91cc6:

  • Schema: packages/payload/src/collections/operations/inputSchemas.ts adds trash: trashSchema to deleteDocumentsInputShape. deleteDocumentsInputSchema is strict, so trash: true is now accepted instead of rejected as an unrecognized key.
  • Handler: packages/plugin-mcp/src/mcp/builtin/collections/deleteTool.ts destructures trash from input and passes it to both payload.delete calls (the id branch and the where branch), matching the pattern the issue cites from updateTool.ts.
  • Automated test: the PR adds an int test in test/plugin-mcp/int.spec.ts that calls deleteDocuments with trash: true and checks that payload.delete receives the post ID, collection slug, and trash: true. This test verifies pass-through through a spy, not end-to-end deletion of a trashed document from the database. It supports the stated requirement.

The issue's suggested fix matches these changes. The required behavior is implemented. The #19050 requirements are met.

Full details: Out of Scope Changes check

Explanation

All changes map to the #19050 objective:

  • inputSchemas.ts (+1): adds the trash option to the shared delete input shape. This is the change the issue requests.
  • deleteTool.ts (+3/-1): passes trash to both payload.delete calls. This is the change the issue requests.
  • test/plugin-mcp/int.spec.ts (+35): adds a test for the new behavior. Tests support the objective.
  • packages/payload/src/cli/commands/collections/deleteDocuments.ts (+2): passes args.trash to both payload.delete calls. The CLI command uses deleteDocumentsLocalInputSchema, which is built from the same deleteDocumentsInputShape. The CLI therefore accepts trash as a direct result of the shared schema change. The issue names this schema as the fix location, so this side effect is expected and not unrelated work.

No change lacks a connection to the objective. No unrelated refactoring or unrelated behavior change is present in the reviewed summary.

Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 4 files.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@AlessioGr AlessioGr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks!

@AlessioGr
AlessioGr merged commit 3c5610b into payloadcms:main Nov 9, 2026
299 checks passed
@github-actions

Copy link
Copy Markdown
Contributor

🚀 This is included in version v4.0.0-beta.8

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.

plugin-mcp: deleteDocuments can't delete trashed documents (no trash option)

2 participants