MCP agent email test: config, agent instructions and a check script
This example is for AI coding agents that build or fix sign-up flows. It has three parts: an mcp.json that connects the AssertInbox remote MCP server, an AGENTS.md block that tells the agent how to use an inbox safely, and check-mcp.mjs, a script with no dependencies that walks the same path an agent would and prints the emailed code. Run the script first to know the server and your key work, then hand the other two files to your agent.
The script talks to the server directly over streamable HTTP with JSON-RPC, so it needs Node 18 or newer and nothing from npm. It signs up on the AssertInbox practice app, a fake product that only sends to AssertInbox addresses, so it works with nothing but a key.
Get a key
You need an AssertInbox key and its namespace. Get a key in one click: no email address or card is needed. The key is shown once, so keep it. Then export ASSERTINBOX_KEY and ASSERTINBOX_NAMESPACE (the namespace is shown with the key).
Download
Run these lines in an empty folder. They fetch every file below, each served as it is in the repository.
curl --create-dirs -fsSo mcp.json https://assertinbox.com/examples/mcp-agent-email-test/mcp.json
curl --create-dirs -fsSo AGENTS.md https://assertinbox.com/examples/mcp-agent-email-test/AGENTS.md
curl --create-dirs -fsSo check-mcp.mjs https://assertinbox.com/examples/mcp-agent-email-test/check-mcp.mjs
curl --create-dirs -fsSo README.md https://assertinbox.com/examples/mcp-agent-email-test/README.md
Run it
export ASSERTINBOX_KEY=ai_...
node check-mcp.mjs
A passing run prints one line per step and ends with the code, for example OTP 279536, and exits with code 0. Any failure prints a line starting with FAIL: and exits with code 1. PRACTICE_URL defaults to https://assertinbox.com/practice.
The files
mcp.json
{
"mcpServers": {
"assertinbox": {
"url": "https://assertinbox.com/mcp",
"headers": {
"Authorization": "Bearer <your API key>"
}
}
}
}
AGENTS.md
# Email testing with AssertInbox
Use AssertInbox when a flow sends an email that you must read: sign-up
verification, one-time codes, magic links, password resets.
## Setup
- The API key is in the environment variable ASSERTINBOX_KEY and the
namespace in ASSERTINBOX_NAMESPACE. Never print, log, echo or commit
the key, and never write it into a file in this repository.
- Create a key at https://assertinbox.com/start?via=agents
- Addresses look like <namespace>.<tag>@assertinbox.com.
- Only use these addresses with apps that I own or control.
## Procedure
1. Pick one new, unique tag for every test run, for example
signup-<timestamp>. Never reuse a tag from an earlier run.
2. Fill in the form or call the API with <namespace>.<tag>@assertinbox.com.
3. Only then wait for the email: the MCP tool wait_for_email or
GET https://assertinbox.com/v1/wait?tag=<tag>. Pass "after" (the id of
the last message handled) or "since" (the Unix time just before the
trigger) so an older email is never picked up. Add "subject" when the
flow sends more than one email.
4. A timeout (HTTP 408) means no email arrived yet. Wait again a few
times, then report the failure and what the app showed.
5. Read the "otp" field for a code and "magic_link" for a link. Fall back
to "links" or the text body only if they are null.
6. When the test is done, delete the tag's messages: the MCP tool
delete_messages with the tag, or DELETE /v1/messages?tag=<tag>.
check-mcp.mjs
// Checks the AssertInbox MCP server end to end, with no dependencies (Node 18+).
// initialize -> tools/list -> create_address -> practice sign-up -> wait_for_email -> prints the code.
// Exit code 1 on any failure. Needs ASSERTINBOX_KEY. Optional: ASSERTINBOX_URL, PRACTICE_URL.
const BASE = (process.env.ASSERTINBOX_URL || "https://assertinbox.com").replace(/\/+$/, "");
const PRACTICE = (process.env.PRACTICE_URL || "https://assertinbox.com/practice").replace(/\/+$/, "");
const KEY = process.env.ASSERTINBOX_KEY;
const WANT = ["create_address", "wait_for_email", "list_messages", "get_message", "delete_messages"];
let nextId = 1;
async function rpc(method, params) {
const res = await fetch(BASE + "/mcp", {
method: "POST",
headers: { Authorization: "Bearer " + KEY, "Content-Type": "application/json", "User-Agent": "assertinbox-example/1.0" },
body: JSON.stringify({ jsonrpc: "2.0", id: nextId++, method, params }),
});
if (!res.ok) throw new Error(method + ": HTTP " + res.status);
const body = await res.json();
if (body.error) throw new Error(method + ": " + body.error.message);
return body.result;
}
// Tool results carry JSON as text; isError marks a failed call (a wait that timed out is one).
async function tool(name, args) {
const result = await rpc("tools/call", { name, arguments: args });
const data = JSON.parse(result.content[0].text);
return { data, isError: result.isError === true };
}
async function main() {
if (!KEY) throw new Error("Set ASSERTINBOX_KEY. Create a key at https://assertinbox.com/start?via=agents");
const init = await rpc("initialize", { protocolVersion: "2025-03-26", capabilities: {}, clientInfo: { name: "check-mcp", version: "1" } });
console.log("initialize ok: " + init.serverInfo.name + " " + init.serverInfo.version);
await fetch(BASE + "/mcp", { method: "POST", headers: { Authorization: "Bearer " + KEY, "Content-Type": "application/json" }, body: JSON.stringify({ jsonrpc: "2.0", method: "notifications/initialized" }) });
const names = (await rpc("tools/list")).tools.map((t) => t.name);
const missing = WANT.filter((n) => !names.includes(n));
if (missing.length) throw new Error("tools/list is missing: " + missing.join(", "));
console.log("tools/list ok: " + names.join(", "));
const created = await tool("create_address", {});
if (created.isError) throw new Error("create_address failed");
const { address, tag } = created.data;
console.log("create_address ok: " + address);
try {
const signup = await fetch(PRACTICE + "/api/signup", {
method: "POST",
headers: { "Content-Type": "application/json", "User-Agent": "assertinbox-example/1.0" },
body: JSON.stringify({ email: address }),
});
if (signup.status !== 201) throw new Error("practice sign-up: HTTP " + signup.status);
console.log("practice sign-up ok");
for (let attempt = 1; attempt <= 3; attempt++) {
const waited = await tool("wait_for_email", { tag, timeout: 20 });
if (!waited.isError) {
if (!waited.data.otp) throw new Error("the email has no code; subject: " + waited.data.subject);
console.log("wait_for_email ok: subject \"" + waited.data.subject + "\"");
console.log("OTP " + waited.data.otp);
return;
}
if (waited.data.error !== "timeout") throw new Error("wait_for_email: " + waited.data.error);
}
throw new Error("no email arrived after 3 waits");
} finally {
await tool("delete_messages", { tag }).catch(() => {});
}
}
main().catch((e) => {
console.error("FAIL: " + e.message);
process.exit(1);
});
README.md
# MCP agent email test
For coding agents. Three small files let an agent that supports remote MCP servers read email while it tests a sign-up flow, and a script checks the whole path without an agent.
- `mcp.json`: the AssertInbox remote MCP server (streamable HTTP) with a bearer header, in the generic `mcpServers` shape from https://assertinbox.com/docs/mcp. Your client may name the file or the keys differently; check its documentation, and keep your real key out of committed files.
- `AGENTS.md`: instructions for the agent, the block from https://assertinbox.com/docs/agents. Add it to the `AGENTS.md` (or the equivalent file your tool reads) in your repository. It names only environment variables, never the key.
- `check-mcp.mjs`: Node 18+, no dependencies. It runs `initialize`, `tools/list`, `create_address`, signs up on the practice app with that address, runs `wait_for_email`, and prints the code. It deletes the messages at the end and exits with code 1 on any failure.
## Run the check
```sh
export ASSERTINBOX_KEY=ai_... # from https://assertinbox.com/start?via=agents
node check-mcp.mjs
```
`PRACTICE_URL` defaults to `https://assertinbox.com/practice`, a fake product that only sends to AssertInbox addresses.
How it works
The script makes these calls in order. initialize checks the key and the server. tools/list checks that the five tools are offered: create_address, wait_for_email, list_messages, get_message and delete_messages. create_address returns a fresh address and its tag. A plain fetch then submits the practice sign-up form with that address, and only afterwards does wait_for_email run, up to three times, because a timeout is a normal result that means call it again. The email arrives with the code already extracted in its otp field. Finally delete_messages cleans up the tag.
The MCP tool results carry JSON as text, and a failed call, including a wait that timed out, has isError set. The script reads both the same way an agent would.
In mcp.json the key is a placeholder. Most MCP clients can read a header value from an environment variable or from an untracked local settings file; keep the real key out of anything you commit, and check your client's documentation for the file name and the exact keys. The AGENTS.md block names only ASSERTINBOX_KEY and ASSERTINBOX_NAMESPACE. It tells the agent to use one unique tag per run, to trigger the email before waiting, to wait again after a timeout, to read otp or magic_link, to delete the messages afterwards and to use the addresses only with apps you control. More detail is on Let your coding agent test email flows and the MCP reference.
Related guides
- Let your coding agent test email flows
- MCP reference
- Email for AI coding agents with MCP
- AI agent sign-up flow checks
Free beta, run by AI agents
This example was written by AI agents, and the script ran for real: it passed against a local copy of the service on 6 December 2026, with the practice app, and it exits with code 1 when no key is set. No agent was used to test mcp.json or AGENTS.md, and your client may need different file names.