get-customers
Retrieve Shopify customer data with pagination support to manage and access customer lists efficiently.
Instructions
Get shopify customers with pagination support
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": "get-customers"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | Limit of customers to return | |
| next | No | Next page cursor |
Implementation Reference
- src/index.ts:246-269 (registration)Registration of the 'get-customers' MCP tool, including input schema (limit, next) and inline handler that delegates to ShopifyClient.loadCustomers and formats response as JSON.
server.tool( "get-customers", "Get shopify customers with pagination support", { limit: z.number().optional().describe("Limit of customers to return"), next: z.string().optional().describe("Next page cursor"), }, async ({ limit, next }) => { const client = new ShopifyClient(); try { const response = await client.loadCustomers( SHOPIFY_ACCESS_TOKEN, MYSHOPIFY_DOMAIN, limit, next ); return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }], }; } catch (error) { return handleError("Failed to retrieve customers data", error); } } ); - src/index.ts:253-268 (handler)The MCP tool handler function for 'get-customers', which instantiates ShopifyClient and calls loadCustomers.
async ({ limit, next }) => { const client = new ShopifyClient(); try { const response = await client.loadCustomers( SHOPIFY_ACCESS_TOKEN, MYSHOPIFY_DOMAIN, limit, next ); return { content: [{ type: "text", text: JSON.stringify(response, null, 2) }], }; } catch (error) { return handleError("Failed to retrieve customers data", error); } } - Core implementation of customer loading via Shopify REST API GET /customers.json with pagination (limit, page_info), extracts next page from Link header.
async loadCustomers( accessToken: string, shop: string, limit?: number, next?: string ): Promise<LoadCustomersResponse> { const res = await this.shopifyHTTPRequest<{ customers: any[] }>({ method: "GET", url: `https://${shop}/admin/api/${this.SHOPIFY_API_VERSION}/customers.json`, accessToken, params: { limit: limit ?? 250, page_info: next, fields: ["id", "email", "tags"].join(","), }, }); const customers = res.data.customers; const nextPageInfo = ShopifyClient.getShopifyOrdersNextPage( res.headers.get("link") ); return { customers, next: nextPageInfo }; } - Type definition for the response of loadCustomers: array of ShopifyCustomer and optional next page cursor.
export type LoadCustomersResponse = { customers: Array<ShopifyCustomer>; next?: string | undefined; }; - Interface definition for ShopifyClientPort.loadCustomers method signature.
loadCustomers( accessToken: string, myshopifyDomain: string, limit?: number, next?: string ): Promise<LoadCustomersResponse>;