get-customers
Retrieve customer data from Shopify using a search query and limit results for targeted insights.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | No | ||
| searchQuery | No |
Implementation Reference
- src/tools/getCustomers.ts:26-110 (handler)The execute function implementing the core logic of the get-customers tool, performing a GraphQL query to Shopify to retrieve customers based on search query and limit.execute: async (input: GetCustomersInput) => { try { const { searchQuery, limit } = input; const query = gql` query GetCustomers($first: Int!, $query: String) { customers(first: $first, query: $query) { edges { node { id firstName lastName email phone createdAt updatedAt tags defaultAddress { address1 address2 city provinceCode zip country phone } addresses { address1 address2 city provinceCode zip country phone } amountSpent { amount currencyCode } numberOfOrders } } } } `; const variables = { first: limit, query: searchQuery }; const data = (await shopifyClient.request(query, variables)) as { customers: any; }; // Extract and format customer data const customers = data.customers.edges.map((edge: any) => { const customer = edge.node; return { id: customer.id, firstName: customer.firstName, lastName: customer.lastName, email: customer.email, phone: customer.phone, createdAt: customer.createdAt, updatedAt: customer.updatedAt, tags: customer.tags, defaultAddress: customer.defaultAddress, addresses: customer.addresses, amountSpent: customer.amountSpent, numberOfOrders: customer.numberOfOrders }; }); return { customers }; } catch (error) { console.error("Error fetching customers:", error); throw new Error( `Failed to fetch customers: ${ error instanceof Error ? error.message : String(error) }` ); } }
- src/tools/getCustomers.ts:6-9 (schema)Zod input schema defining parameters for the get-customers tool: optional searchQuery and limit (default 10).const GetCustomersInputSchema = z.object({ searchQuery: z.string().optional(), limit: z.number().default(10) });
- src/index.ts:109-121 (registration)MCP server registration of the get-customers tool, using inline schema and delegating execution to the imported getCustomers.execute function.server.tool( "get-customers", { searchQuery: z.string().optional(), limit: z.number().default(10) }, async (args) => { const result = await getCustomers.execute(args); return { content: [{ type: "text", text: JSON.stringify(result) }] }; } );
- src/index.ts:65-65 (registration)Initialization of the getCustomers tool with the Shopify GraphQL client.getCustomers.initialize(shopifyClient);
- src/index.ts:12-12 (registration)Import of the getCustomers tool module.import { getCustomers } from "./tools/getCustomers.js";