Skip to main content
Glama
clavia-labs

Shopify Update MCP Server

by clavia-labs

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
NameRequiredDescriptionDefault
customerIdYesCustomer ID to tag
tagsYesTags 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.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);
        }
      }
    );
  • Core handler implementation for tagging a customer using Shopify 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;
    }
  • 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 ShopifyClientPort
    tagCustomer(
      accessToken: string,
      myshopifyDomain: string,
      tags: string[],
      customerId: string
    ): Promise<boolean>;
  • Utility function handleError used in the tool handler for error responses
    function 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,
      };
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While 'Add tags' implies a mutation operation, it lacks details on permissions required, whether tags are appended or replaced, error handling (e.g., invalid customerId), rate limits, or response format. This is a significant gap for a mutation tool with zero annotation coverage.

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 a single, efficient sentence with zero waste. It's appropriately sized for a simple tool and front-loaded with the core action, making it easy to parse quickly.

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

Completeness2/5

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

Given this is a mutation tool with no annotations and no output schema, the description is incomplete. It doesn't explain what happens on success (e.g., returns updated customer object) or failure, nor does it cover behavioral aspects like idempotency or side effects. For a 2-parameter tool with 100% schema coverage but critical gaps in mutation context, a low score is warranted.

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

Parameters3/5

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

The schema description coverage is 100%, with both parameters (customerId and tags) clearly documented in the schema. The description adds no additional meaning beyond what the schema provides (e.g., no examples, format details, or constraints). Baseline 3 is appropriate when the schema does the heavy lifting.

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

Purpose4/5

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

The description clearly states the action ('Add tags') and target resource ('to a customer'), providing a specific verb+resource combination. However, it doesn't differentiate from potential sibling tools like 'get-customers' or other customer management tools that might exist in the broader ecosystem, though none are directly related to tagging in the provided sibling list.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., customer must exist), exclusions (e.g., cannot remove tags), or related tools (e.g., if there's a 'remove-tags' or 'update-customer' tool). Usage is implied only by the action itself.

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