Skip to main content
Glama

create_segment

Create targeted contact segments by applying custom filters to organize newsletter recipients based on specific criteria like email domains or signup dates.

Instructions

Create a new contact segment with a filter.

Filter examples: {"email": {"$like": "%@example.com"}} — contacts with example.com emails {"inserted_at": {"$gt": "2026-01-01"}} — contacts added after Jan 1

Args: name: Segment name. filter: Filter JSON object for matching contacts.

Returns: The created segment record.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYes
filterYes

Implementation Reference

  • The underlying client method that performs the API call to create a segment.
    def create_segment(self, name: str, filter: dict) -> dict:
        """Create a new segment."""
        resp = self.session.post(f"{self.url}/api/v1/segments", json={"data": {"name": name, "filter": filter}},
                                headers=self._headers(), timeout=30)
        resp.raise_for_status()
        return resp.json()
  • mcp_server.py:231-247 (registration)
    The MCP tool registration and handler implementation that calls the KeilaClient.
    @mcp.tool()
    def create_segment(name: str, filter: dict) -> dict:
        """
        Create a new contact segment with a filter.
    
        Filter examples:
            {"email": {"$like": "%@example.com"}}  — contacts with example.com emails
            {"inserted_at": {"$gt": "2026-01-01"}} — contacts added after Jan 1
    
        Args:
            name: Segment name.
            filter: Filter JSON object for matching contacts.
    
        Returns:
            The created segment record.
        """
        return _client.create_segment(name=name, filter=filter)

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/gwbischof/keila-mcp'

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