Skip to main content
Glama
amir-bengherbi

Shopify MCP Server

get-collections

Retrieve Shopify store collections with optional filters for name and result limits to manage product groupings effectively.

Instructions

Get all collections

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNoMaximum number of collections to return
nameNoFilter collections by name

Implementation Reference

  • src/index.ts:484-510 (registration)
    Tool registration for 'get-collections', including inline schema (limit, name params) and handler that calls ShopifyClient.loadCollections
    server.tool(
      "get-collections",
      "Get all collections",
      {
        limit: z
          .number()
          .optional()
          .default(10)
          .describe("Maximum number of collections to return"),
        name: z.string().optional().describe("Filter collections by name"),
      },
      async ({ limit, name }) => {
        const client = new ShopifyClient();
        try {
          const collections = await client.loadCollections(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            { limit, name }
          );
          return {
            content: [{ type: "text", text: JSON.stringify(collections, null, 2) }],
          };
        } catch (error) {
          return handleError("Failed to retrieve collections", error);
        }
      }
    );
  • Core handler logic for loading collections (both custom and smart) via Shopify REST API, handling pagination with next cursor
    async loadCollections(
      accessToken: string,
      shop: string,
      queryParams: ShopifyCollectionsQueryParams,
      next?: string
    ): Promise<LoadCollectionsResponse> {
      const nextList = next?.split(",");
      const customNext = nextList?.[0];
      const smartNext = nextList?.[1];
      let customCollections: ShopifyCollection[] = [];
      let customCollectionsNextPage;
      let smartCollections: ShopifyCollection[] = [];
      let smartCollectionsNextPage;
    
      if (customNext !== "undefined") {
        const customRes =
          await this.shopifyHTTPRequest<ShopifyCustomCollectionsResponse>({
            method: "GET",
            url: `https://${shop}/admin/api/${this.SHOPIFY_API_VERSION}/custom_collections.json`,
            accessToken,
            params: {
              limit: queryParams.limit,
              page_info: customNext,
              title: customNext ? undefined : queryParams.name,
              since_id: customNext ? undefined : queryParams.sinceId,
            },
          });
    
        customCollections = customRes.data?.custom_collections || [];
    
        customCollectionsNextPage = ShopifyClient.getShopifyOrdersNextPage(
          customRes.headers?.get("link")
        );
      }
      if (smartNext !== "undefined") {
        const smartRes =
          await this.shopifyHTTPRequest<ShopifySmartCollectionsResponse>({
            method: "GET",
            url: `https://${shop}/admin/api/${this.SHOPIFY_API_VERSION}/smart_collections.json`,
            accessToken,
            params: {
              limit: queryParams.limit,
              page_info: smartNext,
              title: smartNext ? undefined : queryParams.name,
              since_id: smartNext ? undefined : queryParams.sinceId,
            },
          });
    
        smartCollections = smartRes.data?.smart_collections || [];
    
        smartCollectionsNextPage = ShopifyClient.getShopifyOrdersNextPage(
          smartRes.headers?.get("link")
        );
      }
      const collections = [...customCollections, ...smartCollections];
    
      if (customCollectionsNextPage || smartCollectionsNextPage) {
        next = `${customCollectionsNextPage},${smartCollectionsNextPage}`;
      } else {
        next = undefined;
      }
      return { collections, next };
    }
  • TypeScript type definitions for collections query parameters, collection data, API responses, and LoadCollectionsResponse used by the tool handler
    export type ShopifyCollectionsQueryParams = {
      sinceId?: string; // Retrieve all orders after the specified ID
      name?: string;
      limit: number;
    };
    
    export type ShopifyCollection = {
      id: number;
      handle: string;
      title: string;
      updated_at: string;
      body_html: Nullable<string>;
      published_at: string;
      sort_order: string;
      template_suffix?: Nullable<string>;
      published_scope: string;
      image?: {
        src: string;
        alt: string;
      };
    };
    
    export type ShopifySmartCollectionsResponse = {
      smart_collections: ShopifyCollection[];
    };
    
    export type ShopifyCustomCollectionsResponse = {
      custom_collections: ShopifyCollection[];
    };
    
    export type LoadCollectionsResponse = {
      collections: ShopifyCollection[];
      next?: string;
    };
  • Interface definition for ShopifyClientPort.loadCollections method signature used by the tool
    loadCollections(
      accessToken: string,
      myshopifyDomain: string,
      queryParams: ShopifyQueryParams,
      next?: string
    ): Promise<LoadCollectionsResponse>;
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. 'Get all collections' implies a read operation, but it doesn't specify permissions needed, rate limits, pagination behavior, or what 'all' entails (e.g., across the entire system). The description lacks details on return format or error conditions.

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 three words, front-loading the core purpose without any wasted text. Every word earns its place, making it efficient for quick understanding.

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 and no output schema, the description is incomplete for a tool with parameters. It doesn't explain what 'collections' are in this context, how results are structured, or behavioral aspects like ordering or defaults. For a list operation with filtering parameters, more context is needed.

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 fully documents the 'limit' and 'name' parameters. The description adds no parameter-specific information beyond what's in the schema, but since the schema is comprehensive, a baseline score of 3 is appropriate.

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 all collections' clearly states the verb ('Get') and resource ('collections'), making the tool's purpose immediately understandable. It doesn't distinguish from sibling tools like 'get-products-by-collection', but it's specific enough to avoid vagueness or tautology.

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 sibling tools like 'get-products-by-collection' for filtering products by collection, or clarify if this is for listing all collections versus filtered subsets. No exclusions or prerequisites are stated.

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