reorder_variants
Reorder product variants by assigning unique 1-indexed positions. Only specify variants whose positions are changing; others remain unchanged.
Instructions
Set the display order of variants on a product. Positions are 1-indexed and must be unique across all variants in the product (you can't have two variants both at position 2). Affects the order variants appear on the product page and in Shopify admin. Only provide the variants whose positions are changing — others stay where they are.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| productId | Yes | Product GID. | |
| positions | Yes |
Implementation Reference
- src/tools/variants.ts:418-444 (handler)The handler function for the 'reorder_variants' tool. It calls the Shopify GraphQL mutation productVariantsBulkReorder with the product ID and the array of positions (variant ID + 1-indexed position), throws on user errors, and returns a summary string.
server.tool( "reorder_variants", "Set the display order of variants on a product. Positions are 1-indexed and must be unique across all variants in the product (you can't have two variants both at position 2). Affects the order variants appear on the product page and in Shopify admin. Only provide the variants whose positions are changing — others stay where they are.", reorderVariantsSchema, async (args) => { const data = await client.graphql<{ productVariantsBulkReorder: { userErrors: ShopifyUserError[]; }; }>(VARIANTS_BULK_REORDER_MUTATION, { productId: args.productId, positions: args.positions, }); throwIfUserErrors( data.productVariantsBulkReorder.userErrors, "productVariantsBulkReorder", ); return { content: [ { type: "text" as const, text: `Reordered ${args.positions.length} variant(s).`, }, ], }; }, ); - src/tools/variants.ts:219-229 (schema)Zod schema for the 'reorder_variants' tool. Accepts a productId (string GID) and an array of positions, each containing a variant id (string GID) and a 1-indexed integer position.
const reorderVariantsSchema = { productId: z.string().describe("Product GID."), positions: z .array( z.object({ id: z.string().describe("Variant GID."), position: z.number().int().min(1), }), ) .min(1), }; - src/server.ts:64-64 (registration)Registration call: registerVariantTools is invoked in the buildServer function, which wires the tool to the MCP server.
registerVariantTools(s, shopify); - src/tools/variants.ts:112-121 (helper)The GraphQL mutation string VARIANTS_BULK_REORDER_MUTATION used by the reorder_variants handler to call Shopify's productVariantsBulkReorder endpoint.
const VARIANTS_BULK_REORDER_MUTATION = /* GraphQL */ ` mutation VariantsBulkReorder( $productId: ID! $positions: [ProductVariantPositionInput!]! ) { productVariantsBulkReorder(productId: $productId, positions: $positions) { userErrors { field message } } } `;