add_or_update_member
Add new subscribers or update existing ones in Mailchimp audiences using email as the unique identifier. Maintains current subscription status while managing contact information and tags.
Instructions
Add a new subscriber or update an existing one in a Mailchimp audience. Uses email as the unique key (upsert). Will not change subscription status of existing members.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| list_id | Yes | Audience/list ID | |
| Yes | Email address of the contact | ||
| first_name | No | First name | |
| last_name | No | Last name | |
| tags | No | Tags to apply (e.g. ['Lead', 'Strategy']) |
Implementation Reference
- server.js:349-376 (handler)The handler function for 'add_or_update_member', which processes the input parameters, hashes the email, calls Mailchimp API to set the member, and optionally applies tags.
async ({ list_id, email, first_name, last_name, tags }) => { const subscriberHash = crypto.createHash("md5").update(email.toLowerCase()).digest("hex"); const body = { email_address: email, status_if_new: "subscribed", merge_fields: {}, }; if (first_name) body.merge_fields.FNAME = first_name; if (last_name) body.merge_fields.LNAME = last_name; const result = await mailchimp.lists.setListMember(list_id, subscriberHash, body); if (tags && tags.length > 0) { await mailchimp.lists.updateListMemberTags(list_id, subscriberHash, { tags: tags.map((t) => ({ name: t, status: "active" })), }); } return { content: [ { type: "text", text: JSON.stringify( { success: true, email: result.email_address, status: result.status, is_new: result.status === "subscribed" && !result.last_changed, tags_applied: tags || [], }, null, - server.js:339-348 (registration)The registration of the 'add_or_update_member' tool, including its schema definition.
server.tool( "add_or_update_member", "Add a new subscriber or update an existing one in a Mailchimp audience. Uses email as the unique key (upsert). Will not change subscription status of existing members.", { list_id: z.string().describe("Audience/list ID"), email: z.string().describe("Email address of the contact"), first_name: z.string().optional().describe("First name"), last_name: z.string().optional().describe("Last name"), tags: z.array(z.string()).optional().describe("Tags to apply (e.g. ['Lead', 'Strategy'])"), },