create_tag
Generate and manage tags in Klaviyo to organize customer profiles, campaigns, and marketing workflows. Supports system and custom tag types for efficient categorization.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the tag | |
| tag_type | Yes | Type of tag |
Implementation Reference
- src/tools/tags.js:36-57 (handler)Handler function that constructs the payload for creating a tag and calls klaviyoClient.post to the '/tags/' endpoint. Handles errors by returning error content.async (params) => { try { const payload = { data: { type: "tag", attributes: { name: params.name, tag_type: params.tag_type } } }; const result = await klaviyoClient.post('/tags/', payload); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error creating tag: ${error.message}` }], isError: true }; }
- src/tools/tags.js:32-35 (schema)Zod validation schema for the create_tag tool inputs: name (string) and tag_type (enum: system or custom).{ name: z.string().describe("Name of the tag"), tag_type: z.enum(["system", "custom"]).describe("Type of tag") },
- src/tools/tags.js:31-60 (registration)Direct registration of the 'create_tag' tool using server.tool(), including name, schema, handler function, and description."create_tag", { name: z.string().describe("Name of the tag"), tag_type: z.enum(["system", "custom"]).describe("Type of tag") }, async (params) => { try { const payload = { data: { type: "tag", attributes: { name: params.name, tag_type: params.tag_type } } }; const result = await klaviyoClient.post('/tags/', payload); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error creating tag: ${error.message}` }], isError: true }; } }, { description: "Create a new tag in Klaviyo" } );
- src/server.js:42-42 (registration)Top-level call to registerTagTools which includes the create_tag tool registration.registerTagTools(server);
- src/klaviyo-client.js:182-190 (helper)The post function from klaviyoClient used by the handler to make the API POST request to create the tag.export async function post(endpoint, data, fallbackFn) { return executeWithRetry( () => client.post(endpoint, data), 'POST', endpoint, data, fallbackFn ); }