get_segment
Retrieve a specific customer segment from Klaviyo using its ID to access targeted audience data for marketing automation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ID of the segment to retrieve |
Implementation Reference
- src/tools/segments.js:35-47 (handler)Handler function that retrieves a specific segment from the Klaviyo API using the provided ID and returns the segment data or an error.async (params) => { try { const segment = await klaviyoClient.get(`/segments/${params.id}/`); return { content: [{ type: "text", text: JSON.stringify(segment, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error retrieving segment: ${error.message}` }], isError: true }; } },
- src/tools/segments.js:32-34 (schema)Zod schema for the tool input, requiring a string 'id' parameter for the segment ID.{ id: z.string().describe("ID of the segment to retrieve") },
- src/tools/segments.js:31-49 (registration)Registers the 'get_segment' tool on the MCP server with schema, handler, and description."get_segment", { id: z.string().describe("ID of the segment to retrieve") }, async (params) => { try { const segment = await klaviyoClient.get(`/segments/${params.id}/`); return { content: [{ type: "text", text: JSON.stringify(segment, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error retrieving segment: ${error.message}` }], isError: true }; } }, { description: "Get a specific segment from Klaviyo" } );