Skip to main content
Glama

list_variants

Retrieve all variants of a product, including option definitions, prices, SKU, barcode, inventory, and taxable status. Use to inspect the full SKU matrix before modifying 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 function that executes the 'list_variants' tool logic — runs the GraphQL query, formats options and variants, and returns the formatted text response.
      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 the 'list_variants' tool: requires productId (string GID) and optional 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 call: server.tool('list_variants', ...) inside registerVariantTools, binding the name, description, schema, and handler.
    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 formatVariant used by the handler to format a single variant into a display string.
    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 LIST_VARIANTS_QUERY used by the handler 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 provided, so description carries full burden. It accurately describes the data returned (read-only) and lists fields, but does not mention pagination behavior or cursor handling despite the 'first' parameter. No destructive side effects are claimed, so no contradiction, but missing pagination details reduces transparency.

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: first sentence defines scope, second enumerates returned fields, third provides usage guidance. No unnecessary words, highly efficient and front-loaded.

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?

For a tool with 2 parameters and no output schema, the description gives a comprehensive overview of returned data and usage context. However, it lacks explanation of pagination mechanics for the 'first' parameter, which is needed for large product variant lists.

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

Parameters2/5

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

Schema description coverage is 50%: productId is described as 'Product GID' but 'first' lacks any description. The description adds no extra meaning for 'first' beyond its existence, failing to compensate for the missing schema description. For a parameter controlling result count, this is a significant 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 along with option definitions and possible values, specifying the exact fields returned. It explicitly distinguishes from sibling mutation tools (create_variants, update_variants, delete_variants) by advising use before calling them.

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

Usage Guidelines4/5

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

Explicitly says to use it 'to inspect a product's full SKU matrix before calling create_variants/update_variants/delete_variants,' providing clear context. It does not explicitly state when not to use, but the read-only nature is implicit and alternatives are implied by sibling names.

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