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
访问服务器

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.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选