delete_variants
Delete multiple variants from a Shopify product permanently. Keeps at least one variant per product; variants in completed orders remain visible. Irreversible action.
Instructions
Permanently delete one or more variants from a product. Irreversible. Each product must keep at least one variant — Shopify rejects requests that would empty the product (delete the whole product via update_product status:ARCHIVED, or use the admin UI for full deletion). Variants in completed orders are kept-but-hidden by Shopify automatically; the historical record on the order is preserved.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productId | Yes | Product GID. | |
| variantIds | Yes |
Implementation Reference
- src/tools/variants.ts:214-217 (schema)Input schema for delete_variants: requires productId and an array of 1-100 variantIds.
const deleteVariantsSchema = { productId: z.string().describe("Product GID."), variantIds: z.array(z.string()).min(1).max(100), }; - src/tools/variants.ts:389-416 (handler)Handler for delete_variants tool. Calls the Shopify productVariantsBulkDelete mutation and reports the count of deleted variants.
server.tool( "delete_variants", "Permanently delete one or more variants from a product. Irreversible. Each product must keep at least one variant — Shopify rejects requests that would empty the product (delete the whole product via update_product status:ARCHIVED, or use the admin UI for full deletion). Variants in completed orders are kept-but-hidden by Shopify automatically; the historical record on the order is preserved.", deleteVariantsSchema, async (args) => { const data = await client.graphql<{ productVariantsBulkDelete: { product: { id: string } | null; userErrors: ShopifyUserError[]; }; }>(VARIANTS_BULK_DELETE_MUTATION, { productId: args.productId, variantsIds: args.variantIds, }); throwIfUserErrors( data.productVariantsBulkDelete.userErrors, "productVariantsBulkDelete", ); return { content: [ { type: "text" as const, text: `Deleted ${args.variantIds.length} variant(s) from ${args.productId}.`, }, ], }; }, ); - src/tools/variants.ts:103-110 (helper)GraphQL mutation string used by the delete_variants handler to delete variants via Shopify's productVariantsBulkDelete.
const VARIANTS_BULK_DELETE_MUTATION = /* GraphQL */ ` mutation VariantsBulkDelete($productId: ID!, $variantsIds: [ID!]!) { productVariantsBulkDelete(productId: $productId, variantsIds: $variantsIds) { product { id } userErrors { field message } } } `; - src/server.ts:64-64 (registration)Registration call that wires up all variant tools (including delete_variants) onto the MCP server.
registerVariantTools(s, shopify);