tag-customer
Add tags to Shopify customers to organize and segment them for targeted marketing and personalized experiences.
Instructions
Add tags to a customer
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| customerId | Yes | Customer ID to tag | |
| tags | Yes | Tags to add to the customer |
Implementation Reference
- src/index.ts:271-301 (registration)Registration of the 'tag-customer' MCP tool including schema and inline handler that delegates to ShopifyClient.tagCustomerserver.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); } } );
- Core handler implementation for tagging a customer using Shopify GraphQL 'tagsAdd' mutationasync 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:274-277 (schema)Input schema using Zod for customerId (string) and tags (array of strings){ customerId: z.string().describe("Customer ID to tag"), tags: z.array(z.string()).describe("Tags to add to the customer"), },
- Interface definition for the tagCustomer method in ShopifyClientPorttagCustomer( accessToken: string, myshopifyDomain: string, tags: string[], customerId: string ): Promise<boolean>;
- src/index.ts:639-654 (helper)Utility function handleError used in the tool handler for error responsesfunction handleError( defaultMessage: string, error: unknown ): { content: { type: "text"; text: string }[]; isError: boolean; } { let errorMessage = defaultMessage; if (error instanceof CustomError) { errorMessage = `${defaultMessage}: ${error.message}`; } return { content: [{ type: "text", text: errorMessage }], isError: true, }; }