Dev.to Security 🔐 Cybersecurity 👁 2 📖 3 min read

Building an MCP email server where the AI can't press Send

Your team already uses Claude, ChatGPT, Gemini or another assistant to write, summarise and analyse. But the information that matters most (orders, quotes, incidents, conversations with customers and suppliers) lives in

Your team already uses Claude, ChatGPT, Gemini or another assistant to write, summarise and analyse. But the information that matters most (orders, quotes, incidents, conversations with customers and suppliers) lives in email, and the assistant can't see it.

The Model Context Protocol (MCP) is a clean way to fix that. An MCP server exposes a narrow set of tools for a system, and any compatible client can use them. Build the connector once and it works with whichever assistant supports MCP, so you are not tied to one AI vendor.

The hard part isn't reading mail. It's making sure the assistant can never send, move or delete anything on its own. Here is how we approached that design.

Why generic "AI for email" fails

Off-the-shelf integrations tend to break in two places:

  1. Privacy. Many require forwarding mail to an external service or granting a third-party platform full mailbox access.
  2. Control. An assistant that sends messages by itself is a risk no serious organisation should accept.

So the goal was a connector that runs on the company's own mail server, reads mailboxes in place with no forwarding or intermediary service, and treats every write as something a human signs off.

Split the tools by risk

One function per tool, grouped by what they can change:

Type Tools Needs approval?
Query search by sender, subject, date or folder; read messages and attachments; summarise; list mailboxes and folders No, read-only
Compose draft, send, reply, forward Yes, every send
Attachments add files to an outgoing message, including re-attaching files from an existing email Yes, with the send
Organise create folders, move, archive, mark read/unread/flagged Yes, every action
Delete delete messages (they go to Trash and can be recovered) Yes, every action

Read tools answer directly. Anything that changes state is proposed first.

The approval contract

Every write tool takes an explicit confirmation parameter. The flow is:

  1. The assistant prepares the action and shows it in full: recipients, subject, body, attachments, or the folder and messages it will move.
  2. The user approves that specific action in the conversation.
  3. Only then does the client call the tool with confirmation set.

An illustrative call (not production code) looks like this:

{
  "tool": "send_email",
  "arguments": {
    "mailbox": "sales",
    "to": ["[email protected]"],
    "subject": "Follow-up on your quote",
    "body": "…",
    "attachments": ["quote.pdf"],
    "confirm": false
  }
}

With confirm: false the server returns a preview and does nothing. No "yes", no side effect.

A confirmation flag is a contract that the client must honour, so it is not enough on its own. The server needs backstops that hold even if a client misbehaves.

Server-side backstops

  • Least privilege. The connector runs as a dedicated system user with no administrator rights.
  • Mailboxes by configuration. Accessible mailboxes are added or removed in config; the assistant sees only those.
  • Token authentication over HTTPS. No valid token, no access. Tokens can be rotated at any time.
  • Hourly send limit. Even if something went wrong, mass sending isn't possible.
  • Everything logged. Every action with its timestamp and result, so you can reconstruct what happened and when.
  • Recoverable deletes. Deletion moves messages to Trash.

This follows the principle OWASP describes under "Excessive Agency": authorisation is enforced in the target system, not left to the model's judgement.

Deliverability is part of the job

A perfect reply is useless if it lands in spam. Check SPF (which servers may send for your domain), DKIM (the signature proving the message wasn't altered) and DMARC (what receivers should do when the other two fail). Don't stop at DNS records: send a real test message and confirm the recipient sees "pass" for all three.

What people actually ask it

  • "Summarise this week's supplier emails."
  • "Find the last quote we sent this customer and draft a follow-up with the PDF attached."
  • "Archive this month's automatic notifications."
  • "Which important emails have gone more than three days without a reply?"

It can work across several mailboxes at once, for example a personal one and a shared contact address.

Roll it out in phases

  1. Read-only pilot on a single mailbox: search, read and summarise only.
  2. Write tools with approval: drafts, sends and organisation, each confirmed.
  3. More mailboxes and training, so people learn to ask well and approve with judgement.
  4. Ongoing review of logs, limits and permissions.

For Microsoft 365 or Google Workspace, the same design applies, but the integration has to be adapted to what each platform allows.

Originally published on the TIC Place blog.

About the author's team: from Masdenverge, a village near Tarragona in Spain, TIC Place writes MCP connectors, AI agents and integrations, all deployed on infrastructure our clients control. More: ticplace.com.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.