← All guides marginal.sh

How to Track Email Experiment Results in Code

Updated June 2026 · Hosted email MCP server

This how-to guide shows you how to track email experiment results in code with marginal, the hosted email MCP server for AI agents. You'll launch a subject line A/B test, fetch open and click metrics, and read within-test lift — all from the same workflow your agent already runs.

What you need before you start

Tracking results in code means your AI agent calls marginal's MCP tools directly instead of clicking through a dashboard. Once your client is connected, the four tools — generate_variants, launch_test, get_results, and recommend_next — become available as functions your agent can invoke.

Step 1: Launch a test you can measure

Before you can track anything, you need a running experiment. Use generate_variants to draft subject lines, then launch_test to start a managed send. Each launch returns a test identifier — keep this ID, because it's the handle you'll use to pull results later.

Because the send is managed by marginal, open and click tracking is wired up automatically. You don't instrument anything yourself; the metrics accrue against the test ID as recipients interact with the email.

Step 2: Pull and track results with get_results

To track email experiment results in code, call get_results with the test ID from Step 1. It returns the open and click figures per variant along with within-test lift metrics, so you can see which subject line is winning relative to the control rather than reading raw counts in isolation.

Since this is a single tool call, it's easy to poll on a schedule — check results an hour after launch, then again the next morning. Your agent can compare the lift values between runs to decide whether the signal is stable enough to act on.

Step 3: Decide the next move and automate it

Tracking results is only useful if you act on them. Pass the test ID to recommend_next and marginal suggests the follow-up step based on the observed lift — for example promoting the leading subject line to the rest of your list.

This closes the loop for AI agent email marketing: generate, launch, measure, and recommend all happen as MCP tool calls. You can chain them in a single agent run so each new campaign learns from the last. See the full reference at https://marginal.sh/mcp and the docs at https://marginal.sh/docs/ for tool parameters.

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