Mailport

Mailport

Connects multiple IMAP and SMTP mailboxes to MCP clients like ChatGPT without exposing credentials, enabling email search and thread retrieval via natural language.

Category
Visit Server

README

<div align="center">

Mailport

Your inboxes. One secure MCP gateway.

Connect multiple IMAP and SMTP mailboxes to ChatGPT and other MCP clients without exposing mailbox credentials to the model.

MCP TanStack Start Neon Bitwarden License

Architecture · Security · Thread protocol · Setup

</div>

[!IMPORTANT] Mailport is a security-preview project. Its architecture is designed for production use, but it is necessary to use your own vercel, db, bitwarden etc account because otherwise I can see your passwords 😅

Why Mailport

Most email integrations are built around one provider. Mailport provides a small, provider-independent MCP boundary for Gmail, Microsoft 365, iCloud, Yahoo, Aruba and any public IMAP/SMTP server with valid TLS.

  • Credentials never enter the chat. Users add a mailbox through a short-lived HTTPS connection link.
  • Passwords stay in a vault. IMAP and SMTP credentials are separate Bitwarden Secrets Manager secrets.
  • Email stays ephemeral. Message bodies are fetched on demand and are not indexed or retained by default.
  • Threads are model-ready. RFC headers, native provider IDs and conservative heuristics reconstruct useful conversations.
  • Access is scoped. OAuth separates mail:read and mail:send; opaque account references prevent arbitrary mailbox selection.

MCP tools

Tool What it does
accounts_list Lists connected mailboxes using opaque references and masked addresses.
connection_link_create Returns a 256-bit, single-use mailbox connection link valid for ten minutes.
threads_search Searches bounded filters and reconstructs conversations across selected folders.
thread_get Produces chronological, compact context with explicit omissions and truncation.
email_send_prepare Returns the exact recipients, subject and body for explicit approval plus a five-minute token.
email_send_confirm Sends only the unchanged, explicitly approved message and consumes the token once.

Sending is text-only in the initial release. It requires mail:send, an SMTP-enabled account, an exact preview and a separate explicit confirmation. Attachments are intentionally excluded.

How it works

flowchart TD
    C["ChatGPT or MCP client"] -->|"OAuth 2.1 + scoped token"| M["Mailport on Vercel"]
    U["User in secure connection page"] -->|"IMAP / SMTP credentials"| M
    M -->|"Secret IDs and metadata"| N["Neon Postgres"]
    M -->|"Encrypted credentials"| B["Bitwarden Secrets Manager"]
    M -->|"TLS, on-demand fetch"| P["Mail providers"]

ChatGPT never receives mailbox passwords, provider tokens or arbitrary IMAP access. Neon stores ownership and non-secret metadata; Bitwarden stores the credentials; Mailport fetches messages only when an authorized tool call needs them.

Thread intelligence

Mailport reconstructs a thread in a deterministic order:

  1. Deduplicate copies using normalized RFC Message-ID values.
  2. Join provider-native thread IDs within the same account.
  3. Follow In-Reply-To and References relationships.
  4. Optionally apply a conservative subject, participant and time heuristic.

Search expansion is bounded to two rounds. Compact context keeps the first message, matching anchors and the latest messages while removing repeated quoted history. Heuristic joins are returned with an explicit confidence label instead of being presented as certain.

Security boundaries

Boundary Policy
Chat ↔ Mailport OAuth 2.1, PKCE, audience validation and scoped access tokens.
User ↔ onboarding Authenticated HTTPS page; fragment token; single use; ten-minute expiry.
Mailport ↔ Bitwarden Dedicated machine account restricted to one Secrets Manager project.
Mailport ↔ providers Verified TLS 1.2+, fixed ports, public-address validation and DNS-pinned sockets.
Mailport ↔ Neon Pooled TLS connection; no mailbox password or message body persistence.
Email ↔ model Email is untrusted data and cannot choose tools, accounts, scopes or recipients.

The application does not log passwords, OAuth tokens, subjects, message bodies, recipients or raw provider errors. See the complete security model.

Stack

  • TanStack Start and React on the Vercel Node.js runtime.
  • Official Model Context Protocol TypeScript SDK with stateless Streamable HTTP at /mcp.
  • Better Auth email OTP and OAuth provider with PKCE, JWKS, consent and Dynamic Client Registration.
  • Neon Serverless Postgres and Drizzle ORM.
  • Bitwarden Secrets Manager official Node SDK.
  • ImapFlow, PostalMime, html-to-text and Nodemailer.

Dependencies are pinned to exact versions and the lockfile is committed.

Quick start

Requirements: Node.js 22+, a Neon database, a Bitwarden Secrets Manager project and a Resend sender.

git clone https://github.com/eduardo-bolognini/mailport-mcp.git
cd mailport-mcp
npm install
cp .env.example .env.local

Fill .env.local, then run:

npm run db:migrate
npm run dev

The local application is available at http://localhost:3000; the MCP endpoint is http://localhost:3000/mcp. The full environment guide covers Neon, Bitwarden, Resend, Vercel and OAuth: docs/ENVIRONMENT.md.

Connect ChatGPT

After deploying and configuring the production environment:

  1. Enable Developer mode in ChatGPT under Settings → Apps → Advanced settings.
  2. Create a new app with the MCP URL https://your-domain.example/mcp.
  3. Select OAuth authentication. Mailport exposes discovery and Dynamic Client Registration, so no ChatGPT client secret is required.
  4. Sign in using the email code and grant Mailport read and send access once. A single mailbox setup link then configures IMAP and, when you enable it in the same form, SMTP. Every actual send still requires approval of the exact message preview.

Development

npm run typecheck
npm run check
npm test
npm run build

The test suite covers credential serialization, deterministic thread reconstruction and compact model context.

Project map

src/server/auth       Email OTP, OAuth and scoped token validation
src/server/mail       IMAP, SMTP, filtering, threading and context assembly
src/server/mcp        MCP tools and Streamable HTTP transport
src/server/secrets    Bitwarden Secrets Manager boundary
src/server/db         Neon and Drizzle schema
drizzle               Versioned database migrations
docs                  Architecture, security and protocol documentation

Roadmap

  • Attachment metadata and opt-in bounded extraction.
  • Provider OAuth adapters alongside app passwords.
  • Admin security controls, credential rotation and mailbox revocation.
  • Interoperability fixtures for additional MCP clients.

See the detailed roadmap.

Contributing

Security-minded contributions are welcome. Keep the gateway small, avoid credential or content persistence, and include tests for changes to authorization, filtering or threading behavior.

For vulnerabilities, follow SECURITY.md instead of opening a public issue.

License

Apache-2.0 © Eduardo Bolognini. See LICENSE.

Recommended Servers

playwright-mcp

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.

Official
Featured
TypeScript
Magic Component Platform (MCP)

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.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

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.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

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.

Official
Featured
TypeScript
Kagi MCP Server

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.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

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.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured