Skip to main content
Glama
amir-bengherbi

Shopify MCP Server

get-variants-by-ids

Retrieve specific product variants from a Shopify store using their unique IDs. This tool fetches variant details for inventory management, order processing, or data analysis.

Instructions

Get product variants by their IDs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
variantIdsYesArray of variant IDs to retrieve

Implementation Reference

  • src/index.ts:192-215 (registration)
    Registers the 'get-variants-by-ids' MCP tool, defines input schema (array of variantIds), and provides the handler function that instantiates ShopifyClient and calls loadVariantsByIds to fetch and return variant data as JSON.
    server.tool(
      "get-variants-by-ids",
      "Get product variants by their IDs",
      {
        variantIds: z
          .array(z.string())
          .describe("Array of variant IDs to retrieve"),
      },
      async ({ variantIds }) => {
        const client = new ShopifyClient();
        try {
          const variants = await client.loadVariantsByIds(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            variantIds
          );
          return {
            content: [{ type: "text", text: JSON.stringify(variants, null, 2) }],
          };
        } catch (error) {
          return handleError("Failed to retrieve variants", error);
        }
      }
    );
  • Core handler logic: Executes GraphQL query to fetch product variants by IDs using nodes(ids: [...]), includes product details and images, filters valid ProductVariant nodes, returns variants with shop currencyCode.
    async loadVariantsByIds(
      accessToken: string,
      shop: string,
      variantIds: string[]
    ): Promise<LoadVariantsByIdResponse> {
      const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop);
    
      const graphqlQuery = gql`
        {
          shop {
            currencyCode
          }
          nodes(ids: ${JSON.stringify(variantIds)}) {
            __typename
            ... on ProductVariant {
              ${productVariantsFragment}
              product {
                id
                title
                description
                images(first: 20) {
                  edges {
                    node {
                      ${productImagesFragment}
                    }
                  }
                }
              }
            }
          }
        }
      `;
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          shop: {
            currencyCode: string;
          };
          nodes: Array<
            | ({
                __typename: string;
              } & ProductVariantWithProductDetails)
            | null
          >;
        };
      }>({
        url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`,
        accessToken,
        query: graphqlQuery,
      });
    
      const variants = res.data.data.nodes.filter(
        (
          node
        ): node is {
          __typename: string;
        } & ProductVariantWithProductDetails =>
          node?.__typename === "ProductVariant"
      );
      const currencyCode = res.data.data.shop.currencyCode;
    
      return { variants, currencyCode };
    }
  • TypeScript interface definition for loadVariantsByIds method in ShopifyClientPort.
    loadVariantsByIds(
      accessToken: string,
      shop: string,
      variantIds: string[]
    ): Promise<LoadVariantsByIdResponse>;
  • Type definition for the response of loadVariantsByIds, including currency and array of variants with product details.
    export type LoadVariantsByIdResponse = {
      currencyCode: string;
      variants: ProductVariantWithProductDetails[];
    };
  • Extended type for product variant including associated product details (title, description, images).
    export type ProductVariantWithProductDetails = ProductVariant & {
      product: {
        id: string;
        title: string;
        description: string;
        images: {
          edges: {
            node: ProductImage;
          }[];
        };
      };
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It only states what the tool does ('Get product variants'), but doesn't describe whether this is a read-only operation, what permissions are required, how many variants can be retrieved at once, error handling for invalid IDs, or the format of returned data. For a retrieval tool with zero annotation coverage, this leaves significant behavioral gaps.

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 a single, efficient sentence that gets straight to the point with zero wasted words. It follows the principle of front-loading the most important information (what the tool does) without unnecessary elaboration. Every word earns its place in this minimal but complete statement of purpose.

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

Completeness2/5

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

Given the tool has no annotations, no output schema, and the description provides only basic purpose without behavioral context, this is incomplete for effective agent use. While the purpose is clear, the agent lacks information about what the tool returns, how it handles errors, limitations, or authentication requirements. For a data retrieval tool, this represents significant contextual gaps.

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 schema description coverage is 100% with the single parameter 'variantIds' fully documented in the schema. The description adds no additional parameter semantics beyond what's already in the schema ('Array of variant IDs to retrieve'). According to scoring rules, when schema coverage is high (>80%), the baseline is 3 even with no param info in the description.

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

Purpose4/5

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

The description 'Get product variants by their IDs' clearly states the verb ('Get'), resource ('product variants'), and key constraint ('by their IDs'). It distinguishes from general product retrieval tools like 'get-products' or 'get-products-by-ids' by focusing specifically on variants. However, it doesn't explicitly differentiate from potential sibling tools that might also retrieve variants through other means.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when this tool is preferred over 'get-products' (which might include variants) or 'get-products-by-ids', nor does it specify prerequisites like needing specific variant IDs. The agent must infer usage from the tool name and description alone.

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/amir-bengherbi/shopify-mcp-server'

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