Skip to main content
Glama

list_variants

List all variants of a product to inspect its full SKU matrix, including option definitions, prices, SKUs, barcodes, inventory, and taxable status. Use to review variant details before creating, updating, or deleting variants.

Instructions

List all variants of a single product, plus the product's option definitions (Size, Color, etc.) and possible values. For each variant returns: title, GID, price, compareAtPrice, SKU, barcode, current inventory quantity, taxable flag, inventory policy, and the option-value combination that produced it. Use to inspect a product's full SKU matrix before calling create_variants/update_variants/delete_variants.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
productIdYesProduct GID.
firstNo

Implementation Reference

  • The async handler that executes the list_variants tool logic: calls the Shopify GraphQL API with LIST_VARIANTS_QUERY, formats and returns product options and variants as text.
      async (args) => {
        const data = await client.graphql<{
          product:
            | {
                id: string;
                title: string;
                options: ProductOptionNode[];
                variants: {
                  edges: Array<{ node: VariantNode }>;
                  pageInfo: { hasNextPage: boolean };
                };
              }
            | null;
        }>(LIST_VARIANTS_QUERY, { productId: args.productId, first: args.first });
        if (!data.product) {
          return {
            content: [
              { type: "text" as const, text: `Product not found: ${args.productId}` },
            ],
          };
        }
        const p = data.product;
        const optionLines = p.options.map(
          (o) =>
            `  ${o.name} (#${o.position}): ${o.optionValues.map((v) => v.name).join(", ")}`,
        );
        const variantLines = p.variants.edges.map(({ node }) => formatVariant(node));
        return {
          content: [
            {
              type: "text" as const,
              text: [
                `${p.title} — ${p.id}`,
                "Options:",
                ...optionLines,
                `Variants (${p.variants.edges.length}):`,
                ...variantLines,
                p.variants.pageInfo.hasNextPage
                  ? "(more variants available; raise `first` to page further)"
                  : "",
              ]
                .filter(Boolean)
                .join("\n"),
            },
          ],
        };
      },
    );
  • Input schema for list_variants: productId (string GID) and first (int, 1-100, default 50).
    const listVariantsSchema = {
      productId: z.string().describe("Product GID."),
      first: z.number().int().min(1).max(100).default(50),
    };
  • Registration of the 'list_variants' tool on the McpServer inside registerVariantTools(), wired up in src/server.ts at line 64.
    server.tool(
      "list_variants",
      "List all variants of a single product, plus the product's option definitions (Size, Color, etc.) and possible values. For each variant returns: title, GID, price, compareAtPrice, SKU, barcode, current inventory quantity, taxable flag, inventory policy, and the option-value combination that produced it. Use to inspect a product's full SKU matrix before calling create_variants/update_variants/delete_variants.",
      listVariantsSchema,
      async (args) => {
        const data = await client.graphql<{
          product:
            | {
                id: string;
                title: string;
                options: ProductOptionNode[];
                variants: {
                  edges: Array<{ node: VariantNode }>;
                  pageInfo: { hasNextPage: boolean };
                };
              }
            | null;
        }>(LIST_VARIANTS_QUERY, { productId: args.productId, first: args.first });
        if (!data.product) {
          return {
            content: [
              { type: "text" as const, text: `Product not found: ${args.productId}` },
            ],
          };
        }
        const p = data.product;
        const optionLines = p.options.map(
          (o) =>
            `  ${o.name} (#${o.position}): ${o.optionValues.map((v) => v.name).join(", ")}`,
        );
        const variantLines = p.variants.edges.map(({ node }) => formatVariant(node));
        return {
          content: [
            {
              type: "text" as const,
              text: [
                `${p.title} — ${p.id}`,
                "Options:",
                ...optionLines,
                `Variants (${p.variants.edges.length}):`,
                ...variantLines,
                p.variants.pageInfo.hasNextPage
                  ? "(more variants available; raise `first` to page further)"
                  : "",
              ]
                .filter(Boolean)
                .join("\n"),
            },
          ],
        };
      },
    );
  • Helper function that formats a VariantNode into a human-readable string used in the list_variants handler output.
    function formatVariant(v: VariantNode): string {
      const opts =
        v.selectedOptions?.map((o) => `${o.name}=${o.value}`).join(", ") ??
        "(no options)";
      const sku = v.sku ? ` SKU:${v.sku}` : "";
      const cmp = v.compareAtPrice ? ` cmp:${v.compareAtPrice}` : "";
      const qty =
        v.inventoryQuantity !== null && v.inventoryQuantity !== undefined
          ? ` qty:${v.inventoryQuantity}`
          : "";
      return `  ${v.title} [${opts}] ${v.price}${cmp}${sku}${qty} — ${v.id}`;
    }
  • GraphQL query used by the list_variants tool to fetch product options and variants.
    const LIST_VARIANTS_QUERY = /* GraphQL */ `
      query ListVariants($productId: ID!, $first: Int!) {
        product(id: $productId) {
          id
          title
          options {
            id
            name
            position
            optionValues { id name hasVariants }
          }
          variants(first: $first) {
            edges {
              node {
                id
                title
                price
                compareAtPrice
                sku
                barcode
                position
                taxable
                inventoryPolicy
                inventoryQuantity
                selectedOptions { name value }
              }
            }
            pageInfo { hasNextPage endCursor }
          }
        }
      }
    `;
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It implies a read-only operation by stating 'List all variants,' but does not disclose potential behavioral traits like pagination behavior (the 'first' parameter suggests pagination), rate limits, or required permissions. While the description is safe, it lacks explicit behavioral disclosure.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is three sentences: the first states the main purpose, the second lists output fields, and the third gives usage guidance. It is concise, front-loaded, and every sentence adds value without unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

There is no output schema, so the description compensates by listing the returned fields (title, GID, price, etc.). It also mentions option definitions. However, it does not explain pagination behavior despite having a 'first' parameter. Overall, it provides sufficient context for a list operation.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 2 parameters: productId (described as 'Product GID.') and first (no description in schema, but default 50). Schema description coverage is 50%. The tool description does not add additional meaning to these parameters beyond what the schema provides. It mentions output fields but not parameter details, so it fails to compensate for the schema gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it 'lists all variants of a single product' plus option definitions, and enumerates the returned fields. The verb 'list' and resource 'variants of a single product' are specific. It distinguishes itself from sibling mutation tools like create_variants, update_variants, and delete_variants.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly says 'Use to inspect a product's full SKU matrix before calling create_variants/update_variants/delete_variants,' providing clear when-to-use and when-not-to-use guidance. This effectively differentiates it from sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/miller-joe/shopify-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server