Skip to main content
Glama

list_customers

Retrieve customers sorted newest first, including name, email, order count, and total spent. Filter by email, tags, order count, spending, or marketing consent to find specific customers for orders or segmentation.

Instructions

List customers in the store, newest first by creation date. Returns each customer's display name, email, lifetime order count, and total amount spent (in shop currency). Supports Shopify's customer query syntax for filtering by email, tag, order count, spend, marketing-consent, account state, and more. Cursor-paginated; pass after to advance pages. Use this to find customer GIDs before referencing them in draft orders or to segment for marketing.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
firstNoPage size (1-100).
queryNoShopify customer query syntax. Examples: 'email:*@gmail.com' (domain match), 'tag:vip' (tagged), 'orders_count:>=5' (repeat customer), 'amount_spent:>=500' (high value), 'state:enabled', 'accepts_marketing:true'. Combine with AND/OR.
afterNoCursor from the previous page's pageInfo for pagination. Omit on the first call.

Implementation Reference

  • GraphQL query used by list_customers to fetch customers (sorted newest first)
    const LIST_CUSTOMERS_QUERY = /* GraphQL */ `
      query ListCustomers($first: Int!, $after: String, $query: String) {
        customers(first: $first, after: $after, query: $query, sortKey: CREATED_AT, reverse: true) {
          edges {
            cursor
            node {
              id
              firstName
              lastName
              email
              displayName
              numberOfOrders
              amountSpent { amount currencyCode }
              createdAt
            }
          }
          pageInfo { hasNextPage hasPreviousPage startCursor endCursor }
        }
      }
    `;
  • Input schema for list_customers: first (page size), query (filter string), after (pagination cursor)
    const listCustomersSchema = {
      first: z
        .number()
        .int()
        .min(1)
        .max(100)
        .default(20)
        .describe("Page size (1-100)."),
      query: z
        .string()
        .optional()
        .describe(
          "Shopify customer query syntax. Examples: 'email:*@gmail.com' (domain match), 'tag:vip' (tagged), 'orders_count:>=5' (repeat customer), 'amount_spent:>=500' (high value), 'state:enabled', 'accepts_marketing:true'. Combine with AND/OR.",
        ),
      after: z
        .string()
        .optional()
        .describe(
          "Cursor from the previous page's pageInfo for pagination. Omit on the first call.",
        ),
    };
  • Tool handler for list_customers — executes the GraphQL query, formats results with name, email, order count, and spend
    server.tool(
      "list_customers",
      "List customers in the store, newest first by creation date. Returns each customer's display name, email, lifetime order count, and total amount spent (in shop currency). Supports Shopify's customer query syntax for filtering by email, tag, order count, spend, marketing-consent, account state, and more. Cursor-paginated; pass `after` to advance pages. Use this to find customer GIDs before referencing them in draft orders or to segment for marketing.",
      listCustomersSchema,
      async (args) => {
        const data = await client.graphql<{ customers: Connection<Customer> }>(
          LIST_CUSTOMERS_QUERY,
          { first: args.first, query: args.query, after: args.after },
        );
        const lines = [
          `Found ${data.customers.edges.length} customer(s):`,
          ...data.customers.edges.map(({ node }) => {
            const name = node.displayName ?? "(no name)";
            const email = node.email ?? "(no email)";
            const orders = node.numberOfOrders ?? "0";
            const spent = node.amountSpent
              ? `${node.amountSpent.amount} ${node.amountSpent.currencyCode}`
              : "0";
            return `  ${name} <${email}> — ${orders} orders, ${spent} — ${node.id}`;
          }),
        ];
        return { content: [{ type: "text" as const, text: lines.join("\n") }] };
      },
    );
  • Registration of the list_customers tool via server.tool() including its schema and handler function
    export function registerCustomerTools(
      server: McpServer,
      client: ShopifyClient,
    ): void {
      server.tool(
        "list_customers",
        "List customers in the store, newest first by creation date. Returns each customer's display name, email, lifetime order count, and total amount spent (in shop currency). Supports Shopify's customer query syntax for filtering by email, tag, order count, spend, marketing-consent, account state, and more. Cursor-paginated; pass `after` to advance pages. Use this to find customer GIDs before referencing them in draft orders or to segment for marketing.",
        listCustomersSchema,
        async (args) => {
          const data = await client.graphql<{ customers: Connection<Customer> }>(
            LIST_CUSTOMERS_QUERY,
            { first: args.first, query: args.query, after: args.after },
          );
          const lines = [
            `Found ${data.customers.edges.length} customer(s):`,
            ...data.customers.edges.map(({ node }) => {
              const name = node.displayName ?? "(no name)";
              const email = node.email ?? "(no email)";
              const orders = node.numberOfOrders ?? "0";
              const spent = node.amountSpent
                ? `${node.amountSpent.amount} ${node.amountSpent.currencyCode}`
                : "0";
              return `  ${name} <${email}> — ${orders} orders, ${spent} — ${node.id}`;
            }),
          ];
          return { content: [{ type: "text" as const, text: lines.join("\n") }] };
        },
      );
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the burden. It discloses ordering, filtering syntax, pagination method, and returned fields. However, it doesn't mention rate limits, authentication requirements, or idempotency. Adequate but not comprehensive.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is three sentences with no waste. It front-loads the primary purpose, then adds filtering/pagination details, and closes with practical use cases. Every sentence earns its place.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given no output schema and no annotations, the description is quite complete: it specifies returned fields, ordering, filtering, pagination, and use cases. It could mention potential errors or rate limits, but for a list operation, this is sufficient.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% coverage for its 3 parameters. The description adds value by providing examples of query syntax and explaining pagination context, going beyond the schema descriptions. Baseline 3 raised to 4 for this added context.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('List customers'), the resource ('customers'), and adds ordering ('newest first by creation date') and returned fields. It distinguishes itself from sibling tools like 'create_customer' and 'update_customer' by focusing on listing.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly states when to use this tool: 'to find customer GIDs before referencing them in draft orders or to segment for marketing.' It also mentions filtering capabilities. However, it does not explicitly state when NOT to use it or provide alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/miller-joe/shopify-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server