Skip to main content

Building AI-Powered Email Workflows with Resend MCP and Claude Code

Updated 22 min readMarkdown
Building AI-Powered Email Workflows with Resend MCP and Claude Code

Source Code

The complete project is available on GitHub: View the Resend MCP Email Workflow Lab

A sandbox experiment: a real transactional email pipeline, an AI that operates it through MCP, and the guardrails that make that safe.

Why I Tried This

Most "AI + email" demos end when the AI sends one email. That never felt like the interesting part. In a real product, sending is one line of SDK code. The hard parts are everything around it:

  • Is the template right?
  • Did the webhook fire?
  • Why did this user never get their password reset?
  • Is the address suppressed, did the API reject the request, or did our own endpoint drop the event?

Resend publishes an official MCP server. When I listed its tools, I counted 138 of them, covering emails, templates, webhooks, logs, suppressions, domains, contacts, broadcasts, automations, and inboxes. That made me curious whether an AI coding agent could do the around work: build part of an email pipeline, then debug it like an on-call engineer.

So I built a small password-reset email service in TypeScript and connected Claude Code to Resend through MCP. I put guardrails around it, then deliberately broke the webhook to see whether Claude could explain the failure.

Constraints, because they shape everything below:

  • A brand-new Resend account
  • No verified domain
  • No real recipients. Everything goes to Resend's simulator addresses

MCP in Plain English

MCP (Model Context Protocol) is a standard way for an AI application to use external tools.

Term Meaning In this project
MCP client The AI application Claude Code
MCP server A program that exposes capabilities Resend's MCP server
Tool One action the server offers, with a name, a description and a JSON schema for its inputs list-emails, create-webhook

Under the hood, client and server exchange JSON-RPC messages:

  1. The client asks tools/list and gets back every tool's name and schema.
  2. The client puts those descriptions in front of the model.
  3. When the model decides to use a tool, the client sends tools/call with arguments.
  4. The server performs the real API request and returns the result as text.

I wanted to see this for myself rather than trust a diagram. So I started the open-source resend-mcp package locally and spoke raw JSON-RPC to it. The script is scripts/list-mcp-tools.mjs in the repo. Two things stood out:

  • Tools only. MCP has three main primitives: tools, resources and prompts. Resend's server implements only tools. Asking it for resources/list or prompts/list returns "Method not found".
  • Tools carry annotations. 56 of the 138 declare readOnlyHint: true, which is the server's own statement that they don't change anything. I used those annotations later to build the permission rules.

๐Ÿงช Check it yourself: my count comes from resend-mcp 2.29.0 on npm. Resend's docs say the hosted server runs the same open-source code, but your OAuth connection may be on a newer version. In Claude Code, run /mcp and open the Resend server. Expect roughly 138 tools with the same names.


What Resend MCP Lets Claude Code Do

The full inventory, generated from the server itself, is in docs/TOOLS.md. Grouped (counts from resend-mcp 2.29.0):

Group Tools Examples
Inboxes 30 threads, labels, drafts, replies
Contacts (incl. properties, imports, membership) 18 create, list, import CSV
Broadcasts 11 create, compose, send, click stats
Emails 10 send, batch send, get, cancel, metrics
Webhooks 10 create, list events, delivery attempts, replay
Domains 10 create, verify, DNS records
Templates 8 create, publish, duplicate
Automations 7 create, inspect runs
Segments, topics, suppressions, API keys/OAuth, logs, usage, events, editor, received email 34 get-suppression, list-logs, get-log, get-usage
Total 138

Two Ways to Connect, Two Ways to Authenticate

Resend offers a remote (hosted) server at https://mcp.resend.com/mcp and a local server (npx -y resend-mcp).

OAuth (remote server, the default). Claude Code opens a browser, you log in to Resend and approve access, and Claude Code receives a token it can use on your behalf. No secret key is pasted anywhere. This is what I use:

claude mcp add --transport http resend https://mcp.resend.com/mcp

Then run /mcp inside Claude Code, select resend, and complete the browser login.

API key. A long-lived secret (re_...), passed as an environment variable to a local server or as a Bearer header to the remote one. You need it where no browser login is possible, such as CI or a server:

bash

claude mcp add resend -e RESEND_API_KEY=re_xxxxxxxxx -- npx -y resend-mcp

Resend's own guidance is to prefer OAuth and fall back to Bearer tokens only where a browser login isn't available.

An MCP Action Is Not Your Application's Code

This distinction organises the whole project:

Claude Code via MCP Your app via the SDK
Who decides to act The model, with your approval Your code, on a user's request
Credentials Your OAuth login An API key in .env
When While you develop or debug Every time a user resets a password
Good for Templates, webhooks, investigations Sending, at runtime, reliably

I think of it as a control plane (Claude through MCP) and a data plane (the app through the SDK). The app never depends on the AI, and the AI is never in the request path.


Prerequisites

  • Node.js 20.6 or newer
  • Claude Code, with Resend MCP connected (I used the OAuth connection)
  • A Resend account and an API key for the app (Dashboard โ†’ API Keys). "Sending access" is enough.
  • cloudflared, to expose your local webhook endpoint (Step 3)
  • The project: resendwork/

โš ๏ธ Manual step: create the API key in the Resend dashboard yourself. Claude is denied create-api-key in this project on purpose, because I don't want key material in an AI conversation.

Setup

cd resendwork
npm install
cp .env.example .env     # paste your RESEND_API_KEY
npm test                 # 15 tests: guard, mailer, signed webhooks
npm run test:hook

All 25 tests pass in a clean environment, and no Resend account is involved.

Point Claude Code's guardrails at your tool names

Claude Code names MCP tools mcp__<server>__<tool>, and the <server> part depends on how you connected. This matters because a permission rule with the wrong name silently matches nothing.

Run /mcp, open Resend, and read any tool's full name. Then:

bash

node scripts/gen-claude-settings.mjs mcp__resend__   # use YOUR prefix

That writes .claude/settings.json (55 allowed read-only tools, 17 "ask first", 28 denied, plus the hook) and updates the subagent's tool list. Restart Claude Code in resendwork/.

Resend MCP connected to Claude Code over OAuth

First Contact: A Read-Only Audit

My first prompt only reads:

Audit this Resend account without changing anything. Use get-usage, list-domains,
list-emails, list-templates and list-webhooks. Tell me: plan limits, whether any
domain is verified, and what I can and can't do in this account right now.

Every one of those tools is annotated read-only, so the settings let them run without prompts.

Expected result: no domains, no templates, no webhooks, and usage near zero. Claude should conclude that sending is limited to onboarding@resend.dev. I'm deliberately not quoting plan numbers here. Check what get-usage reports for your own account.

A read-only audit: five MCP tools, zero approval โ”‚ prompts, zero changes.

Guardrails Before Workflows

An agent connected to an email account is a send button driven by natural language. I set up four independent layers before doing anything else.

Layer 1: CLAUDE.md

It states the sandbox rules in plain words. It's helpful, but only advisory.

Layer 2: Permission rules in .claude/settings.json

Rule Tools
โœ… Allowed Read-only tools
โ“ Ask first Writes such as send-email, create-template, create-webhook, replay-webhook-event
โ›” Denied Deletes, API-key and domain changes, send-broadcast

One deliberate exception: get-webhook is read-only but asks, because its output includes the webhook signing secret.

Layer 3: A send-firewall hook (.claude/hooks/send-firewall.mjs)

Claude Code runs this hook before any Resend send tool and passes the call as JSON on stdin. If the hook exits with code 2, the call is blocked and the hook's message goes back to Claude. My hook:

  • reads the same ALLOWED_RECIPIENTS as the app (default *@resend.dev);
  • walks the whole input, so to, cc, bcc, batch emails and send-event's email are all checked;
  • matches domains exactly, so x@resend.dev.attacker.com is rejected;
  • blocks tools whose recipients it can't see (send-broadcast, send-inbox-draft, reply-to-inbox-thread-email);
  • fails closed: no recognisable recipient, or unparseable input, means blocked.

The core of the hook:

export function decide(call, { rules, allowOpaque }) {
  const tool = String(call.tool_name ?? '').split('__').at(-1);
  if (OPAQUE.includes(tool)) return allowOpaque ? null : `Send firewall: ${tool} sends to recipients this hook cannot see...`;
  const recipients = collectRecipients(call.tool_input ?? {});
  if (recipients.length === 0) return `Send firewall: could not find any recipient in ${tool}; blocking to be safe.`;
  const blocked = recipients.filter((r) => !isAllowed(r, rules));
  return blocked.length ? `Send firewall: ${blocked.join(', ')} not allowed...` : null;
}

test/hook.test.mjs runs the script as a subprocess for 10 cases:

  • simulator address allowed
  • Gmail blocked
  • a hidden cc blocked
  • the look-alike domain blocked
  • a bad address inside a batch blocked
  • broadcasts blocked
  • fail-closed on empty or garbage input

Layer 4: A read-only subagent

This one is for investigations, and it comes in later.

Why the hook exists

One detail from the schema surprised me. The from, cc and bcc descriptions in send-email tell the model, in capitals, that it must ask the user for these values and never fill them in itself. It's a good server-side instinct, but it's a request to the model, not something enforced. That's exactly why the hook exists.

Prove the hook works in Claude Code itself

Send a short test email from onboarding@resend.dev to my-friend@gmail.com saying hi.

Expected result: you approve the send-email permission prompt. The hook then blocks the call with Send firewall: my-friend@gmail.com not allowed..., and Claude reports the block and suggests a simulator address.

โš ๏ธ If the email goes through, your hook matcher doesn't match your tool names. Re-run the settings generator with the right prefix.

The hook blocks a send to a real address before it reaches Resend.

The Project: Delivery Lab

I wanted one coherent workflow, not a tour of tools: a password-reset email service, plus an AI on-call engineer that can explain any delivery outcome.

Password resets are the email users notice most when they don't arrive. And Resend's simulator addresses let me produce every interesting outcome on demand, with no domain at all:

Address Simulates
delivered@resend.dev successful delivery
bounced@resend.dev hard bounce (SMTP 550 5.1.1 "Unknown User")
complained@resend.dev delivered, then marked as spam
suppressed@resend.dev suppressed send (reason: previously bounced)

They also accept labels such as bounced+run42@resend.dev, which keeps each run apart.

Architecture

                         MY LAPTOP
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                                                          โ”‚
โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        curl /timeline         โ”‚
โ”‚   โ”‚     Claude Code      โ”‚ โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”‚
โ”‚   โ”‚ rules + hook +       โ”‚                          โ”‚    โ”‚
โ”‚   โ”‚ subagent             โ”‚                          โ–ผ    โ”‚
โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜           โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
โ”‚              โ”‚                       โ”‚ Delivery Lab appโ”‚ โ”‚
โ”‚              โ”‚ MCP tools             โ”‚ Node+Resend SDK โ”‚ โ”‚
โ”‚              โ”‚                       โ””โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ฒโ”€โ”€โ”€โ”˜ โ”‚
โ”‚              โ”‚                           โ”‚         โ”‚     โ”‚
โ”‚              โ”‚                 emails.send()   events.jsonl
โ”‚              โ”‚                           โ”‚         โ”‚     โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚                           โ”‚         โ”‚
               โ–ผ                           โ”‚   โ”Œโ”€โ”€โ”€โ”€โ”€โ”ดโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                โ”‚   โ”‚ cloudflared    โ”‚
     โ”‚ Resend MCP (OAuth) โ”‚                โ”‚   โ”‚ tunnel         โ”‚
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                โ”‚   โ””โ”€โ”€โ”€โ”€โ”€โ–ฒโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
               โ”‚                           โ”‚         โ”‚
               โ–ผ                           โ–ผ         โ”‚ signed webhooks
     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” โ”‚
     โ”‚                   RESEND                    โ”‚โ”€โ”˜
     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Who does what:

  • Claude Code (MCP) creates and publishes the email template, registers the webhook, and investigates.
  • The app (SDK) sends the emails and receives webhooks.
  • The interesting part is where the two views disagree. If Resend knows an email bounced but the app never heard, something is broken. That's the kind of question I want Claude to answer.

The Implementation, Explained

The app is TypeScript on Node's built-in http module, with one runtime dependency (resend), run with tsx. The full layout is in the README.

Configuration and the recipient guard

src/config.ts reads everything from environment variables and fails with a clear message if RESEND_API_KEY is missing.

src/recipient-guard.ts is the app's own allowlist:

export function isAllowed(address: string, rules: readonly string[]): boolean {
  const addr = normalizeAddress(address);
  const domain = addr.slice(addr.lastIndexOf('@') + 1);
  return rules.some((rule) => {
    const r = rule.trim().toLowerCase();
    return r.startsWith('*@') ? domain === r.slice(2) : addr === r;
  });
}

Why have a guard in the app and a hook in Claude Code? Each covers a path the other can't see. The hook never sees SDK calls, and the guard never sees MCP calls.

Sending: template first, inline fallback

src/mailer.ts sends through the published Resend template when PASSWORD_RESET_TEMPLATE_ID is set:

const payload = this.config.passwordResetTemplateId
  ? { from, to: [to], template: { id: this.config.passwordResetTemplateId, variables }, tags }
  : { from, to: [to], subject: 'Reset your password', text, html, tags };

const { data, error } = await this.client.emails.send(payload, idempotencyKey ? { idempotencyKey } : undefined);
if (error) return { ok: false, error: `${error.name}: ${error.message}`, statusCode: error.statusCode };
  • Tags (flow=password_reset, scenario=...) make each email findable later, by me and by Claude.
  • An idempotency key means that if the scenario script is retried, Resend won't send the same email twice.
  • The SDK returns { data, error } instead of throwing, so the mailer turns errors into a result the caller must handle.
  • DRY_RUN=1 logs instead of sending.

test/mailer.test.ts uses a fake client to check that:

  • the guard runs before any API call
  • the template payload has no html
  • tags are sanitised
  • API errors are returned rather than thrown

Webhooks: verify the signature, store once

A webhook is Resend calling my server when something happens, such as "email delivered" or "email bounced". Anyone on the internet can POST to a public URL, so every webhook is signed. Resend computes an HMAC over the message id, the timestamp and the raw body, using a secret only it and I know. I recompute it, and if it doesn't match, I reject the request.

event = this.resend.webhooks.verify({
  payload: req.rawBody,   // the exact bytes; re-serialised JSON would fail
  headers: { id, timestamp, signature },
  webhookSecret: this.secret,
});

In SDK 6.39.0, webhooks.verify delegates to the standardwebhooks library. That library also rejects timestamps more than 5 minutes old or in the future, which limits replay attacks.

src/webhook-handler.ts makes two more decisions:

  • Deduplication. Every delivery carries an id (svix-id), and the store keeps each id once. A retried or manually replayed delivery gets 200 OK (otherwise Resend would keep retrying) but isn't stored twice.
  • An outage switch. SIMULATE_WEBHOOK_OUTAGE=1 makes the endpoint answer 503. That's how I break things on purpose later.

test/webhook-handler.test.ts signs real payloads with standardwebhooks and checks that:

  • a valid event is stored
  • a tampered body is rejected (400)
  • missing headers are rejected (400)
  • a duplicate delivery is acknowledged but stored once
  • an outage returns 503

Scripts

Command What it does
npm run send:scenarios Sends one password reset to each simulator address, labelled with a run id, and saves the email IDs to data/run-<id>.json
npm run report For the latest run, prints the event each email should produce and what the app actually received

Running the Experiment

Step 1: The first real send (through MCP)

Send a test email from onboarding@resend.dev to delivered@resend.dev,
subject "Delivery Lab: first send", text "Hello from Claude Code via Resend MCP."

You'll get a permission prompt (send-email is in "ask"), and the hook allows the call because the recipient matches *@resend.dev.

Expected result: the send succeeds and returns an email ID.

โš ๏ธ Open question: Resend's docs say onboarding@resend.dev can only send to your own account email. Yet Resend's own quickstart examples send from onboarding@resend.dev to delivered@resend.dev. Which rule applies to a brand-new account is unconfirmed. If you get a 403 ("You can only send testing emails to your own email address"), put your account email in OWNER_EMAIL in .env and use it for this step. Note that this limits the bounce, complaint and suppression scenarios, because they depend on the simulator addresses.

Step 2: Let Claude build the template

Create a Resend email template for a password reset:
- name "Password reset", alias "password-reset", subject "Reset your password"
- variables: USER_NAME (string, fallback "there") and RESET_URL (string)
- simple, accessible, table-based HTML plus a plain-text version
- one clear button linking to {{{RESET_URL}}}, and a line saying the link expires
Show me the HTML first. After I approve, create it and publish it, then give me the template ID.

What happens, in tool calls: create-template (the template starts as a draft), then publish-template (a template must be published before the app can send with it). Both ask first.

Two things I learned from the tool schema:

  • Variables use triple braces in HTML: {{{RESET_URL}}}.
  • FIRST_NAME, LAST_NAME, EMAIL and RESEND_UNSUBSCRIBE_URL are reserved, and declaring them causes a validation error. That's why my app uses USER_NAME.

The create-template description also ships a full checklist of email-HTML rules: table layouts, inline styles, Outlook conditionals and so on. The server is essentially teaching the model how to write email HTML.

Put the returned ID into .env as PASSWORD_RESET_TEMPLATE_ID.

Expected result: the template appears in the dashboard under Templates as published, with USER_NAME and RESET_URL listed as variables.

Created and published by Claude Code through Resend MCP;

Step 3: Run the app and register the webhook

Terminal 1:

npm run dev

Terminal 2:

cloudflared tunnel --url http://localhost:3000

cloudflared prints a public https://<random>.trycloudflare.com URL that forwards to your laptop. Resend can't reach localhost, which is why the tunnel exists. The URL changes every time you restart the tunnel.

Create a Resend webhook pointing to https://<your-tunnel>.trycloudflare.com/webhooks/resend
for these events: email.sent, email.delivered, email.delivery_delayed, email.bounced,
email.complained, email.suppressed, email.failed. Then tell me the webhook ID.

๐Ÿ” A security finding: create-webhook returns the new signing secret in its tool result (tools/webhooks.js prints Signing Secret: ...). That means the secret is now in the AI conversation. I accept that for a sandbox. Copy it into .env as RESEND_WEBHOOK_SECRET and restart npm run dev. For anything real, I'd create the webhook in the dashboard and copy the secret myself. rotate-webhook-signing-secret and get-webhook print the secret too, which is why the first is denied and the second asks.

Check the health endpoint:

curl -s localhost:3000/health

You want "webhookSecretConfigured": true.

Expected result: the webhook appears in the dashboard with the seven events, status enabled.

Step 4: Run the scenarios

npm run send:scenarios
# wait about a minute
npm run report

Expected report:

delivered   OK      expected email.delivered   saw [email.sent, email.delivered]
bounced     OK      expected email.bounced     saw [email.sent, email.bounced]
complained  OK      expected email.complained  saw [email.sent, email.delivered, email.complained]
suppressed  OK      expected email.suppressed  saw [email.suppressed]

๐Ÿ“ The exact event lists are an expectation, not observed output. The order, and the presence of email.sent, may differ in your run.

Resend's view of the same run.

Step 5: Break the webhook on purpose

Here is the scenario I actually care about. Set SIMULATE_WEBHOOK_OUTAGE=1 in .env, restart npm run dev, then:

npm run send:scenarios
npm run report        # expected: MISSING on every line

Resend now gets 503 from my endpoint. From the app's point of view, these emails vanished.

Now I ask the on-call subagent, without telling it what I did:

Use the email-oncall agent. The latest run in data/ shows MISSING for every scenario.
Did the emails go out? Why doesn't our app know what happened to them?

The subagent (.claude/agents/email-oncall.md) can only call read-only Resend tools, plus curl to the app's /timeline endpoint. Its instructions set an investigation order:

  1. API logs
  2. The email's status
  3. Suppression
  4. Webhook events
  5. Delivery attempts
  6. The app's timeline

Its answer must follow the format Verdict / Evidence / Fix / Customer reply.

These are the tools that should crack this one, according to their descriptions:

Tool What it reveals list-webhook-events Each event's status: pending, attempting, success or failed list-webhook-event-attempts What my endpoint returned on each attempt: the HTTP status and response body get-webhook-event next_attempt_at, when Resend will retry on its own

Expected result: the verdict says the emails were processed normally, but the webhook deliveries are failing because the endpoint returns 503. It quotes the body simulated outage (SIMULATE_WEBHOOK_OUTAGE=1) as evidence. The fix is to restore the endpoint, then replay the failed event IDs.

Step 6: Recover with a replay

Set SIMULATE_WEBHOOK_OUTAGE=0 and restart the app. Before replaying anything, check whether Resend's automatic retries already recovered on their own:

npm run report

Then, in the main Claude session (not the read-only subagent):

For the webhook events from the latest run that are still failed or attempting,
replay them with replay-webhook-event. List them first and wait for my approval.

According to the tool description, a manual replay is the dashboard's Replay button. It doesn't schedule further automatic retries, and the webhook must be enabled.

npm run report        # expected: OK again

Expected result: replayed events arrive and the report flips back to OK.

Two things to watch:

  1. Did automatic retries recover some events before you replayed them?
  2. If a replayed event had already arrived through a retry, the app log should show "duplicate": true and the report shouldn't double-count.

๐Ÿ“ Assumption: each replay attempt is signed with a fresh timestamp. If replays fail verification with "timestamp too old", that assumption is wrong.

Step 7 (optional): An API-level failure

This shows the other class of failure, where the email never leaves Resend. Temporarily set:

FROM_ADDRESS=Delivery Lab <hello@example.com>

example.com is a domain you haven't verified. Restart npm run dev, then run one send:

curl -s -XPOST localhost:3000/password-reset -d '{"to":"delivered@resend.dev"}'

Ask the subagent why it failed. Its first investigation step, list-logs then get-log, returns the full request and response bodies.

Expected result: a 4xx response about the unverified domain, quoted from the log. Restore FROM_ADDRESS afterwards.

Results and Observations

I established these from the server's own source and schemas, before touching the account:

  • 138 tools, tools only. There are no MCP resources or prompts.
  • Read-only annotations are reliable enough to build permissions from. 56 tools carry readOnlyHint: true.
  • Secrets can flow into the conversation. create-webhook, get-webhook and rotate-webhook-signing-secret all print the signing secret.
  • The schemas carry real domain knowledge: reserved template variables, email-HTML rules, and "ask the user for from/cc/bcc."
  • Inbox tools are present even in the local build (30 of them), although Resend's docs describe Inboxes as a remote-server feature. I confirmed only that they're present. I didn't test them.

Security Considerations

  • Prefer OAuth for the agent, and a scoped key for the app. The app's key only needs sending access.
  • Enforce with code, not prompts. The hook and permission rules worked regardless of what the model "wanted". CLAUDE.md and the tool descriptions are advisory.
  • Get the tool names right. A permission rule or hook matcher with the wrong prefix matches nothing, silently. That's why this repo generates the settings from your prefix, and why the firewall test comes before any real send.
  • Treat email content as untrusted input. Strangers write the subjects, bodies and webhook payloads. The subagent is told to treat them as data, and it physically has no send tools.
  • Webhooks: verify signatures, use the raw body, reject stale timestamps, deduplicate by delivery id, and always return 2xx for a valid event.
  • Mind where secrets end up. Signing secrets returned by tools land in the transcript. For production, handle them in the dashboard.
  • Least privilege per task. The investigator can't replay. Replays happen in the main session, behind an approval prompt.

Conclusion

Resend MCP turns the whole Resend platform into something an AI agent can operate, not just "send an email". The useful pattern I ended up with:

  • The app sends through the SDK, boringly and predictably.
  • Claude Code works on the control plane through MCP, building templates, wiring webhooks, and explaining failures.
  • Guardrails live in code: an app allowlist, a send-firewall hook, permission rules, and a subagent that can only read.

Everything here runs on a free sandbox account with no domain. The repo, including the hook, the subagent and the tests, is at [link to your repo].


Source Code

The complete project is available on GitHub: View the Resend MCP Email Workflow Lab

Sources

About the author

  • Senior Software Engineer exploring the intersection of frontend engineering, backend systems, and real-world problem solving. I write about React, TypeScript, Next.js, Node.js, NestJS, PostgreSQL, architecture, and lessons from building products.

No comments yet. Be the first to comment.