reorder_variants
Reorder variants on a Shopify product by assigning unique 1-indexed positions. Only specify variants with changed positions; others remain unchanged. Controls display order on product page and admin.
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:219-229 (schema)Zod schema for reorder_variants: accepts productId (string) and positions (array of {id: string, position: int >=1})
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/tools/variants.ts:418-444 (handler)Handler for reorder_variants: calls productVariantsBulkReorder mutation with productId and positions, throws on user errors, returns success message
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:112-121 (helper)GraphQL mutation VARIANTS_BULK_REORDER_MUTATION used by the reorder_variants tool
const VARIANTS_BULK_REORDER_MUTATION = /* GraphQL */ ` mutation VariantsBulkReorder( $productId: ID! $positions: [ProductVariantPositionInput!]! ) { productVariantsBulkReorder(productId: $productId, positions: $positions) { userErrors { field message } } } `; - src/server.ts:64-64 (registration)Registration of variant tools (including reorder_variants) on the MCP server
registerVariantTools(s, shopify);