get_segments
Retrieve customer segments from Klaviyo using filters and pagination to manage targeted marketing audiences.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "get_segments"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filter | No | Filter query for segments | |
| page_size | No | Number of segments per page (1-100) | |
| page_cursor | No | Cursor for pagination |
Implementation Reference
- src/tools/segments.js:13-25 (handler)Handler function that fetches segments from Klaviyo API using the klaviyoClient and returns the JSON response or an error message.
async (params) => { try { const segments = await klaviyoClient.get('/segments/', params); return { content: [{ type: "text", text: JSON.stringify(segments, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error retrieving segments: ${error.message}` }], isError: true }; } }, - src/tools/segments.js:8-12 (schema)Zod schema defining optional input parameters: filter, page_size, and page_cursor for the get_segments tool.
{ filter: z.string().optional().describe("Filter query for segments"), page_size: z.number().min(1).max(100).optional().describe("Number of segments per page (1-100)"), page_cursor: z.string().optional().describe("Cursor for pagination") }, - src/tools/segments.js:7-27 (registration)Registers the 'get_segments' tool with the MCP server, specifying name, input schema, handler function, and description.
"get_segments", { filter: z.string().optional().describe("Filter query for segments"), page_size: z.number().min(1).max(100).optional().describe("Number of segments per page (1-100)"), page_cursor: z.string().optional().describe("Cursor for pagination") }, async (params) => { try { const segments = await klaviyoClient.get('/segments/', params); return { content: [{ type: "text", text: JSON.stringify(segments, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Error retrieving segments: ${error.message}` }], isError: true }; } }, { description: "Get segments from Klaviyo" } );