Skip to main content
Glama
clavia-labs

Shopify Update MCP Server

by clavia-labs

get-variants-by-ids

Retrieve specific product variants from Shopify using their unique IDs to access detailed variant information.

Instructions

Get product variants by their IDs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
variantIdsYesArray of variant IDs to retrieve

Implementation Reference

  • src/index.ts:220-242 (registration)
    Registration of the 'get-variants-by-ids' MCP tool, including description, Zod input schema for variantIds array, and inline handler that uses ShopifyClient to load variants by IDs and returns JSON-formatted response.
    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 implementation in ShopifyClient that performs GraphQL query using nodes(ids:) to fetch product variants by their GIDs, includes associated product details and images, filters for ProductVariant type, returns variants array with 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 in ShopifyClientPort for the loadVariantsByIds method, specifying input parameters and LoadVariantsByIdResponse output.
    loadVariantsByIds(
      accessToken: string,
      shop: string,
      variantIds: string[]
    ): Promise<LoadVariantsByIdResponse>;
  • Type definition for the response of loadVariantsByIds, including currencyCode and array of ProductVariantWithProductDetails (variant plus product info).
    export type LoadVariantsByIdResponse = {
      currencyCode: string;
      variants: ProductVariantWithProductDetails[];
    };

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
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.