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
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| filter | Yes |
Implementation Reference
- client.py:190-195 (handler)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)