Skip to main content
Glama
amir-bengherbi

Shopify MCP Server

get-products

Retrieve all products or search by title from a Shopify store using GraphQL API. Specify a search term or limit results for product management.

Instructions

Get all products or search by title

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
searchTitleNoSearch title, if missing, will return all products
limitYesMaximum number of products to return

Implementation Reference

  • The MCP tool handler function for 'get-products'. Instantiates ShopifyClient, fetches products via loadProducts (supporting title search and limit), formats each product using formatProduct helper, joins formatted strings, and returns as text content or error response.
    async ({ searchTitle, limit }) => {
      const client = new ShopifyClient();
      try {
        const products = await client.loadProducts(
          SHOPIFY_ACCESS_TOKEN,
          MYSHOPIFY_DOMAIN,
          searchTitle ?? null,
          limit
        );
        const formattedProducts = products.products.map(formatProduct);
        return {
          content: [{ type: "text", text: formattedProducts.join("\n") }],
        };
      } catch (error) {
        return handleError("Failed to retrieve products data", error);
      }
    }
  • Zod input schema for the 'get-products' tool: optional searchTitle (string) for filtering by product title, and limit (number) for pagination.
    {
      searchTitle: z
        .string()
        .optional()
        .describe("Search title, if missing, will return all products"),
      limit: z.number().describe("Maximum number of products to return"),
    },
  • src/index.ts:105-132 (registration)
    Full registration of the 'get-products' MCP tool using server.tool(), including name, description, input schema, and inline handler function.
    server.tool(
      "get-products",
      "Get all products or search by title",
      {
        searchTitle: z
          .string()
          .optional()
          .describe("Search title, if missing, will return all products"),
        limit: z.number().describe("Maximum number of products to return"),
      },
      async ({ searchTitle, limit }) => {
        const client = new ShopifyClient();
        try {
          const products = await client.loadProducts(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            searchTitle ?? null,
            limit
          );
          const formattedProducts = products.products.map(formatProduct);
          return {
            content: [{ type: "text", text: formattedProducts.join("\n") }],
          };
        } catch (error) {
          return handleError("Failed to retrieve products data", error);
        }
      }
    );
  • Core helper method loadProducts in ShopifyClient class: executes GraphQL query to Shopify Admin API to retrieve products filtered by title (using lucene-style query), limited by count, supports cursor pagination, returns LoadProductsResponse with products, next cursor, and currency.
    async loadProducts(
      accessToken: string,
      myshopifyDomain: string,
      searchTitle: string | null,
      limit: number = 10,
      afterCursor?: string
    ): Promise<LoadProductsResponse> {
      const titleFilter = searchTitle ? `title:*${searchTitle}*` : "";
      const graphqlQuery = gql`
        {
          shop {
            currencyCode
          }
          products(first: ${limit}, query: "${titleFilter}"${
        afterCursor ? `, after: "${afterCursor}"` : ""
      }) {
            edges {
              node {
                ${productFragment}
              }
            }
            pageInfo {
              hasNextPage
              endCursor
            }
          }
        }
      `;
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          shop: {
            currencyCode: string;
          };
          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.products.edges;
      const products = edges.map((edge) => edge.node);
      const pageInfo = data.products.pageInfo;
      const next = pageInfo.hasNextPage ? pageInfo.endCursor : undefined;
      const currencyCode = data.shop.currencyCode;
    
      return { products, next, currencyCode };
    }
  • Helper function formatProduct: converts a ProductNode object into a human-readable multi-line string, including title, description, handle, and details for each variant (title, id, price, sku, inventoryPolicy). Used by the tool handler.
    function formatProduct(product: ProductNode): string {
      return `
      Product: ${product.title} 
      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 of behavioral disclosure. It states what the tool does but lacks details on permissions, rate limits, pagination, error handling, or response format. For a read operation with no 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 extremely concise with just one sentence that efficiently conveys the core functionality. It's front-loaded and wastes no words, 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 what the return values look like, how results are structured, or any behavioral constraints. For a tool with two parameters and no structured output documentation, more context is needed for effective use.

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 documents both parameters thoroughly. The description adds minimal value by implying the 'searchTitle' parameter's optional nature and the tool's dual functionality, but doesn't provide additional syntax or format details beyond what the schema specifies.

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 tool's purpose with a specific verb ('Get') and resource ('products'), and distinguishes between two modes: retrieving all products or searching by title. However, it doesn't explicitly differentiate from sibling tools like 'get-products-by-collection' or 'get-products-by-ids', which would require 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-by-collection' or 'get-products-by-ids'. It mentions the two modes of operation but doesn't specify scenarios, prerequisites, or exclusions for choosing this tool over siblings.

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