slab-email
Headless email connector that lets AI agents read, search, draft, and send emails across multiple providers (Proton, IMAP/SMTP, Gmail) via REST and MCP tools, with scoped permissions and encrypted credential storage.
README
slab-email
Headless email connector for AI agents via REST and MCP.
slab-email is a local-first microservice that standardizes mailbox access behind a normalized API and MCP tool surface.
It is designed for slab-agents and other AI runtimes that need controlled access to multiple email accounts with secure credentials handling.
What is it?
slab-email is not an email UI.
It provides:
- Normalized read/search/create/send capabilities over email providers.
- Admin REST for account and access-profile management.
- MCP server for LLM/tooling clients.
- Provider-level adapters for:
- Proton via Proton Mail Bridge (mandatory).
- Generic IMAP/SMTP.
- Gmail via OAuth2 + Gmail API.
- Encrypted credential storage in SQLite.
- Scoped connector tokens with per-profile capabilities.
- Send idempotency and basic anti-loop rate limiting.
Architecture
High-level flow:
slab-agentscalls/mcpwith a scoped connector token.- REST admin endpoints configure providers and access profiles.
- Accounts are stored in SQLite; credentials are encrypted at rest.
- At request time, provider instances are created from account config + decrypted secret.
slab-emailexecutes operations against provider APIs (IMAP/SMTP or Gmail API).
slab-agents (REST/MCP) -> slab-email
|
+-> sqlite (config + encrypted secrets)
+-> providers
+ proton_bridge -> Proton Mail Bridge (local IMAP/SMTP)
+ imap_smtp -> Any IMAP/SMTP
+ gmail -> Gmail API (OAuth2)
Features
- Multi-account support:
- connect and manage multiple accounts simultaneously.
- Provider abstraction:
- Proton Bridge + IMAP/SMTP generic + Gmail.
- Connector-scoped permissions:
- read / draft / send.
- Idempotent send/reply with
idempotencyKey. - Threaded read/list payloads and full message hydration.
- Encrypted secrets using
AES-256-GCM. - Access tokens scoped to profiles.
- Admin API and MCP API separated by token requirements.
- Docker and CI ready.
Stack
- Node.js + TypeScript
- Express 5
- SQLite (
better-sqlite3) - Zod
- MCP SDK (
@modelcontextprotocol/sdk) - IMAP/SMTP:
imapflow,nodemailer - Gmail:
googleapis/google-auth-library
Quickstart
1) Start local service
npm install
cp .env.example .env
Set values in .env and run:
export SLAB_EMAIL_ADMIN_KEY=change-me
export SLAB_EMAIL_MASTER_KEY=<32-byte base64 or 64-hex key>
npm run dev
Expected:
GET /health→{"status":"ok"}./mcpavailable onPOST /mcp.
2) Register a scoped profile + token
Use admin token for account/profile management and connector token for regular usage.
Configuration
Required / relevant environment variables:
HOST(default127.0.0.1)PORT(default6981)DATABASE_PATH(default./data/slab-email.db)SLAB_EMAIL_ADMIN_KEY(required)SLAB_EMAIL_MASTER_KEY(required, 32-byte key)GOOGLE_CLIENT_IDGOOGLE_CLIENT_SECRETGOOGLE_REDIRECT_URI(defaulthttp://127.0.0.1:6981/api/oauth/google/callback)MAX_SENDS_PER_ACCOUNT_PER_HOUR(default60)MCP_ALLOWED_ORIGINS(comma-separated)MCP_ALLOWED_ORIGINS_HOSTS(comma-separated)PUBLIC_ADMIN_ALLOWED_ORIGINS(comma-separated)
See .env.example for the minimum bootstrap.
Proton Bridge setup
- Install Proton Mail Bridge.
- Add your Proton account in Bridge and copy generated IMAP/SMTP config.
- Configure
slab-emailwith that config through:POST /api/accounts/proton-bridge
- Test:
POST /api/accounts/:id/test
This project intentionally does not implement Proton login automation. Use only Bridge-generated credentials.
See docs/proton.md.
Gmail setup
- Create Google Cloud OAuth credentials.
- Set
GOOGLE_CLIENT_ID,GOOGLE_CLIENT_SECRET,GOOGLE_REDIRECT_URIin.env. - Start service.
- Use:
POST /api/accounts/gmail/connectto obtainauthorizationUrl.
- Complete OAuth in browser.
- Callback:
GET /api/oauth/google/callback
- Gmail account is stored with refresh token in encrypted DB.
See docs/gmail.md.
REST API
- Base:
GET /health/api/*POST /mcp
- Authentication:
- Admin endpoints:
Bearer <SLAB_EMAIL_ADMIN_KEY> - Operational + MCP:
Bearer <scoped connector token>
- Admin endpoints:
See docs/api.md for full request/response examples.
MCP
Endpoint: POST /mcp
Tools:
email_list_accountsemail_searchemail_get_messageemail_list_threadsemail_get_threademail_create_draftemail_sendemail_reply
See docs/mcp.md for tool payloads and usage.
Security model
SLAB_EMAIL_MASTER_KEYis required to encrypt/decrypt provider secrets.- Secrets are never returned by admin REST/MCP.
- Scoped connector tokens replace admin key in operational contexts.
- Read/write/send permissions are enforced per access profile.
- Send is idempotent by
(accountId, idempotencyKey). - Unknown send outcomes are surfaced as
SEND_OUTCOME_UNKNOWNand never auto-retried blindly. - Per-account send throttling default:
MAX_SENDS_PER_ACCOUNT_PER_HOUR. - Logs redact likely sensitive keys.
Data model
email_accounts: account metadata and provider config (without secrets).email_account_secrets: encrypted payload (username,password,refreshToken).access_profiles+access_profile_accounts.access_tokens: hashed connector tokens.send_operations: status + audit fields andidempotency_key.
See docs/architecture.md.
Docker
Dockerfilefor image build.docker-compose.ymlfor local runtime.
Note: Proton Bridge is local-first. If running Bridge outside Docker on host, configure connectivity carefully (host networking or equivalent) because the container cannot assume access to host 127.0.0.1 credentials by default.
Development
npm run dev # start with hot reload
npm test # run test suite
npm run lint
npm run typecheck
npm run build
npm start # run production bundle
Testing
Domain tests cover:
- Account lifecycle and secret encryption
- OAuth state validation
- Profile scoping and permissions
- Search/list vs get payload separation
- Send idempotency
- Unknown send outcome behavior
- MCP auth/scoping/tool execution
Limitations (MVP)
- No attachments support.
- No mailbox sync engine, local full-text search index, or webhook push sync.
- No batching/outbound campaign workflows.
- No webmail UI in this service.
slab-agents integration
If ../slab-agents exists, use docs/slab-agents-integration.md for integration contract and configuration.
License
MIT
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.