Skip to main content
Glama

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>;

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