add_or_update_member
Add new subscribers or update existing ones in Mailchimp lists, manage subscription status and tags.
Instructions
Add a new subscriber or update if exists (upsert). Status: subscribed, pending, unsubscribed. Tags: comma-separated.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| list_id | Yes | ||
| Yes | |||
| status | No | subscribed | |
| first_name | No | ||
| last_name | No | ||
| tags | No |
Implementation Reference
- mcp_mailchimp/server.py:513-544 (handler)The `add_or_update_member` tool handler is implemented in `mcp_mailchimp/server.py` using `@mcp.tool()` to expose it to the MCP protocol. It performs an upsert operation on a Mailchimp list member using the Mailchimp API.
@mcp.tool() async def add_or_update_member( list_id: str, email: str, status: str = "subscribed", first_name: str = "", last_name: str = "", tags: str = "", ) -> str: """Add a new subscriber or update if exists (upsert). Status: subscribed, pending, unsubscribed. Tags: comma-separated.""" mc = get_client() h = mc.subscriber_hash(email) body: dict[str, Any] = { "email_address": email.lower().strip(), "status_if_new": status, } merge_fields: dict[str, str] = {} if first_name: merge_fields["FNAME"] = first_name if last_name: merge_fields["LNAME"] = last_name if merge_fields: body["merge_fields"] = merge_fields if tags: body["tags"] = [t.strip() for t in tags.split(",") if t.strip()] m = await mc.put(f"/lists/{list_id}/members/{h}", json=body) return _fmt({ "email": m.get("email_address", ""), "status": m.get("status", ""), "id": m.get("id", ""), "message": "Member added/updated.", })