list_shops
Retrieve a list of all shops connected to your Printify account, enabling quick management and overview of multiple stores.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "list_shops"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- src/index.ts:118-146 (registration)Registration of the 'list_shops' tool on the MCP server. It has no input schema (empty object {}) and dynamically imports and calls listPrintifyShops from the printify-shops service.
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 }; } } ); - src/services/printify-shops.ts:57-115 (handler)The handler function 'listPrintifyShops' that executes the tool logic. It calls printifyClient.getShops() to fetch shops, identifies the currently selected shop, and returns a formatted text response listing all available shops.
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/printify-api.ts:135-160 (helper)The getShops() method on the PrintifyAPI class, which is called by the handler to fetch shops from the Printify API via the SDK's shops.list() method.
async getShops() { try { console.log('Fetching shops from Printify API...'); try { const shops = await this.client.shops.list(); console.log('Shops response:', shops); if (shops && Array.isArray(shops)) { return shops; } else { console.warn('No shops found in the Printify API response'); return []; } } catch (sdkError) { console.error('Error fetching shops from Printify API:', sdkError); // Return the mock shops we created during initialization console.log('Returning mock shops...'); return this.shops; } } catch (error) { console.error('Error fetching shops:', error); throw error; } } - src/printify-api.ts:102-110 (helper)Supporting helper methods getCurrentShopId() and getAvailableShops() used by the handler to identify the currently active shop.
// Get all available shops getAvailableShops(): PrintifyShop[] { return this.shops; } // Get the current shop ID getCurrentShopId(): string | null { return this.shopId; }