Repository navigation
Description
Describe the Bug
The MCP plugin's deleteDocuments tool can't delete a document that is in the trash. On a collection with trash: true, it returns NotFound for a trashed document.
The tool's input schema has no trash option, and the handler calls payload.delete without one. deleteByIDOperation defaults to trash = false and adds the non-trashed filter, so a trashed document is never found. The find, update and count tools all accept trash; only delete is missing it.
As a result, an MCP client can trash a document (through updateDocuments with deletedAt) and can find it with trash: true, but it can't empty it from the trash. Sending trash: true to deleteDocuments is rejected by the strict schema.
Link to the code that reproduces this issue
- Schema without
trash:payload/packages/payload/src/collections/operations/inputSchemas.ts
Lines 119 to 131 in aebbf75
const deleteDocumentsInputShape = { id: z.optional(idSchema), slug: slugSchema, depth: depthSchema, fallbackLocale: fallbackLocaleSchema, locale: localeSchema, where: whereSchema, } export const deleteDocumentsInputSchema = strictObject( deleteDocumentsInputShape, z.superRefine(requireIDOrWhere), ) - Handler that passes no
trash:payload/packages/plugin-mcp/src/mcp/builtin/collections/deleteTool.ts
Lines 26 to 69 in aebbf75
const { id, depth, fallbackLocale, locale, where } = input logger.info( `Deleting document from collection: ${slug}${id ? ` with ID: ${id}` : ' with where clause'}${locale ? `, locale: ${locale}` : ''}`, ) try { if (id !== undefined) { const result = await payload.delete({ id: parseDocumentID({ id, collectionSlug: slug, payload }), collection: slug, depth, overrideAccess: authorizedMCP.overrideAccess, req, ...(locale && { locale }), ...(fallbackLocale !== undefined && { fallbackLocale }), }) return { content: [ { type: 'text', text: `Document deleted successfully from collection "${slug}"!\nDeleted document:\n\`\`\`json\n${JSON.stringify(result)}\n\`\`\``, }, ], doc: result, } } if (where === undefined) { return { content: [{ type: 'text', text: 'Error: Either id or where clause must be provided' }], } } const result = await payload.delete({ collection: slug, depth, overrideAccess: authorizedMCP.overrideAccess, req, where, ...(locale && { locale }), ...(fallbackLocale !== undefined && { fallbackLocale }), }) - Default
trash = falseand the non-trashed filter:payload/packages/payload/src/collections/operations/deleteByID.ts
Lines 97 to 123 in aebbf75
trash = false, } = args // ///////////////////////////////////// // Access // ///////////////////////////////////// const accessResults = !overrideAccess ? await executeAccess( { id, slug: collectionConfig.slug, req }, collectionConfig.access.delete, ) : true const hasWhereAccess = hasWhereAccessResult(accessResults) // ///////////////////////////////////// // Retrieve document // ///////////////////////////////////// let where = combineQueries({ id: { equals: id } }, accessResults) // Exclude trashed documents when trash: false where = appendNonTrashedFilter({ enableTrash: collectionConfig.trash, trash, where, })
Reproduction Steps
- Add
trash: trueto a collection, enable it inmcpPluginwith delete allowed, and create a document. - Over MCP, trash it:
updateDocumentswith{ id, data: { deletedAt: <now> } }. - Over MCP, call
deleteDocumentswith{ id }. It returns NotFound. - Call
deleteDocumentswith{ id, trash: true }. The input is rejected (unrecognized key).
Expected: the document can be deleted from the trash, as the admin panel's "Delete permanently" and the Local API's payload.delete({ id, trash: true }) both allow.
Suggested fix: add trash: trashSchema to deleteDocumentsInputShape. Then destructure trash in deleteTool.ts and pass it to both payload.delete calls, as updateTool.ts does.
Which area(s) are affected?
plugin: mcp
Environment Info
payload: 4.0.0-beta.4
@payloadcms/plugin-mcp: 4.0.0-beta.4
@payloadcms/db-vercel-postgres: 4.0.0-beta.4
next: 16.4.1
node: 24.22.1
Still present on main at aebbf75.
Activity
fix: address six additional Payload v4 core and plugin issues [skip ci]
fix(plugin-mcp): allow deleteDocuments to delete trashed documents (p…
github-actions commentedon Nov 10, 2026
🚀 This is included in version v4.0.0-beta.8