get-collections
Retrieve Shopify collection data using GraphQL API to manage product groupings with search and pagination controls.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| searchTitle | No | ||
| limit | No |
Implementation Reference
- src/tools/getCollections.ts:45-96 (handler)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) }` ); } } };
- src/tools/getCollections.ts:6-9 (schema)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) }] }; } );
- src/tools/getCollections.ts:16-30 (helper)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);