Home
Docs
Developer Documentation

Build with Mailathon

Intent in, verified email out. Connect your agents via MCP or REST, leverage the provider adapter framework, and let Mailathon handle brand compliance, deliverability, and rendering.

Quickstart

1. Install the MCP server

terminal
cd mcp
pip install -e .

2. Configure environment

.env
MAILATHON_API_BASE_URL=http://localhost:8000
MAILATHON_WEB_BASE_URL=http://localhost:3000
MAILATHON_AUTH_TOKEN=your-token-here

3. Run the server

terminal
# stdio transport (Claude Desktop, Cursor)
python server.py

# SSE transport (web-based MCP clients)
python server.py --sse

4. Add to Claude Desktop

~/.claude/claude_desktop_config.json
{
  "mcpServers": {
    "mailathon": {
      "command": "python",
      "args": ["/path/to/mailathon-web/mcp/server.py"],
      "env": {
        "MAILATHON_API_BASE_URL": "http://localhost:8000",
        "MAILATHON_WEB_BASE_URL": "http://localhost:3000",
        "MAILATHON_AUTH_TOKEN": "your-token-here"
      }
    }
  }
}

API Reference

The Mailathon API is a FastAPI service exposing intent-native email operations. All models use Pydantic v2 with extra="forbid" for strict validation.

POST/v1/emails/{task_id}/send

Send a verified email draft via a delivery provider. Self-contained - the caller provides draft, provider name, config, and recipient. No cross-service DB access needed.

Request body
{
  "draft": {
    "subject": "Welcome to Mailathon",
    "html_body": "<html>...</html>",
    "plain_body": "Welcome...",
    "from_name": "Mailathon",
    "from_email": "hello@mailathon.ai"
  },
  "provider_name": "resend",
  "provider_config": { "api_key": "re_..." },
  "recipient": "user@example.com",
  "metadata": { "campaign_id": "camp_01" }
}
Response
{
  "send_id": "msg_abc123",
  "task_id": "task_789",
  "status": "queued"
}

Core Models

EmailType

welcome, promotion, newsletter, reactivation, transactional, announcement

CampaignGoal

activate, convert, retain, upsell, educate, recover_cart

FunnelStage

awareness, consideration, conversion, onboarding, retention

ToneOverride

softer, more_direct, urgent

MCP Server

Thin HTTP proxy that exposes Mailathon's workflows to AI agents. Each tool maps 1:1 to an HTTP endpoint — no business logic lives in the MCP layer.

AI Agent←MCP→server.py←HTTP→FastAPI :8000 & Next.js :3000

Available Tools (8)

ToolTarget
generate_brand_emailAPI :8000
get_email_statusWeb :3000
get_email_resultWeb :3000
approve_emailWeb :3000
send_emailWeb :3000
get_brand_guidelinesAPI :8000
update_brand_guidelinesAPI :8000
list_templatesWeb :3000

Example Tool Call

MCP request
{
  "method": "tools/call",
  "params": {
    "name": "generate_brand_email",
    "arguments": {
      "org_id": "org_123",
      "brand_id": "brand_456",
      "intent": "announce our new product launch",
      "audience_desc": "existing customers",
      "magic_mode": false
    }
  }
}

Environment Variables

VariableDescription
MAILATHON_API_BASE_URLFastAPI backend base URL
MAILATHON_WEB_BASE_URLNext.js web app base URL
MAILATHON_AUTH_TOKENBearer token sent to both services

Integration Framework

Provider adapters — not one-off integrations. The registry pattern lets you connect once and swap freely between providers.

Delivery Providers

resend

Resend transactional email service

agentmail

AgentMail inbox + thread management

Data Providers

csv_import

CSV file import for subscriber lists

Registering a Provider

python
from integrations import registry, DeliveryProvider

class MyProvider(DeliveryProvider):
    @property
    def name(self) -> str:
        return "my_provider"

    async def send_email(self, draft, recipient, metadata=None):
        # Your delivery logic here
        ...

# Auto-registers via decorator or manual call
registry.register_provider("my_provider", MyProvider)

Troubleshooting

CONNECTION_ERROR

One of the backend services is not running. Start FastAPI (:8000) and/or Next.js (:3000).

TIMEOUT

Generation can take up to 5 minutes for complex emails. SSE stream has a 300s timeout. Check backend logs if persistent.

HTTP 401/403

Set MAILATHON_AUTH_TOKEN to a valid bearer token.

Retry behavior: requests automatically retry 3x with exponential backoff (0.5s → 4s) for 502/503/504 responses and connection errors.