Skip to main content
Workflows Library MCP Directory Realtime AI News Sponsor Tier Subscribe
Front Page / AI Tools / Deep Dive

Build a DearAgent Email MCP Server: Self-Hosted Email Inbox for AI Agents with Cloudflare Workers [2026]

Build DearAgent Email MCP Server: self-hosted email inbox API for AI agents using Cloudflare Workers and FastMCP. Open-source alternative to AgentMail.

Marcus Vance

Marcus Vance

Head of Protocol Engineering

Sep 12, 2026 Published
|
Sep 12, 2026 Updated
|
7 Minutes Reading Time

DearAgent is an open-source email inbox API for AI agents, self-hosted on Cloudflare Workers. With 20 GitHub stars since its September 2026 launch, it provides an MCP server that gives AI agents read and send access to email through a clean, secure API -- an alternative to commercial services like AgentMail.

This post builds the DearAgent MCP server from scratch: the Cloudflare Workers email worker, the MCP server wrapper, authentication and security considerations, and integration patterns for AI agents that need email access.


Why Email MCP Matters

Email remains the most universal communication protocol for business workflows. AI agents that can read, send, and manage email can automate customer support, lead qualification, invoice processing, and project coordination. However, email APIs are notoriously complex -- IMAP and SMTP require specialized configuration, and OAuth flows for Gmail and Outlook are non-trivial.

DearAgent solves this by providing a purpose-built email API designed for AI agent consumption: simple REST endpoints, API-key authentication, and an MCP server that translates between the email protocol and the MCP tool interface.

The Architecture

DearAgent uses a two-component architecture. The Cloudflare Workers Email Worker receives and forwards email, storing it in a KV namespace. The MCP Server wraps the email API as MCP tools, exposing tools for reading inbox messages, searching email, sending messages, and managing email threads.

Step 1: Cloudflare Workers Email Worker

The email worker captures incoming email through Cloudflare's email binding, stores the email content in a KV namespace for persistence, and optionally forwards it to your primary inbox. A fetch handler exposes REST endpoints for sending email and reading the inbox. Authentication is handled through a pre-shared API key stored as a Cloudflare secret.

Step 2: FastMCP Email Server

The MCP server wraps the DearAgent email API using FastMCP decorators. It defines three tools: read_inbox returns the most recent emails from the configured inbox, send_email sends an email from the AI agent's configured address, and search_emails filters emails by subject or sender. Each tool makes HTTP requests to the Cloudflare worker endpoint.

Step 3: Self-Hosted Deployment

DearAgent deploys on Cloudflare Workers free tier, which handles up to 100,000 requests per day at no cost. Clone the repository, configure environment secrets (API_KEY, FORWARD_TO), and deploy using the wrangler CLI. The deployment takes approximately 10 minutes including Cloudflare KV namespace setup.

Step 4: Email Forwarding Configuration

To receive email through DearAgent, configure your domain's MX records to point to Cloudflare's email routing service. Add an MX record with priority 10 pointing to mx.cloudflare.com, configure email routing in the Cloudflare Dashboard to route incoming email to your worker, and set up email forwarding for specific addresses. The MX propagation takes about 15 minutes.

Security Considerations

DearAgent's security model uses API-key authentication for every request. The inbox read tool works without any write access by default to prevent accidental email sends. The send_email tool requires explicit subject and body parameters with no accidental reply or draft functionality. All data stays in your Cloudflare KV namespace, never touching a third-party service.

The BankMCP Server follows a similar read-only-by-default pattern for sensitive data access. DearAgent extends this approach to email, one of the most sensitive data sources an AI agent can access.

Practical Workflows

With DearAgent connected, AI agents can automate customer support triage by reading incoming support emails, categorizing by urgency, and drafting responses. They can process invoices by scanning invoice emails, extracting payment details, and updating accounting records. They can handle meeting scheduling by reading scheduling requests, checking availability, and sending calendar invitations. They can qualify leads by monitoring a lead inbox, scoring incoming inquiries, and routing qualified leads to sales.

Each workflow uses the same two MCP tools combined with domain-specific logic in the agent's LangGraph workflow.

Comparison with AgentMail

DearAgent is the open-source alternative to AgentMail, a commercial email API for AI agents. DearAgent is free and self-hosted with unlimited email accounts per domain, while AgentMail costs $20 per month for a single inbox. DearAgent requires a custom domain and 30 minutes of setup time, while AgentMail can be configured in 5 minutes.

For teams that need email MCP at scale or operate in regulated industries where data residency matters, DearAgent's self-hosted model is the better choice. For individual developers who want the fastest setup, AgentMail's zero-configuration approach wins. The Remote MCP Servers Hub catalog includes both DearAgent and AgentMail, letting developers choose based on their deployment preferences.

Email Threading and Context Management

One important feature DearAgent handles well is email threading. When an AI agent sends a reply, the worker associates it with the original thread by tracking the In-Reply-To and References headers. This lets agents maintain coherent email conversations across multiple turns, essential for customer support and project coordination workflows.

The threading support complements the MCP Analytics Server approach to session management -- each email thread is treated as a session with its own context, allowing agents to pick up conversations where they left off.

Rate Limiting and Abuse Prevention

Email MCP servers face a unique abuse vector: an AI agent that goes rogue could send spam emails or exfiltrate your inbox contents. DearAgent implements three rate limiting mechanisms:

Per-agent rate limiting: Each API key has a configurable rate limit. The default is 100 email reads and 20 email sends per hour. This prevents any single agent from overwhelming the system or sending excessive emails.

Send confirmation threshold: Outgoing emails to new recipients (addresses not previously seen in the inbox) require a secondary confirmation step. The agent sends the email to a draft queue, and a human must approve it before delivery. Emails to known contacts pass through automatically.

Content scanning: Outgoing emails are scanned against spam patterns and sensitive data leakage rules. If an email contains credit card numbers, passwords, or API keys, the send is blocked and the agent is notified. This is the same approach used by the Geiger MCP Scanner for detecting sensitive credentials in MCP server configurations.

Handling Multiple Email Addresses

DearAgent supports multiple email addresses per domain through the Cloudflare email routing configuration. Each address can be mapped to a different API key, allowing different agents to access different inboxes. A customer support agent could monitor support@domain.com while a sales agent monitors leads@domain.com, both using the same DearAgent worker but different API keys.

The multi-address support is critical for organizations that want to deploy multiple AI agents with different email responsibilities. Each agent has scoped access to only its designated inbox, preventing cross-contamination of email data.

Testing the MCP Server

Before connecting an AI agent to your real email, test the server with a dedicated test address:

{
  "mcpServers": {
    "dearagent-test": {
      "command": "python",
      "args": ["-m", "dearagent_mcp.server"],
      "env": {
        "WORKER_URL": "https://your-worker.your-subdomain.workers.dev",
        "API_KEY": "test-key-123",
        "TEST_MODE": "true"
      }
    }
  }
}

In test mode, emails are logged but never actually sent. This lets you verify that your agent's email workflow works correctly before enabling real sending capability. The test mode also generates mock responses so you can validate the full send-receive cycle without needing a second email address.

Production Hardening

For production deployment, add monitoring and alerting to your DearAgent setup:

  1. Set up Cloudflare Worker analytics to track request volume, error rates, and latency
  2. Configure alerts for sudden spikes in send volume (potential abuse indication)
  3. Implement email content backup to Cloudflare R2 for long-term retention
  4. Rotate API keys monthly using automated key rotation

Production hardening follows the same pattern as the Google SEO & GEO MCP Server, which uses Google service account credentials with automatic rotation and monitoring.

The Future of Agent Email

DearAgent is part of a broader trend: purpose-built communication APIs designed for AI agent consumption rather than human users. Traditional email protocols assume a human reading and composing messages. Agent protocols assume automated processing, structured data extraction, and programmatic responses.

As more AI agents gain email access, the volume of agent-to-human and agent-to-agent email will grow significantly. DearAgent's self-hosted model ensures that this growth doesn't require paying per-message fees to commercial providers -- a critical consideration for teams running large-scale agent deployments. By @deepakb.

Executive Briefing

Enjoyed this breakdown? Get our morning dispatch in your inbox.

Curated breakdowns of frontier model architectures and compute markets delivered every weekday. Zero fluff.

🎉 Thank You for Subscribing!

Marcus Vance
Author Profile

Marcus Vance

Head of Protocol Engineering

Marcus Vance specializes in the Model Context Protocol (MCP), FastMCP tooling, Claude Desktop integrations, and secure agent RPC transports.

Related Intelligence Analysis

Briefing AI Tools

Vercel AI SDK Tool Calling React: 5 Steps (2026)

Vercel AI SDK tool calling React integration is a programming pattern that executes server-side functions based on large language model decisions and streams the results to a React frontend. By combining streamText with...

Marcus Vance Marcus Vance
12m read
Breaking AI Tools

Fact-Density vs. Word Count: The New SEO for 2026

Fact Density is the ratio of verifiable, unique information to the total word count of a piece of content. In 2026, AI search engines like Perplexity and Gemini prioritize high fact density over traditional word count. A...

Marcus Vance Marcus Vance
4m read
Audio Briefing
Accessibility Preferences
High Contrast Mode
Accessible Reading Font

Keyboard Shortcuts

Open Search Dialog ⌘K or /
Toggle Theme (Dark/Light) t
Toggle Audio Player a
Open Shortcuts Menu ?
Close Active Dialog Esc