email-engine

mcp
Security Audit
Warn
Health Warn
  • License — License: Apache-2.0
  • Description — Repository has a description
  • Active repo — Last push 0 days ago
  • Low visibility — Only 9 GitHub stars
Code Pass
  • Code scan — Scanned 12 files during light audit, no dangerous patterns found
Permissions Pass
  • Permissions — No dangerous permissions requested

No AI report is available for this listing yet.

SUMMARY

Self-hosted event engine for any mailbox: IMAP, JMAP and inbound SMTP in, one replayable event log out, with safe reversible actions, scoped tokens for AI agents, and an MCP server.

README.md

email-engine

Connect a mailbox once. Get one stream of events out, and one safe way to act on mail back in.

Every mail provider speaks its own dialect: IMAP, JMAP, the Gmail API, Microsoft Graph. This engine sits in front of them, so your app or AI agent sees the same seven events and the same small set of actions whichever mailbox is underneath. You host it yourself: one Node process and one SQLite file. Think of it as USB for email.

flowchart LR
    subgraph MAIL["Your mailboxes"]
        direction LR
        IMAP["IMAP<br/>any provider"]
        JMAP["JMAP<br/>Fastmail, Stalwart"]
        FWD["Forwarded mail<br/>inbound SMTP"]
        GAPI["Gmail API, Graph<br/>experimental"]
    end

    subgraph ENGINE["The engine"]
        direction LR
        LOG[("Event log<br/>every change,<br/>numbered in order")]
        ACT["Actions<br/>journaled, undoable,<br/>can wait for approval"]
    end

    subgraph USERS["What you build on it"]
        direction LR
        APP["Your app<br/>HTTP, SSE, webhooks"]
        AGENT["AI agent<br/>over MCP"]
    end

    MAIL <-->|"changes in,<br/>actions out"| ENGINE
    ENGINE <-->|"events out,<br/>requests in"| USERS

Status: 0.1.0 beta. It passes its scenario suite against Dovecot and Stalwart. It has not yet been run against a commercial provider such as Gmail or Microsoft 365, or for longer than an hour. Read SECURITY.md before you expose it to anything.

What you get

You get What it means
One event log Every change in every mailbox becomes a numbered event. Read it by polling, Server-Sent Events or webhook, and replay from any number after being offline.
Safe actions Move, flag, tag, delete, draft, send and timers. A repeated request never runs twice, each action is written to a journal, and moves, flags, tags, deletes, drafts and timers can be undone.
An approval queue A token can be propose-only: its writes wait in a queue until someone else with approval rights says yes. Sending and deleting wait for approval from every token except the admin's.
Scoped tokens Each app or agent gets a token naming the accounts, folders, events and actions it may touch. A token can also mask one-time codes and card numbers in message bodies and snippets.
No model inside The engine is deterministic. A trust level per message comes from the DMARC and DKIM results and from prior correspondence, never from a language model.

An event is plain JSON. This example is shortened and its values are illustrative:

{
  "cursor": 42,
  "type": "message.received",
  "account": "acc_…",
  "occurred_at": "2026-10-06T20:35:21.597Z",
  "payload": {
    "message_id": "msg_…",
    "thread_id": "thr_…",
    "subject": "Invoice 12",
    "snippet": "Please find attached…",
    "trust": "known",
    "has_attachments": true
  }
}

How an agent works with it

The agent never talks to the mail server. It reads events, asks the engine for an action, and the engine decides whether that happens now or waits for a person.

sequenceDiagram
    autonumber
    participant M as Mail server
    participant E as The engine
    participant A as AI agent
    participant H as You

    M-->>E: new mail arrives
    E-->>A: message.received
    A->>E: move it to Invoices
    Note over E: The agent's token is propose-only,<br/>so nothing touches the mailbox yet
    E-->>H: action.updated (proposed)
    H->>E: approve
    E->>M: move the message
    E-->>A: action.updated (executed)
    H->>E: undo
    E->>M: move it back

"You" here means an API call made with the admin token, or with a separate token that names approve. There is no approval screen yet.

Quick start

You need Node 22 or newer, and Docker for the bundled test mail server.

npm install
npm run build

docker compose up -d              # local test mail servers: Dovecot and Stalwart
node test/seed.mjs alice 6        # six test messages on Dovecot for user "alice", password "pass"

ENGINE_TOKEN=test node dist/index.js

In a second terminal, connect the mailbox and read the log:

curl -X POST http://127.0.0.1:8080/accounts \
  -H "authorization: Bearer test" -H "content-type: application/json" \
  -d '{"provider":"imap","address":"[email protected]",
       "imap":{"host":"127.0.0.1","port":993,"secure":true,"user":"alice","pass":"pass","insecure_tls":true}}'

node test/events.mjs 0        # pretty-print the event log
node test/smoke.mjs           # end-to-end check: push, actions, undo, proposals, timers, SSE, tokens

To connect a real mailbox, see Providers.

Use it from Claude Desktop or any MCP client

The engine ships its own MCP server with 19 tools: search, read, move, flag, tag, draft, send, and the approve, reject and undo controls. It holds one scoped token, and whatever that token may see and do is exactly what the agent may see and do.

First create a token for the agent. A propose-only token can never approve or undo anything, and no scoped token can approve its own proposal, so the agent cannot let itself through.

curl -X POST http://127.0.0.1:8080/tokens -H "authorization: Bearer test" -H "content-type: application/json" -d '{
  "name": "my-agent",
  "actions": ["search", "get_message", "get_thread", "get_action", "propose", "move", "set_flags", "tag", "create_draft"],
  "redact": ["otp", "card"], "mode": "propose_only"
}'

Then add this to your MCP client's configuration, with the secret the call returned:

{
  "mcpServers": {
    "email-engine": {
      "command": "node",
      "args": ["C:/path/to/email-engine/dist/mcp.js"],
      "env": { "ENGINE_URL": "http://127.0.0.1:8080", "ENGINE_MCP_TOKEN": "tok_..." }
    }
  }
}

The full tool list is in the Reference.

What it has been tested against

The same scenarios run against every server on a fresh engine, with mail changed behind the engine's back. The full matrix, with latencies and each server's quirks, is in the conformance report.

Server How it connects Result
Dovecot 2.4 IMAP Every scenario that applies passes. Sending is not exercised on this target.
Stalwart 0.13.3 IMAP, IMAP with OAuth, JMAP Every scenario passes, including sending to another mailbox.
The engine's own SMTP listener Forwarded mail Every scenario that applies passes. Read-only by nature.
Gmail API, Microsoft Graph Mock servers only The sync logic passes against mocks. No live run yet.
Gmail, Microsoft 365, other hosted providers IMAP with OAuth Not yet run. This is the most useful thing you can contribute.

Documentation

  • Reference: HTTP routes, events, actions, scoped tokens, the MCP tools, configuration.
  • Providers: JMAP, forwarded mail, OAuth for Gmail and Microsoft 365, the Gmail API and Graph, how credentials are stored.
  • Testing and conformance: the scenario suite, running it against your own provider, the code layout, and the mail-server lessons learned so far.
  • spec/: JSON Schemas for events, actions, tokens and capabilities.
  • SECURITY.md: what is protected and what is not.

Not yet

  • A body and attachment cache. Every fetch re-reads the message source today.
  • Webhook signatures and a retry queue.
  • STARTTLS on the inbound listener.
  • Gmail Pub/Sub push and Graph change notifications. Both poll today.
  • Graph child folders.
  • Live runs against commercial providers, and a soak run measured in days.

Contributing

The shortest useful contribution is a conformance run against a mail server this project has not seen. The longest is a new adapter. CONTRIBUTING.md explains both.

Licence

Apache-2.0. No contributor licence agreement: you keep your copyright and license your contribution under Apache-2.0 by submitting it.

Reviews (0)

No results found