create_event
Track and log customer interactions by generating events with specified metrics, profile details, and custom properties for marketing automation via Klaviyo MCP Server.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| metric | Yes | Metric information for the event | |
| profile | Yes | Profile information for the event | |
| properties | No | Additional properties for the event | |
| time | No | ISO timestamp for the event | |
| value | No | Numeric value for the event |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"metric": {
"additionalProperties": false,
"description": "Metric information for the event",
"properties": {
"name": {
"description": "Name of the metric",
"type": "string"
}
},
"required": [
"name"
],
"type": "object"
},
"profile": {
"additionalProperties": false,
"description": "Profile information for the event",
"properties": {
"email": {
"description": "Email of the customer",
"format": "email",
"type": "string"
}
},
"required": [
"email"
],
"type": "object"
},
"properties": {
"additionalProperties": {},
"description": "Additional properties for the event",
"type": "object"
},
"time": {
"description": "ISO timestamp for the event",
"type": "string"
},
"value": {
"description": "Numeric value for the event",
"type": "number"
}
},
"required": [
"metric",
"profile"
],
"type": "object"
}
Implementation Reference
- src/tools/events.js:43-68 (handler)Handler function that formats the event payload and sends a POST request to Klaviyo's /events/ endpoint using klaviyoClient, returning the result or error.async (params) => { try { // Format payload according to the latest API structure const payload = { data: { type: "event", attributes: { metric: params.metric, profile: params.profile, properties: params.properties || {}, time: params.time || new Date().toISOString(), value: params.value !== undefined ? params.value : 0 } } }; const result = await klaviyoClient.post('/events/', payload); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error creating event: ${error.message}` }], isError: true }; }
- src/tools/events.js:32-42 (schema)Zod schema defining input parameters: metric (with name), profile (with email), optional properties, time, and value.{ metric: z.object({ name: z.string().describe("Name of the metric") }).describe("Metric information for the event"), profile: z.object({ email: z.string().email().describe("Email of the customer") }).describe("Profile information for the event"), properties: z.record(z.any()).optional().describe("Additional properties for the event"), time: z.string().optional().describe("ISO timestamp for the event"), value: z.number().optional().describe("Numeric value for the event") },
- src/tools/events.js:30-71 (registration)Registration of the create_event tool via server.tool, including name, schema, handler function, and description.server.tool( "create_event", { metric: z.object({ name: z.string().describe("Name of the metric") }).describe("Metric information for the event"), profile: z.object({ email: z.string().email().describe("Email of the customer") }).describe("Profile information for the event"), properties: z.record(z.any()).optional().describe("Additional properties for the event"), time: z.string().optional().describe("ISO timestamp for the event"), value: z.number().optional().describe("Numeric value for the event") }, async (params) => { try { // Format payload according to the latest API structure const payload = { data: { type: "event", attributes: { metric: params.metric, profile: params.profile, properties: params.properties || {}, time: params.time || new Date().toISOString(), value: params.value !== undefined ? params.value : 0 } } }; const result = await klaviyoClient.post('/events/', payload); return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error creating event: ${error.message}` }], isError: true }; } }, { description: "Create a new event in Klaviyo" } );