How to Build a Closed-Loop Email Marketing Agent with marginal
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.
- generate_variants — produce candidate subject lines for the test
- launch_test — send the variants and start tracking
- get_results — read within-test lift, opens, and clicks
- recommend_next — turn results into the agent's next action
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.
- Endpoint: https://marginal.sh/mcp
- Auth: Bearer API key (marg_live_...)
- Registry id: sh.marginal/mcp
- Setup details: https://marginal.sh/docs/
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.
- Pass a clear campaign goal so variants stay on-message
- Keep variant count small (2–4) for cleaner lift signals
- launch_test returns an identifier the agent stores for the next step
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_results → lift, opens, clicks per variant
- recommend_next → suggested follow-up action
- Loop back to generate_variants to iterate on the winner
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.
- 100 experiments/month on the free tier
- Four MCP tools: generate_variants, launch_test, get_results, recommend_next
- Listed in the MCP Registry as sh.marginal/mcp