MCP-native email — `from mails import agent` becomes the default agent comms primitive
MCP turned tool integration into a one-line config. We shipped mails.ai as an MCP server first. Every Claude Code, Cursor, Cline, Continue, and Windsurf user gets one-step access to a working email primitive — no per-runtime SDK, no glue code, no server to host.
Deepak
Adding email to an AI agent used to mean picking an SDK, writing a wrapper, and maintaining it across every runtime you ship to. MCP changes that. You add a JSON snippet to your config and your agent has email. This post explains how the mails.ai MCP server works and what you get out of the box.
MCP turned tool integration into a one-line config. Anthropic shipped the Model Context Protocol spec in November 2024, and within six months every major agent runtime supported it — Claude Code, Cursor, Cline, Continue, Windsurf, OpenAI’s Agents SDK, the Anthropic SDK’s own MCP client. Mails.ai shipped as an MCP server first. from mailsai import agent becomes the default agent email primitive for any developer already using one of those runtimes.
MCP in one paragraph
Model Context Protocol standardizes how an agent runtime discovers and calls tools. Tool servers are processes — usually distributed via npm, run on demand — that expose a JSON schema of tool definitions. The agent runtime spawns the server process, queries list_tools, then calls any tool by name with typed arguments and gets typed results back. The model picks tools to call autonomously based on the user’s request. Network effect: every MCP-capable runtime can use any MCP server with zero per-runtime integration work. Think of it like a plugin system: you install the plugin once and every compatible editor can use it.
Why MCP-native distribution matters
The traditional alternatives to MCP both scale poorly:
- Per-language SDKs. A TypeScript SDK, a Python SDK, a Go SDK, a Java SDK, a Ruby SDK, a Rust SDK. Each maintained separately, each with its own release cadence, each with its own surface drift over time. Customers running Mastra in TS but Pydantic AI in Python need two SDK versions kept in sync.
- Per-runtime integrations. Claude Code has its own tool format. Cursor has its own. LangGraph defines tools differently. OpenAI Agents SDK uses its own schema. Building first-party integrations into every runtime is N×M engineering work that nobody wins on.
MCP collapses both. One server, every runtime. From mails.ai’s side, we maintain one tool surface. From your side, you drop one JSON snippet into your runtime config and your agent has email. You don't write any glue code, and there's nothing to keep in sync when you switch runtimes.
The distribution wedge is significant: every Claude Code user already has the runtime, already knows the config file, already has the muscle memory for adding MCP servers. The friction from “I need email in this agent” to “email is wired in” is one config edit and a restart.
The mails MCP server
The server exposes the agent-relevant slice of the mails.ai API as MCP tools:
mails_send— send an email from a named agent; returns the message id, the address it went out as and its threadmails_webhooks_create— register a webhook for structured reply events (the live event stream is no tool, as a tool call cannot stay open, andmails_events_listwithsincereads the same events)mails_list_threads— list the agent’s conversations, filtered by folder, label, read state or a searchmails_check_suppression— check whether an address is suppressed (mails_allowlist_addressoverrides that for one address)mails_get_reputation— query an agent’s reputation score (0-1), workspace-scoped (useful before processing high-stakes inbound)
All tools accept structured JSON arguments and return typed results. No raw text wrestling on either end — the structured reply events from the inbound side show up here too.
Drop-in for any MCP runtime
The full configuration:
{
"mcpServers": {
"mails": {
"command": "npx",
"args": ["-y", "@mailsai/mcp-server"],
"env": {
"MAILS_API_KEY": "mk_live_..."
}
}
}
}That same snippet works in:
- Claude Code — drop into
~/.claude.jsonundermcpServers - Cursor — drop into
~/.cursor/mcp.json - Cline (VS Code) — MCP Settings panel, paste, save
- Continue — save it as
.continue/mcpServers/mails.json; Continue calls MCP tools in Agent mode - Windsurf — MCP server registry, paste, restart
- OpenAI Agents SDK —
MCPServerStdioconstructor with the same command + args - Anthropic SDK (custom Node / Python agents) — the SDK ships MCP-client primitives that take the same shape
The server runs client-side via npx — fetched on demand, run in your local process, no infrastructure to host on your end. Restart the runtime once after the config edit and the agent has email.
What your agent gets automatically
Once configured, the runtime auto-discovers mails_* tools. The model picks them up by name and calls them when the user’s request implies email work. Your agent instructions can be as terse as:
# system prompt
You are Sarah, a support operations assistant.
Use the mails_* tools to send and read email on behalf of yourcompany.com.
For inbound replies, check injection_score before acting.That is enough. The runtime handles tool-schema marshaling, response parsing, error retry, idempotency. You write zero glue code.
The security model
- Server runs client-side. Your runtime spawns the npx server, and the API key never leaves your machine except over HTTPS to api.mails.ai. Clients that connect by URL get the same tools at
https://api.mails.ai/mcp. - Per-agent token scope. A
mk_live_xxxAPI key minted with anagent_idacts for that one agent only; without one, it covers the whole workspace. Compromised runtime → revoke that one key, mint a fresh one, agent resumes. Other agents on other keys are unaffected. - No long-lived sessions. Each tool call carries the API key in a header; we authorize per-call. No session hijack vector.
- Idempotency keys. The server attaches an idempotency key to every
sendcall: theidempotency_keythe call passes, or one of its own. Its own retries reuse that key, and a call repeated with the same key returns the first answer instead of sending a second email. - Tool-side safety:
mails_allowlist_addressrequires a written attestation of at least 20 characters;mails_sendwith a recipient on the suppression list returns a structured error rather than silently failing.
How to start
- Create an API key at
app.mails.ai/api-keys. - Copy the JSON snippet above into your runtime’s MCP config, replacing
mk_live_...with your key. - Restart your runtime.
- Ask your agent to send a test email or list its recent threads. The model will reach for
mails_*tools without further prompting.
Each agent automatically gets its own AI email address — provisioned on first send, DNS-authenticated via SPF, DKIM, and DMARC, and tied to that agent’s identity so replies route back to the right tool.
Read the architecture page for the underlying pipeline, or the structured reply events post for what the inbound webhook events actually look like once tools start firing.
The questions readers ask after this post.
Does the MCP server work without an MCP-capable runtime?
No. For non-MCP runtimes, use the TypeScript or Python SDK directly — same primitives, different transport. The MCP server depends on the runtime spawning the server process and querying its tool list, which only MCP-capable runtimes do. The SDK is what you reach for in a custom Node, Python, or Go agent loop.
Is the MCP server open source?
Yes — MIT-licensed at github.com/mailsai/mailsai, beside the SDKs, and published on npm as @mailsai/mcp-server. The server is intentionally thin: it is a tool-shape over the public REST API, with auth, retries, and idempotency keys handled in one place. Forking it to add custom tools or wrap additional endpoints is supported.
Where do tokens live?
In your runtime's MCP config — same place as any other MCP server's secrets. The MAILS_API_KEY env var stays on the machine running the agent, never sent anywhere except api.mails.ai over HTTPS. We never see your runtime config or the contents of the agent's tool calls beyond what hits our API.
Can I extend with custom tools?
There is no tool-extension SDK: the server registers its built-in tools only. The open-source server is a fork-friendly base — clone it, add your tools to the schema and dispatcher, point your runtime at the local fork. The built-in tools surface remains stable across forks.
What to read next: How every send gets routed and Four agents. One primitive.
Explore the product: MCP email server, All features and Pricing.
Live now
Ship agent email in ~6 lines.
Free tier, no card. Mint a key and drop the SDK into your agent.
