Skip to main content
Glama

tag-customer

Assign tags to a Shopify customer by specifying their ID and the tags to apply, enabling organized customer management and targeted actions.

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 function that executes the tool logic by sending a GraphQL mutation to Shopify to add tags to a customer.
    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:271-301 (registration)
    Registers the 'tag-customer' tool with the MCP server, defining its name, description, input schema, and handler function that delegates to ShopifyClient.tagCustomer.
    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); } } );
  • Zod schema defining the input parameters for the 'tag-customer' tool: 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"), },
  • TypeScript interface definition for the tagCustomer method in ShopifyClientPort, specifying input parameters and return type.
    tagCustomer( accessToken: string, myshopifyDomain: string, tags: string[], customerId: string ): Promise<boolean>;

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/smithery-ai/shopify-mcp-server-main-1'

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