如何透過 Remote MCP 為 AI 智能體配置專屬電郵收件匣並保留人工審批
Give an AI Agent a Real Email Inbox over Remote MCP (with Human Approval)
這篇教學示範如何為 AI 智能體配置專屬電郵收件匣,透過 Remote MCP 和 OAuth 連接,並以人工審批控制寄出的郵件。六種工具會按授權範圍提供,收件匣亦可設定收件人及網域的允許或封鎖清單、每日寄送上限和暫停寄送。作者建議先用無法連接互聯網的 .mail.invalid 測試收件匣跑完整流程。
By Aljay Miskino, VP of Partnerships at Email for Agents
If you have already wired an AI agent into Claude Code, Cursor, or another MCP client, the next request is often: “now let it handle email.” The usual shortcuts are to connect a personal Gmail account or to stand up a send-only API. Both work for a demo. Both get awkward in production: the agent either borrows a person’s identity, or it can send mail but cannot own a conversation.
This walkthrough shows a third shape: give the agent its own inbox, connect it over remote MCP with OAuth, and keep a human in control of what actually leaves. The examples use Email for Agents, where I work. The same design questions apply if you build the mailbox yourself.
What you end up with
- A live address on a platform domain (or a custom domain later), not a forwarding rule into your mailbox.
- A remote MCP server the client signs into with OAuth. An API key is the wrong credential for this path.
- Six tools, and only the ones the grant allows. A read-only agent does not see a send tool.
- An optional approval queue, plus allow/block lists, daily caps, and a pause switch.
- A test inbox that cannot reach the internet, so you can practice the loop in CI.
1. Create an inbox first, then connect the agent
Sign in to the console, create a project, and create an inbox in it. The address you get depends on the project’s environment:
- A test project issues a generated, non-routable address on
.mail.invalid. It uses a simulated transport. You cannot ask for a custom local part or a custom domain there — that restriction is what makes it safe to point an unproven agent at. - A live project issues a real address (for example
ada@agents.emailforagents.ai). Custom domains are a later, paid-plan step.
Do the first end-to-end test in a test project. If the agent tries to send to a real person, the message cannot leave.
2. Connect over remote MCP, not with an API key
The MCP endpoint is:
https://mcp.emailforagents.ai/mcp
Paste that URL into the client’s remote MCP settings, start the connection, and sign in in the browser window that opens. On the consent screen you pick:
- The project.
- The exact inbox or inboxes.
- A permission level: read, read and draft, or read, draft and send.
The grant expires after 30 days and can be revoked sooner. The server identifies itself as email-for-agents-mcp and expects a client that supports remote MCP and OAuth (authorization code with S256 PKCE). A project API key (efa_live_… or efa_test_…) presented at /mcp is rejected on purpose. If your client cannot do OAuth, use the REST API at https://api.emailforagents.ai/v1 instead — same permissions, same send pipeline, different credential.
No named client is certified or one-click. Claude Code, Claude Desktop, and Cursor are listed as testing targets only. Connect one, then prove a round trip in a test project before you rely on it.
3. Know the six tools, and which ones your grant can see
The server exposes six tools. A tool the grant does not cover is omitted from tools/list, not merely refused at call time.
| Tool | Needs | What it does |
|---|---|---|
list_inboxes |
read | Lists the inboxes this grant covers |
list_threads |
read | Lists conversations in one inbox |
list_messages |
read | Lists message ids, recipients, attachment metadata, and previews |
get_message |
read | Reads one message body, bounded in size |
create_draft |
draft | Composes a new message or a threaded reply. It cannot transmit mail |
send_message |
send | Transmits a message, still subject to the inbox’s approval policy |
A read grant sees four tools. Adding draft adds create_draft. Only a send grant sees send_message. Before the draft tool runs, the send scope is stripped from the calling principal, so draft access is not a side door into sending.
That filtering is the point of using MCP this way. A hostile email body is untrusted text in the model’s context. It can argue. It cannot invoke a tool the session never advertised.
4. Decide what is allowed to leave
Permission on the grant is only half of the control plane. Each inbox can also:
- Hold every outgoing message for a person to approve, reject, or replace.
- Allow or block recipients and domains.
- Cap how many recipients may be mailed in a day.
- Pause sending entirely while drafts keep waiting.
Approvals are a record with a lifecycle, not a label you invent in your own code. A held send expires if nobody acts on it (seven days in the current product). The decision is bound to the exact draft that was reviewed; if the body or recipients change, the approval does not apply to the new version.
For a support-triage agent, a typical setup is read and draft plus “ask me first.” For invoice intake that should never reply, use read only and do not grant send. For follow-ups to people you already know, you might grant send and restrict the allow list to one domain, with a daily cap.
5. Send safely when you do use the API
If you call REST instead of MCP, send with an Idempotency-Key on every request that can transmit mail. The same key and the same body return the original result. A retry does not produce a second email. A key reused with a different body is a conflict, which is almost always a bug in the client.
Treat inbound mail, links, and attachments as untrusted data. Permissions come from the grant you configured, never from the text of a message. The product does not claim to be prompt-injection proof — that is why the approval queue exists.
A short, honest checklist before you go live
- Prove the loop on a
.mail.invalidinbox first. - Grant the least access the job needs. Prefer draft-plus-approval over send.
- Confirm your MCP client completed OAuth and that
list_inboxesonly returns the inboxes you picked. - Remember the free allowance is small: one live inbox and 100 email units a month per verified owner, where a unit is one message received or one recipient sent to. Paid plans exist if you outgrow that.
- There is no published SDK today. Use MCP or plain HTTP.
If you want the worked quickstart, including client-specific setup steps, it lives in the Email for Agents docs. Read it, then run the first mail in test mode.
Aljay Miskino is VP of Partnerships at Email for Agents (emailforagents.ai).
來源:DEV Community · dev.to