Skip to main content
Glama

get-collections

Retrieve Shopify collection data using GraphQL API to manage product groupings with search and pagination controls.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
searchTitleNo
limitNo

Implementation Reference

  • The execute method containing the core logic for the get-collections tool: parses input, constructs GraphQL query variables, fetches collections from Shopify API, maps response, and handles errors.
    execute: async (input: GetCollectionsInput) => { try { const { searchTitle, limit } = input; const query = gql`${GET_COLLECTIONS_QUERY}`; const variables = { first: limit, query: searchTitle ? `title:*${searchTitle}*` : undefined }; const data = await shopifyClient.request(query, variables) as { collections: { nodes: Array<{ id: string; handle: string; title: string; updatedAt: string; descriptionHtml: string; sortOrder: string; templateSuffix: string; }>; }; }; const collections = data.collections.nodes.map(node => ({ id: node.id, title: node.title, handle: node.handle, description: node.descriptionHtml, descriptionHtml: node.descriptionHtml, updatedAt: node.updatedAt, productsCount: 0, // Assuming productsCount is not available in the new query seo: { title: node.title, description: node.descriptionHtml }, image: null, // Assuming image is not available in the new query products: [] })); return { collections }; } catch (error) { console.error("Error fetching collections:", error); throw new Error( `Failed to fetch collections: ${ error instanceof Error ? error.message : String(error) }` ); } } };
  • Zod schema defining the input parameters for the get-collections tool.
    const GetCollectionsInputSchema = z.object({ searchTitle: z.string().optional().describe("Optional search term to filter collections by title"), limit: z.number().default(10).describe("Maximum number of collections to return (default: 10)") });
  • src/index.ts:121-133 (registration)
    MCP server registration of the 'get-collections' tool, providing input schema and delegating execution to the imported getCollections.execute method.
    server.tool( "get-collections", { searchTitle: z.string().optional(), limit: z.number().default(10) }, async (args) => { const result = await getCollections.execute(args); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } );
  • GraphQL query string used by the handler to retrieve collection data from Shopify.
    const GET_COLLECTIONS_QUERY = ` query GetCollections($first: Int!, $query: String) { collections(first: $first, query: $query) { nodes { id handle title updatedAt descriptionHtml sortOrder templateSuffix } } } `;
  • src/index.ts:72-72 (registration)
    Initialization of the getCollections tool with the Shopify GraphQL client instance.
    getCollections.initialize(shopifyClient);

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/luckyfarnon/Shopify-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server