Skip to main content
Glama
clavia-labs

Shopify Update MCP Server

by clavia-labs

get-collections

Retrieve Shopify collections with options to filter by name and limit results for inventory management and store organization.

Instructions

Get all collections

Input Schema

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

Implementation Reference

  • The handler function for the 'get-collections' tool. It creates a ShopifyClient instance, calls loadCollections with the provided limit and name filters, and returns the collections as JSON or an error response.
    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);
      }
    }
  • Zod schema defining the input parameters for the 'get-collections' tool: optional limit (default 10) and optional name filter.
      limit: z
        .number()
        .optional()
        .default(10)
        .describe("Maximum number of collections to return"),
      name: z.string().optional().describe("Filter collections by name"),
    },
  • src/index.ts:512-538 (registration)
    The server.tool registration for the 'get-collections' tool, including name, description, input schema, and inline handler function.
    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);
        }
      }
    );
  • The loadCollections method in ShopifyClient, which implements the core logic for fetching both custom and smart collections from Shopify's REST API, supporting limit, name filters, and pagination via 'next'.
    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 };
    }
  • Type definition for the output of loadCollections, used by the tool handler.
      collections: ShopifyCollection[];
      next?: string;
    };

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
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.