delete_segment
Delete a specified segment from a Mailchimp audience by providing the list ID and segment ID.
Instructions
Delete a segment from an audience.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| list_id | Yes | ||
| segment_id | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- mcp_mailchimp/server.py:1122-1127 (handler)The delete_segment tool handler function. Accepts list_id and segment_id, calls DELETE on the Mailchimp API endpoint /lists/{list_id}/segments/{segment_id}, and returns a confirmation message.
@mcp.tool() async def delete_segment(list_id: str, segment_id: str) -> str: """Delete a segment from an audience.""" mc = get_client() await mc.delete(f"/lists/{list_id}/segments/{segment_id}") return _fmt({"segment_id": segment_id, "message": "Segment deleted."}) - mcp_mailchimp/server.py:1122-1122 (registration)The @mcp.tool() decorator registers delete_segment as a tool with the FastMCP server. No schema file exists separately; the handler's signature defines the input schema.
@mcp.tool() - mcp_mailchimp/server.py:41-43 (helper)The _fmt helper function used by delete_segment to format the response as indented JSON.
def _fmt(data: Any) -> str: """Format response data as indented JSON string.""" return json.dumps(data, indent=2, default=str) - mcp_mailchimp/server.py:27-38 (helper)The get_client helper function used by delete_segment to obtain the Mailchimp API client singleton.
def get_client() -> MailchimpClient: global _client if _client is None: api_key = os.environ.get("MAILCHIMP_API_KEY", "") if not api_key or "-" not in api_key: raise ValueError( "MAILCHIMP_API_KEY environment variable required. " "Format: xxxxxxxxxx-usXX " "(get yours at https://mailchimp.com/account/api)" ) _client = MailchimpClient(api_key) return _client - mcp_mailchimp/client.py:70-71 (helper)The MailchimpClient.delete method used by delete_segment to make the HTTP DELETE request to the Mailchimp API.
async def delete(self, path: str) -> Any: return await self._request("DELETE", path)