Skip to main content
Glama
smithery-ai

Shopify Update MCP Server

by smithery-ai

get-products-by-ids

Retrieve specific Shopify products using their unique IDs to access detailed information for inventory management or order processing.

Instructions

Get products by their IDs

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
productIdsYesArray of product IDs to retrieve

Implementation Reference

  • src/index.ts:167-191 (registration)
    Registers the 'get-products-by-ids' tool with MCP server, defines input schema and inline handler that instantiates ShopifyClient, calls loadProductsByIds, formats output using formatProduct, and handles errors.
    server.tool(
      "get-products-by-ids",
      "Get products by their IDs",
      {
        productIds: z
          .array(z.string())
          .describe("Array of product IDs to retrieve"),
      },
      async ({ productIds }) => {
        const client = new ShopifyClient();
        try {
          const products = await client.loadProductsByIds(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            productIds
          );
          const formattedProducts = products.products.map(formatProduct);
          return {
            content: [{ type: "text", text: formattedProducts.join("\n") }],
          };
        } catch (error) {
          return handleError("Failed to retrieve products by IDs", error);
        }
      }
    );
  • Core handler implementation in ShopifyClient: executes GraphQL query using 'nodes(ids)' to fetch products by GID, filters results, returns products and shop currency.
    async loadProductsByIds(
      accessToken: string,
      shop: string,
      productIds: string[]
    ): Promise<LoadProductsResponse> {
      const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop);
    
      const graphqlQuery = gql`
        {
          shop {
            currencyCode
          }
          nodes(ids: ${JSON.stringify(productIds)}) {
            __typename
            ... on Product {
              ${productFragment}
            }
          }
        }
      `;
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          shop: {
            currencyCode: string;
          };
          nodes: Array<
            | ({
                __typename: string;
              } & ProductNode)
            | null
          >;
        };
      }>({
        url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`,
        accessToken,
        query: graphqlQuery,
      });
    
      const data = res.data.data;
    
      const products = data.nodes.filter(
        (
          node
        ): node is {
          __typename: string;
        } & ProductNode => node?.__typename === "Product"
      );
      const currencyCode = data.shop.currencyCode;
    
      return { products, currencyCode };
    }
  • Zod input schema for the tool: requires array of product ID strings.
    {
      productIds: z
        .array(z.string())
        .describe("Array of product IDs to retrieve"),
    },
  • TypeScript output type definition for loadProductsByIds response.
    export type LoadProductsByIdsResponse = {
      currencyCode: string;
      products: ProductNode[];
    };
  • Helper function to format product data into readable text string used in tool response.
    function formatProduct(product: ProductNode): string {
      return `
      Product: ${product.title} 
      id: ${product.id}
      description: ${product.description} 
      handle: ${product.handle}
      variants: ${product.variants.edges
        .map(
          (variant) => `variant.title: ${variant.node.title}
        variant.id: ${variant.node.id}
        variant.price: ${variant.node.price}
        variant.sku: ${variant.node.sku}
        variant.inventoryPolicy: ${variant.node.inventoryPolicy}
        `
        )
        .join(", ")}
      `;
    }
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. It states 'Get products by their IDs', implying a read-only operation, but doesn't disclose behavioral traits like authentication needs, rate limits, error handling, or response format. This leaves gaps in understanding how the tool behaves beyond basic retrieval.

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

Conciseness4/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's front-loaded and easy to parse, though it could be slightly more informative without sacrificing brevity.

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 complexity of a retrieval tool with no annotations and no output schema, the description is incomplete. It lacks details on return values, error cases, or operational context (e.g., pagination, limits), making it inadequate for full understanding despite the simple input schema.

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?

Schema description coverage is 100%, with the parameter 'productIds' documented as 'Array of product IDs to retrieve'. The description adds no additional meaning beyond this, such as format examples or constraints. With high schema coverage, the baseline score of 3 is appropriate as the schema handles parameter documentation adequately.

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

Purpose3/5

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

The description 'Get products by their IDs' clearly states the verb ('Get') and resource ('products'), but it's vague about scope and doesn't distinguish from siblings like 'get-products' or 'get-products-by-collection'. It specifies the lookup mechanism ('by their IDs') but lacks detail on what 'Get' entails (e.g., retrieval, filtering).

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?

No guidance is provided on when to use this tool versus alternatives. With siblings like 'get-products' (likely for broader queries) and 'get-products-by-collection', the description doesn't specify scenarios where ID-based lookup is preferred, such as for precise retrieval of known products, leaving usage ambiguous.

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