Skip to main content
Glama

get-customers

Retrieve customer data from Shopify using a search query and limit results for targeted insights.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
limitNo
searchQueryNo

Implementation Reference

  • 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)
          }`
        );
      }
    }
  • 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";
Install Server

Other Tools

Related 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/GeLi2001/shopify-mcp'

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