Skip to main content
Glama
amir-bengherbi

Shopify MCP Server

tag-customer

Add tags to Shopify customers to organize and segment them for targeted marketing and customer management.

Instructions

Add tags to a customer

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
customerIdYesCustomer ID to tag
tagsYesTags to add to the customer

Implementation Reference

  • Core handler implementation for tagging a Shopify customer using GraphQL 'tagsAdd' mutation.
    async tagCustomer(
      accessToken: string,
      shop: string,
      tags: string[],
      externalCustomerId: string
    ): Promise<boolean> {
      const myshopifyDomain = await this.getMyShopifyDomain(accessToken, shop);
    
      const graphqlQuery = gql`
        mutation tagsAdd($id: ID!, $tags: [String!]!) {
          tagsAdd(id: $id, tags: $tags) {
            userErrors {
              field
              message
            }
            node {
              id
            }
          }
        }
      `;
    
      const res = await this.shopifyGraphqlRequest<{
        data: {
          tagsAdd: {
            userErrors: Array<{
              field: string[];
              message: string;
            }>;
            node: {
              id: string;
            };
          };
        };
      }>({
        url: `https://${myshopifyDomain}/admin/api/${this.SHOPIFY_API_VERSION}/graphql.json`,
        accessToken,
        query: graphqlQuery,
        variables: {
          id: `gid://shopify/Customer/${externalCustomerId}`,
          tags,
        },
      });
    
      const userErrors = res.data.data.tagsAdd.userErrors;
      if (userErrors.length > 0) {
        const errorMessages = userErrors.map((error) => error.message).join(", ");
        throw new Error(errorMessages);
      }
    
      return true;
    }
  • src/index.ts:243-273 (registration)
    MCP server.tool registration for 'tag-customer', including inline handler and Zod input schema.
    server.tool(
      "tag-customer",
      "Add tags to a customer",
      {
        customerId: z.string().describe("Customer ID to tag"),
        tags: z.array(z.string()).describe("Tags to add to the customer"),
      },
      async ({ customerId, tags }) => {
        const client = new ShopifyClient();
        try {
          const success = await client.tagCustomer(
            SHOPIFY_ACCESS_TOKEN,
            MYSHOPIFY_DOMAIN,
            tags,
            customerId
          );
          return {
            content: [
              {
                type: "text",
                text: success
                  ? "Successfully tagged customer"
                  : "Failed to tag customer",
              },
            ],
          };
        } catch (error) {
          return handleError("Failed to tag customer", error);
        }
      }
    );
  • TypeScript interface definition (schema) for the tagCustomer method in ShopifyClientPort.
    tagCustomer(
      accessToken: string,
      myshopifyDomain: string,
      tags: string[],
      customerId: string
    ): Promise<boolean>;

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/amir-bengherbi/shopify-mcp-server'

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