Skip to main content
Glama
smithery-ai

Shopify Update MCP Server

by smithery-ai

get-products-by-collection

Retrieve products from a specific Shopify collection by providing the collection ID. Specify a limit to control the number of products returned.

Instructions

Get products from a specific collection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
collectionIdYesID of the collection to get products from
limitNoMaximum number of products to return

Implementation Reference

  • MCP tool registration, schema, and handler for 'get-products-by-collection'. The handler fetches products by collection ID using ShopifyClient, formats them with formatProduct, and returns formatted text output.
    server.tool(
      "get-products-by-collection",
      "Get products from a specific collection",
      {
        collectionId: z
          .string()
          .describe("ID of the collection to get products from"),
        limit: z
          .number()
          .optional()
          .default(10)
          .describe("Maximum number of products to return"),
      },
      async ({ collectionId, limit }) => {
        const client = new ShopifyClient();
        try {
          const products = await client.loadProductsByCollectionId(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            collectionId,
            limit
          );
          const formattedProducts = products.products.map(formatProduct);
          return {
            content: [{ type: "text", text: formattedProducts.join("\n") }],
          };
        } catch (error) {
          return handleError("Failed to retrieve products from collection", error);
        }
      }
    );
  • Helper function to format a product node into a readable string, used by the tool handler.
    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(", ")}
      `;
    }
  • Core implementation of fetching products by collection ID via Shopify GraphQL API, called by the tool handler.
    async loadProductsByCollectionId(
      accessToken: string,
      shop: string,
      collectionId: string,
      limit: number = 10,
      afterCursor?: string
    ): Promise<LoadProductsResponse> {
      const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop);
    
      const graphqlQuery = gql`
        {
          shop {
            currencyCode
          }
          collection(id: "gid://shopify/Collection/${collectionId}") {
            products(
              first: ${limit}${afterCursor ? `, after: "${afterCursor}"` : ""}
            ) {
              edges {
                node {
                  ${productFragment}
                }
              }
              pageInfo {
                hasNextPage
                endCursor
              }
            }
          }
        }
      `;
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          shop: {
            currencyCode: string;
          };
          collection: {
            products: {
              edges: Array<{
                node: ProductNode;
              }>;
              pageInfo: {
                hasNextPage: boolean;
                endCursor: string;
              };
            };
          };
        };
      }>({
        url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`,
        accessToken,
        query: graphqlQuery,
      });
    
      const data = res.data.data;
      const edges = data.collection.products.edges;
      const products = edges.map((edge) => edge.node);
      const pageInfo = data.collection.products.pageInfo;
      const next = pageInfo.hasNextPage ? pageInfo.endCursor : undefined;
      const currencyCode = data.shop.currencyCode;
    
      return { products, next, currencyCode };
    }
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 states the action but reveals nothing about permissions needed, rate limits, pagination behavior, error conditions, or what format/products are returned. For a read operation 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 with zero wasted words. It's appropriately sized for this tool's complexity and gets straight to the point without unnecessary elaboration.

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 no annotations, no output schema, and multiple sibling tools with overlapping functionality, the description is insufficiently complete. It doesn't explain what 'products' means in this context, how results are structured, or how this differs from other product retrieval tools, leaving the agent with incomplete contextual understanding.

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%, so the schema already fully documents both parameters. The description adds no additional parameter semantics beyond what's in the schema, but doesn't need to compensate for gaps. This meets the baseline expectation when schema does the heavy lifting.

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 ('products from a specific collection'), making the purpose immediately understandable. However, it doesn't distinguish this tool from its sibling 'get-products' or 'get-products-by-ids', which would require more specific differentiation to earn a 5.

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' or 'get-products-by-ids'. There's no mention of prerequisites, context, or exclusion criteria, leaving the agent with minimal usage direction.

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