Skip to content

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

Closed

Description

@rafalyovson

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:
    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:
    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 = false and the non-trashed filter:
    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

  1. Add trash: true to a collection, enable it in mcpPlugin with delete allowed, and create a document.
  2. Over MCP, trash it: updateDocuments with { id, data: { deletedAt: <now> } }.
  3. Over MCP, call deleteDocuments with { id }. It returns NotFound.
  4. Call deleteDocuments with { 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

  1. added a commit that references this issue on Nov 9, 2026
    3c5610b
  2. github-actions commented on Nov 10, 2026

    @github-actions
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions