MCP Email Server MCP Server

1

Add it to Claude Code

Run this in a terminal.

Run in terminal
claude mcp add --transport http mcp-email-server http://localhost:3456/mcp
Required:EMAIL_ENCRYPTION_KEY+ 3 optional
README.md

Unified email management for Gmail and IMAP accounts via MCP

MCP Email Server

Gmail と IMAP アカウントの両方をサポートする、統合メール管理用の包括的な Model Context Protocol (MCP) サーバーです。

🚀 機能

  • MCP プロトコル対応: ストリーミングHTTP MCPサーバー
  • Gmail 統合: OAuth2ベースのGmail API アクセスと自動トークン管理
  • IMAP サポート: 各種メールプロバイダーへの安全なIMAP接続
  • 統一インターフェース: 自動検出機能付きのすべてのメールアカウント用単一MCPインターフェース
  • アカウント管理: 一元化された設定と接続テスト
  • 堅牢なエラーハンドリング: 詳細なユーザーガイダンス付きの包括的なタイムアウトとエラー管理
  • セキュリティ: IMAPアカウント用の暗号化パスワードストレージ
  • クロスアカウント検索: 設定済みのすべてのアカウントを同時に検索

📋 利用可能なMCPツール

🔄 統合ツール(アカウント種別自動判定)

ツール 説明 パラメータ
list_emails 任意のアカウントからメール一覧を取得(種別自動判定) account_name, limit?, folder?, unread_only?
search_emails 任意のアカウントでメール検索(種別自動判定) account_name, query, limit?
search_all_emails 全てのGmailとIMAPアカウントを横断検索 query, accounts?, limit?, sortBy?
get_email_detail 任意のアカウントから詳細メール情報を取得 account_name, email_id
archive_email 任意のアカウントでメールをアーカイブ(種別自動判定) account_name, email_id, remove_unread?
send_email 任意のアカウントからメール送信(種別自動判定) account_name, to, subject, text/html, cc?, bcc?, attachments?

🔧 管理ツール

ツール 説明 パラメータ
list_accounts 設定済みメールアカウントをステータス付きで一覧表示 なし
test_connection 特定のアカウントへの接続テスト account_name
get_account_stats 全アカウントの包括的統計情報を取得 なし

🛠️ 利用可能なスクリプト

scripts/ ディレクトリに配置:

📧 認証とセットアップ

スクリプト 目的 使用方法
gmail-desktop-auth.mjs Gmail OAuth2認証セットアップ npx tsx scripts/gmail-desktop-auth.mjs [ACCOUNT_NAME]
cleanup-env-tokens.mjs 環境変数のクリーンアップと標準化 npx tsx scripts/cleanup-env-tokens.mjs
setup-xserver.mjs XServer用対話式IMAPアカウントセットアップ npx tsx scripts/setup-xserver.mjs
encrypt-password.ts IMAPアカウント用パスワード暗号化 npx tsx scripts/encrypt-password.ts [PASSWORD]

🖥️ サーバー管理

スクリプト 目的 使用方法
server.sh MCP Email Server管理(起動/停止/再起動/状態確認) ./scripts/server.sh {start|stop|restart|status|logs|health}
monitor-health.ts 包括的ヘルスチェック(認証状態診断付き) npm run health:check
test-search-all.sh 横断検索機能テスト ./scripts/test-search-all.sh

⚙️ インストールとセットアップ

1. インストール

git clone <repository-url>
cd mcp-email-server
npm install

2. 環境設定

# 環境設定ファイルのサンプルをコピー
cp .env.example .env

# 設定を編集
nano .env

3. 必要な環境変数

# 必須 - パスワード保存用暗号化キー
EMAIL_ENCRYPTION_KEY=your-unique-32-character-encryption-key

# Gmail OAuth2設定(Gmailを使用する場合)
GMAIL_CLIENT_ID=your-gmail-client-id
GMAIL_CLIENT_SECRET=your-gmail-client-secret  
GMAIL_REDIRECT_URI=urn:ietf:wg:oauth:2.0:oob

# Gmailアカウントトークン(OAuthスクリプトで取得)
GMAIL_REFRESH_TOKEN_accountname=your-refresh-token

# IMAPアカウント設定(IMAPを使用する場合)
IMAP_HOST_accountname=mail.example.com
IMAP_USER_accountname=user@example.com
IMAP_PASSWORD_accountname=encrypted-password-here
IMAP_PORT_accountname=993
IMAP_TLS_accountname=true

4. アカウントセットアップ

Gmailアカウント
# 最初に.envファイルにGmail OAuth2認証情報を設定し、その後:
node scripts/gmail-desktop-auth.mjs ACCOUNT_NAME

# 認証完了後、サーバーを再起動して設定を反映:
./scripts/server.sh restart
IMAPアカウント
# 対話式IMAPセットアップ(推奨):
node scripts/setup-xserver.mjs

# または手動でパスワードを暗号化:
npx tsx scripts/encrypt-password.ts "あなたのパスワード"

5. サーバー起動と確認

# サーバー起動(LaunchAgent使用)
./scripts/server.sh start

# サーバー状態確認
./scripts/server.sh status

# 包括的ヘルスチェック(推奨)
./scripts/server.sh health
# または
npm run health:check

# 完全テストスイート
npm test

🔧 MCP設定

Cursor MCPセットアップ(推奨)

Cursor MCP設定ファイル (~/.cursor/mcp.json) に追加:

{
  "mcpServers": {
    "mcp-email-server": {
      "url": "http://localhost:3456/mcp",
      "transport": "http"
    }
  }
}

【注意】認証なしで接続されるので、サーバーは絶対公開しないでください。

🖥️ サーバーとテスト

bin/ ディレクトリに配置:

スクリプト 目的 使用方法
run-streaming-email-server.ts 本番用MCPサーバー起動 npx tsx bin/run-streaming-email-server.ts
※ run-stdio-email-server.ts はメンテ終了
MacOSの常時起動方法

ストリーミングHTTPサーバーMCPですので、サーバーは利用時常時起動で運用してください。 macOSの場合、以下のようなLaunchAgentのplistファイルを作成しておくと便利です。 /PATH/TOは適切なパスに置換してください。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<dict>
    <key>Label</key>
    <string>localhost.mcp-email-server</string>
    <key>Program</key>
    <string>/PATH/TO/tsx</string>
    <key>ProgramArguments</key>
    <array>
        <string>/PATH/TO/.nvm/versions/node/v23.7.0/bin/tsx</string>
        <string>/PATH/TO/mcp-email-server/bin/run-streaming-email-server.ts</string>
    </array>
    <key>WorkingDirectory</key>
    <string>/PATH/TO/src/git/mcp-email-server</string>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardOutPath</key>
    <string>/PATH/TO/Library/Logs/mcp-email-server.log</string>
    <key>StandardErrorPath</key>
    <string>/PATH/TO/Library/Logs/mcp-email-server-error.log</string>

Tools (9)

list_emailsRetrieve a list of emails from any account with automatic type detection.
search_emailsSearch for emails in a specific account.
search_all_emailsPerform a cross-account search across all configured Gmail and IMAP accounts.
get_email_detailRetrieve detailed information for a specific email.
archive_emailArchive an email in any account.
send_emailSend an email from any configured account.
list_accountsList all configured email accounts with their current status.
test_connectionTest the connection to a specific email account.
get_account_statsGet comprehensive statistics for all configured accounts.

Environment Variables

EMAIL_ENCRYPTION_KEYrequiredUnique 32-character key for encrypting stored passwords
GMAIL_CLIENT_IDClient ID for Gmail OAuth2
GMAIL_CLIENT_SECRETClient Secret for Gmail OAuth2
IMAP_HOST_accountnameIMAP server host address

Configuration

claude_desktop_config.json
{"mcpServers": {"mcp-email-server": {"url": "http://localhost:3456/mcp", "transport": "http"}}}

Try it

Search all my email accounts for messages from 'billing' received this week.
List the unread emails in my work Gmail account.
Send an email to my team regarding the project update using my primary account.
Archive the email with ID 12345 in my personal IMAP account.
Show me the connection status and statistics for all my configured email accounts.

Frequently Asked Questions

What are the key features of MCP Email Server?

Unified interface for both Gmail and IMAP accounts. Cross-account search functionality across all configured mailboxes. Secure encrypted password storage for IMAP accounts. Automated Gmail OAuth2 token management. Integrated health monitoring and connection testing tools.

What can I use MCP Email Server for?

Managing multiple personal and professional email accounts from a single AI interface. Automating email triage by searching across disparate providers simultaneously. Quickly drafting and sending emails using natural language commands. Monitoring the health and connectivity of multiple email accounts in one dashboard.

How do I install MCP Email Server?

Install MCP Email Server by running: git clone https://github.com/kentaroh7777/mcp-email-server && cd mcp-email-server && npm install

What MCP clients work with MCP Email Server?

MCP Email Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Turn this server into reusable context

Keep MCP Email Server docs, env vars, and workflow notes in Conare so your agent carries them across sessions.

Need the old visual installer? Open Conare IDE.
Open Conare