Skip to main content
Glama
smithery-ai

Shopify Update MCP Server

by smithery-ai

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[];
    };
Behavior2/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 of behavioral disclosure. It states the tool retrieves variants but doesn't cover aspects like authentication requirements, rate limits, error handling, or what happens if IDs are invalid. For a read operation with zero annotation coverage, this leaves significant gaps in understanding its behavior.

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 directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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 lack of annotations and output schema, the description is incomplete. It doesn't explain return values, error cases, or behavioral traits like idempotency. For a tool with one parameter but no structured context, more detail is needed to fully understand its 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 schema description coverage is 100%, with the parameter 'variantIds' fully documented in the schema as an array of strings. The description adds no additional meaning beyond what the schema provides, such as format examples or constraints, so it meets the baseline for high schema coverage without compensating value.

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 clearly states the verb ('Get') and resource ('product variants by their IDs'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools like 'get-products-by-ids' or 'get-products', which also retrieve product-related data, so it doesn't achieve full sibling differentiation.

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 like 'get-products-by-ids' or 'get-products', nor does it mention prerequisites such as needing valid variant IDs. It simply states what the tool does without context for selection.

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/smithery-ai/shopify-mcp-server-main-1'

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