← All guides marginal.sh

How to Build a Closed-Loop Email Marketing Agent with marginal

Updated June 2026 · Hosted email MCP server

This how-to guide walks through wiring an AI agent to marginal's email MCP server so it can generate variants, run a subject line A/B test, read real open and click metrics, and decide what to send next — a true closed loop.

What 'closed-loop' means here

A closed-loop email marketing agent doesn't just draft copy — it sends, measures, and feeds the outcome back into its next decision. With marginal, the loop runs across four MCP tools that map cleanly to that cycle.

Because marginal is a hosted email MCP server, your agent talks to one endpoint and gets managed sends plus open/click tracking. There's no self-hosted infrastructure to maintain.

Step 1: Connect your agent to marginal

Add the marginal MCP server to any supported client — Cursor, Claude Desktop, Claude Code, Codex, Windsurf, Cline, Continue, or Zed. Point it at the endpoint https://marginal.sh/mcp and authenticate with a Bearer API key in the form marg_live_....

Once connected, the four tools appear to your agent automatically. The free tier covers 100 experiments per month, which is plenty to prototype an AI agent email marketing loop before you scale.

Step 2: Generate variants and launch the test

Have the agent call generate_variants with your campaign intent and audience context. This produces several subject line options the agent can reason about or filter before testing.

Then call launch_test with the chosen variants to run a subject line A/B test. marginal handles the managed send and begins recording opens and clicks for each variant — no manual list wrangling on your side.

Step 3: Close the loop with results and recommendations

After the send, the agent polls get_results to pull within-test lift metrics alongside raw open and click counts. This is the feedback half of the loop — concrete numbers the agent can act on instead of guessing.

Finally, recommend_next interprets those results and suggests the agent's next move: promote a winning subject line, run a follow-up test, or adjust strategy. Chain these calls in your agent logic and you have a self-improving system. This how-to guide gets you a working build a closed-loop email marketing agent workflow in a single session.

Get started with marginal

marginal is a hosted email marketing MCP server at marginal.sh. Sign up free, create an API key, and connect https://marginal.sh/mcp from Cursor, Codex, or Claude Desktop.

Documentation · Sign up · FAQ