add_or_update_member
Add or update a subscriber in a Mailchimp list using upsert logic. Provide email, status (subscribed, pending, unsubscribed), name, and comma-separated tags. Automatically handles new or existing members.
Instructions
Add a new subscriber or update if exists (upsert). Status: subscribed, pending, unsubscribed. Tags: comma-separated.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| list_id | Yes | ||
| Yes | |||
| status | No | subscribed | |
| first_name | No | ||
| last_name | No | ||
| tags | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- mcp_mailchimp/server.py:515-546 (handler)The 'add_or_update_member' tool handler function. Registered via @mcp.tool() decorator, it adds a new subscriber or updates an existing one (upsert) using Mailchimp's PUT /lists/{list_id}/members/{subscriber_hash} endpoint. Accepts list_id, email, status (default 'subscribed'), first_name, last_name, and comma-separated tags. Computes the MD5 subscriber hash using MailchimpClient.subscriber_hash.
@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.", }) - mcp_mailchimp/server.py:516-516 (registration)Registration of the 'add_or_update_member' tool via the @mcp.tool() decorator on line 515.
async def add_or_update_member( - mcp_mailchimp/server.py:549-555 (helper)The 'archive_member' tool references add_or_update_member in its docstring: 'They can be re-added later via add_or_update_member.'
@mcp.tool() async def archive_member(list_id: str, email: str) -> str: """Archive (soft-delete) a subscriber. They can be re-added later via add_or_update_member.""" mc = get_client() h = mc.subscriber_hash(email) await mc.delete(f"/lists/{list_id}/members/{h}") return _fmt({"email": email, "message": "Member archived."})