DEV Community

Cover image for Building an AI Agent That Sends Email Through MCP
Rabbani
Rabbani

Posted on Edited on

Building an AI Agent That Sends Email Through MCP

Most AI agents can reason about email but can't send any. The usual fix is a custom wrapper around an email API: a function schema, some glue code, error handling, and a prompt describing the fields. It works, but it's a lot of code to maintain for a capability that should be routine.

The Model Context Protocol (MCP) changes this. If an email service exposes an MCP server, any MCP-capable client (Claude, Cursor, or your own agent) can discover and call its tools directly. This article walks through what that looks like with emitd, a transactional email API that hosts a native MCP endpoint, and what to think about before giving an agent the ability to send mail.

The problem with wrapper-based email tools

Hand-written tool definitions tend to drift from the API they wrap. Field names change, optional parameters get omitted, and the agent guesses at what's valid. Every new capability (checking delivery, previewing a template, managing contacts) means another hand-written tool.

An MCP server inverts this. The service publishes its own tool definitions, and the client discovers them at connection time.

What emitd exposes

emitd's hosted MCP server lives at https://mcp.emitd.com/mcp. You point an agent at it with your API key, and it receives tools already scoped to your account. According to the docs, every API call is a tool, using the API's own fields. The tools listed include:

  • send_email
  • get_message
  • preview_template
  • list_domains
  • get_stats
  • upsert_contact

The docs say the same set also covers the rest of the API, including drafting templates with the AI Design Studio and monitoring domains.

Because the tool fields mirror the REST API, the agent works with the same parameters you'd use in a direct call. For comparison, the plain REST call looks like this:

curl https://api.emitd.com/v1/email \
  -H "Authorization: Bearer $EMITD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "you@yourdomain.com",
    "to": ["ada@lovelace.io"],
    "subject": "Welcome to Acme",
    "html_body": "<h1>You are in.</h1>"
  }'
Enter fullscreen mode Exit fullscreen mode

It returns a 202 Accepted with a message_id, and the message is dispatched asynchronously.

Walkthrough: an agent sends a receipt

Once the agent is connected to the MCP endpoint, a request like this is enough:

You: Email Ada her receipt for order #4021.

The agent selects send_email and fills in the fields. This is the example the emitd site shows for that exact request:

{
  "from": "receipts@acme.com",
  "to": ["ada@lovelace.io"],
  "subject": "Your receipt for order #4021",
  "template_alias": "receipt",
  "template_model": { "total": "$48.00" }
}
Enter fullscreen mode Exit fullscreen mode

The result comes back as queued, with a message ID (the site's example shows msg_7f3a1c). The agent didn't need a custom schema or a prompt explaining the fields.

Closing the loop: let the agent check its own work

Sending is only half the job. An agent that fires off an email and assumes success is guessing. emitd's get_message tool returns the delivery timeline for a message, so the agent can find out whether the email it just sent was delivered, opened, or bounced, and act on the answer.

That enables simple, useful behaviors:

  • Confirm a critical email was delivered before telling the user it was.
  • Notice a bounce and report it instead of silently moving on.
  • Answer a user's "did my receipt go out?" with real data.

Guardrails: the part that matters most

Giving an agent an email-sending tool is different from giving it a read-only one. A mistaken tool call can't be undone, and emails can reach real people. The emitd documentation describes several controls relevant here:

  • Scoped keys. If you limit an agent's API key to specific features, the agent only sees the tools for those features. A support-triage agent doesn't need contact management, so it never sees it.
  • Dry runs. The site says dry runs apply to every call.
  • Duplicate protection. The site lists this alongside dry runs. The docs also describe idempotency keys for safe retries, which matters when an agent loops or retries after a timeout.
  • Quotas. Account quotas apply to every call, which puts a ceiling on the damage from a runaway agent.
  • Confirmation policies. The docs mention strict guardrails and human confirmation policies for agent use.

Whatever the provider offers, a sensible pattern is the same: start with a narrowly scoped key, run in dry-run mode while you test the agent's behavior, and keep a human confirmation step on anything that goes to real customers.

Beyond sending

Since the MCP server mirrors the whole API, agents can do more than send. The docs and site describe use cases such as:

  • Previewing a template before sending (preview_template)
  • Drafting on-brand templates from a prompt in the AI Design Studio
  • Upserting contacts (upsert_contact)
  • Checking account stats (get_stats) and listing sending domains (list_domains)

Trade-offs to consider

MCP is not the right choice for every situation:

  • Deterministic flows. A password reset triggered by app code should call the REST API or an SDK directly. An LLM adds latency and nondeterminism with no benefit.
  • Agentic flows. MCP fits best when the sending decision itself comes from an agent: a support assistant, an ops bot, or a workflow that decides when and what to send.

Treat the two as complementary: application code for fixed triggers, MCP for agent-driven ones.

Getting started

  1. Create an account and an API key. emitd's free tier is 5,000 emails a month with no credit card.
  2. Point your MCP client (Cursor, Claude, or a custom agent) at https://mcp.emitd.com/mcp using your API key. The emitd site provides a ready-made config snippet for Cursor and Claude Desktop.
  3. Restrict the key to the features your agent needs.
  4. Test with dry runs before sending to real addresses.

Docs: docs.emitd.com/docs/guides/agents

Disclosure: I'm a co-founder of emitd, the service discussed in this article. Figures and capabilities are as described on emitd's public site and documentation.

Top comments (0)