Skip to main content
Glama

get_segment

Retrieve a specific customer segment from Klaviyo using its ID to access targeted audience data for marketing automation.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
idYesID of the segment to retrieve

Implementation Reference

  • 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
        };
      }
    },
  • 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")
    },
  • 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" }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ivan-rivera-projects/Klaviyo-MCP-Server-Enhanced'

If you have feedback or need assistance with the MCP directory API, please join our Discord server