delete_collection
Permanently delete a Shopify collection grouping while keeping its products. Irreversible. Requires collection ID (use get_collection to confirm). Returns deleted collection ID or 'nothing deleted'.
Instructions
Permanently delete a collection. Products inside it are NOT deleted — only the grouping is removed; products keep all their other associations (other collections, tags, inventory). Irreversible. Confirm the collection ID with get_collection before calling. Returns the deleted collection ID, or a 'nothing deleted' message if the GID didn't match anything.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | GID of the collection to delete. The collection's products are NOT deleted, only the collection grouping. Irreversible. |
Implementation Reference
- src/tools/collections.ts:423-446 (registration)Registration of the 'delete_collection' MCP tool, binding the name to its schema and handler function.
server.tool( "delete_collection", "Permanently delete a collection. Products inside it are NOT deleted — only the grouping is removed; products keep all their other associations (other collections, tags, inventory). Irreversible. Confirm the collection ID with get_collection before calling. Returns the deleted collection ID, or a 'nothing deleted' message if the GID didn't match anything.", deleteCollectionSchema, async (args) => { const data = await client.graphql<{ collectionDelete: { deletedCollectionId: string | null; userErrors: ShopifyUserError[]; }; }>(DELETE_COLLECTION_MUTATION, { input: { id: args.id } }); throwIfUserErrors(data.collectionDelete.userErrors, "collectionDelete"); return { content: [ { type: "text" as const, text: data.collectionDelete.deletedCollectionId ? `Deleted collection ${data.collectionDelete.deletedCollectionId}.` : "No collection matched; nothing deleted.", }, ], }; }, ); - src/tools/collections.ts:427-445 (handler)Handler function for delete_collection: executes the GraphQL mutation with the collection ID, throws on user errors, and returns a confirmation message.
async (args) => { const data = await client.graphql<{ collectionDelete: { deletedCollectionId: string | null; userErrors: ShopifyUserError[]; }; }>(DELETE_COLLECTION_MUTATION, { input: { id: args.id } }); throwIfUserErrors(data.collectionDelete.userErrors, "collectionDelete"); return { content: [ { type: "text" as const, text: data.collectionDelete.deletedCollectionId ? `Deleted collection ${data.collectionDelete.deletedCollectionId}.` : "No collection matched; nothing deleted.", }, ], }; }, - src/tools/collections.ts:217-223 (schema)Zod schema defining the input for delete_collection: a single required 'id' string parameter (the collection GID).
const deleteCollectionSchema = { id: z .string() .describe( "GID of the collection to delete. The collection's products are NOT deleted, only the collection grouping. Irreversible.", ), }; - src/tools/collections.ts:89-96 (helper)GraphQL mutation string for deleting a collection via Shopify's CollectionDelete mutation.
const DELETE_COLLECTION_MUTATION = /* GraphQL */ ` mutation CollectionDelete($input: CollectionDeleteInput!) { collectionDelete(input: $input) { deletedCollectionId userErrors { field message } } } `;