list_shops
Retrieve and manage your Printify shops directly through the MCP server, enabling quick access to store details for product creation and design management.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/services/printify-shops.ts:57-115 (handler)The core handler function 'listPrintifyShops' that fetches shops from Printify API, formats them with current shop indication, and returns formatted response or error.export async function listPrintifyShops(printifyClient: PrintifyAPI) { try { // Validate client is initialized if (!printifyClient) { throw new Error('Printify API client is not initialized. The PRINTIFY_API_KEY environment variable may not be set.'); } // Get shops and current shop ID const shops = await printifyClient.getShops(); const currentShopId = printifyClient.getCurrentShopId(); if (shops.length === 0) { return { success: true, shops: [], response: { content: [{ type: "text", text: "No shops found in your Printify account." }] } }; } // Format shops for display const shopsText = shops.map((shop: any) => { const isCurrent = shop.id.toString() === currentShopId; return `${isCurrent ? '→ ' : ' '}${shop.title} (ID: ${shop.id}, Channel: ${shop.sales_channel})`; }).join('\n'); return { success: true, shops, currentShopId, response: { content: [{ type: "text", text: `Available Printify Shops:\n\n${shopsText}` }] } }; } catch (error: any) { console.error('Error listing Printify shops:', error); return { success: false, error, errorResponse: formatErrorResponse( error, 'List Printify Shops', {}, [ 'Check that your Printify API key is valid', 'Ensure your Printify account is properly connected' ] ) }; } }
- src/index.ts:118-146 (registration)MCP tool registration for 'list_shops'. Dynamically imports the handler from printify-shops service, handles client check, calls the handler, and returns the response.server.tool( "list_shops", {}, async ({}): Promise<{ content: any[], isError?: boolean }> => { // Import the printify shops service const { listPrintifyShops } = await import('./services/printify-shops.js'); // Check if client is initialized if (!printifyClient) { return { content: [{ type: "text", text: "Printify API client is not initialized. The PRINTIFY_API_KEY environment variable may not be set." }], isError: true }; } // Call the service const result = await listPrintifyShops(printifyClient); // Return the result if (result.success) { return result.response as { content: any[], isError?: boolean }; } else { return result.errorResponse as { content: any[], isError: boolean }; } } );