Skip to main content

A FastMCP-based email management server for IMAP/SMTP operations

Project description

Emails MCP Server

A FastMCP-based email management server for IMAP/SMTP operations through the Model Context Protocol (MCP).

Features

  • 📧 Email Management: Get, read, search emails with pagination support
  • 📤 Send & Reply: Send emails with HTML/text, attachments, CC/BCC support
  • 📁 Folder Operations: List, create, delete email folders
  • 📋 Draft Management: Save, update, delete, and manage email drafts
  • 📦 Import/Export: Backup/restore emails with folder structure preservation
  • 🔗 Attachment Handling: Download email attachments to specified locations
  • 📊 Statistics: Get mailbox statistics and unread counts
  • 🛡️ Security: Workspace isolation and secure IMAP/SMTP connections

Installation

Uv is recommanded

uv tool install emails-mcp

From source

git clone https://github.com/lockon-n/emails-mcp.git
cd emails-mcp
uv sync

Usage

Configuration

Create email configuration file (/path/to/your/email/config.json):

Single account format:

{
    "email": "your-email@example.com",
    "password": "your-password", 
    "name": "Your Name",
    "imap_server": "imap.example.com",
    "imap_port": yourport (typically 993),
    "smtp_server": "smtp.example.com",
    "smtp_port": yourport (typically 587),
    "use_ssl": true/false,
    "use_starttls": true/false
}

Usage with Claude Desktop

Add to your ~/.config/claude/claude_desktop_config.json (Linux/macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):

Published Configuration:

{
  "mcpServers": {
    "emails-mcp": {
      "command": "uvx",
      "args": [
        "emails-mcp",
        "--config_file",
        "</path/to/your/email/config.json>",
        "--attachment_upload_path",
        "<your/upload/directory>",
        "--attachment_download_path",
        "<your/downloads/directory>",
        "--email_export_path",
        "<your/exports/directory>"
      ]
    }
  }
}

Development/Unpublished Configuration:

{
  "mcpServers": {
    "emails-mcp": {
      "command": "uv",
      "args": [
        "--directory",
        "<path/to/emails-mcp>",
        "run",
        "emails-mcp",
        "--config_file", 
        "</path/to/your/email/config.json>",
        "--attachment_upload_path",
        "<your/upload/directory>",
        "--attachment_download_path",
        "<path/to/your/config.json>",
        "--email_export_path",
        "<your/exports/directory>"
      ]
    }
  }
}

Note: For security, this tool restricts file operations to the specified directories:

  • --attachment_upload_path: Restricts attachment file selection
  • --attachment_download_path: Where downloaded attachments are saved
  • --email_export_path: Where email exports are saved

As a command line tool

# Basic usage (uses default config file: test_emils.json)
emails-mcp

# With custom configuration file
emails-mcp --config_file config.json

# With path restrictions for security
emails-mcp --config_file config.json \
  --attachment_download_path ./downloads \
  --email_export_path ./exports \
  --attachment_upload_path ./uploads

# With debug logging
emails-mcp --config_file config.json --debug

Supported Arguments

  • --config_file: Email configuration file path
  • --attachment_upload_path: Directory for attachment uploads (restricts file selection)
  • --attachment_download_path: Directory for attachment downloads (files saved here)
  • --email_export_path: Directory for email exports (exports saved here)
  • --debug: Enable debug logging

Available Tools

📧 Email Operations

get_emails

Get paginated list of emails from specified folder

  • folder: Email folder name (default: "INBOX")
  • page: Page number starting from 1 (default: 1)
  • page_size: Number of emails per page (default: 20)

read_email

Read full content of a specific email

  • email_id: Email ID to read

search_emails

Search emails with query string (sorted by date descending)

  • query: Search query (subject, from, body content)
  • folder: Folder to search in (optional)
  • page: Page number starting from 1 (default: 1)
  • page_size: Number of results per page (default: 20)

send_email

Send an email with optional HTML body, CC, BCC, and attachments

  • to: Recipient email address(es), comma-separated
  • subject: Email subject
  • body: Plain text body
  • html_body: HTML body content (optional)
  • cc: CC recipients, comma-separated (optional)
  • bcc: BCC recipients, comma-separated (optional)
  • attachments: List of file paths to attach (optional)

reply_email

Reply to an email

  • email_id: ID of email to reply to
  • body: Reply message body (plain text)
  • html_body: Reply message body (HTML, optional)
  • cc: Additional CC recipients (optional)
  • bcc: BCC recipients (optional)
  • reply_all: Whether to reply to all recipients (default: False)

forward_email

Forward an email to other recipients

  • email_id: ID of email to forward
  • to: Recipients to forward to
  • body: Additional message body (optional)
  • html_body: Additional HTML message body (optional)
  • cc: CC recipients (optional)
  • bcc: BCC recipients (optional)

delete_email / delete_emails

Delete single or multiple emails

  • email_id: Email ID to delete (single)
  • email_ids: List of email IDs to delete (batch)

move_email / move_emails

Move single or multiple emails to another folder

  • email_id: Email ID to move (single)
  • email_ids: List of email IDs to move (batch)
  • target_folder: Target folder name

mark_emails

Mark multiple emails with status

  • email_ids: List of email IDs to mark
  • status: Status to set (read, unread, important, not_important)
📁 Folder Operations

get_folders

Get list of available email folders

create_folder

Create new email folder

  • folder_name: Name of folder to create

delete_folder

Delete email folder

  • folder_name: Name of folder to delete

get_mailbox_stats

Get mailbox statistics

  • folder_name: Specific folder name (optional, defaults to all folders)

get_unread_count

Get unread message count

  • folder_name: Specific folder name (optional, defaults to all folders)
📋 Draft Management

save_draft

Save email draft

  • subject: Email subject
  • body: Plain text body
  • html_body: HTML body content (optional)
  • to: Recipient email address(es) (optional)
  • cc: CC recipients (optional)
  • bcc: BCC recipients (optional)

get_drafts

Get list of saved drafts

  • page: Page number starting from 1 (default: 1)
  • page_size: Number of drafts per page (default: 20)

update_draft

Update existing draft

  • draft_id: Draft ID to update
  • subject: Email subject (optional)
  • body: Plain text body (optional)
  • html_body: HTML body content (optional)
  • to: Recipient email address(es) (optional)
  • cc: CC recipients (optional)
  • bcc: BCC recipients (optional)

delete_draft

Delete draft

  • draft_id: Draft ID to delete
🔧 Management & Utilities

check_connection

Check email server connection status

get_email_headers

Get complete email headers for technical analysis

  • email_id: Email ID to get headers for

export_emails

Export emails to file for backup

  • folder: Specific folder to export (optional)
  • export_path: Path where to save the export file (default: "emails_export.json")
  • max_emails: Maximum number of emails to export (optional)
  • export_all_folders: Export from all folders instead of just one (default: False)

import_emails

Import emails from backup file to IMAP server

  • import_path: Path to import file
  • target_folder: Target folder for imported emails (if preserve_folders=False)
  • preserve_folders: Whether to preserve original folder structure (default: True)

download_attachment

Download email attachment to specified path

  • email_id: Email ID containing the attachment
  • attachment_filename: Name of attachment to download
  • download_path: Directory path where to save the attachment

Configuration Options

Email Server Settings

  • IMAP/SMTP servers: Configure your email provider's servers
  • Security: Supports SSL/TLS and STARTTLS
  • Authentication: Standard username/password authentication

Workspace Security

  • Path Restriction: Limit file operations to specified directory
  • Path Validation: All file paths are validated for security

Pagination

  • Default page size: 20 items per page
  • Maximum page size: 50 items per page
  • Auto-correction: Invalid page parameters are automatically corrected

Error Handling

The server includes comprehensive error handling:

  • Connection errors: Graceful handling of network issues
  • Authentication errors: Clear error messages for login failures
  • Validation errors: Input validation with helpful error messages
  • File system errors: Proper handling of file operation failures

Security Considerations

  • Workspace isolation: File operations can be restricted to a safe directory
  • Input validation: All user inputs are validated
  • Connection security: Supports SSL/TLS encryption
  • Error messages: Avoid exposing sensitive information in error messages

Development

Build

uv build

Publish to PyPI

uv publish

Local Development

# Install development dependencies
uv sync

# Run tests
uv run python -m pytest

# Run server
uv run python -m emails_mcp.server

Project Structure

The codebase follows software engineering best practices:

- models/          # Data models and configurations
- config/          # Configuration management  
- utils/           # Utilities, validators, and parsers
- backends/        # IMAP, SMTP, and file operation backends
- services/        # Business logic layer
- tools/           # MCP tool definitions
- server.py        # Main MCP server entry point

License

MIT License

Contributing

Issues and Pull Requests are welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

emails_mcp-0.1.1.tar.gz (75.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

emails_mcp-0.1.1-py3-none-any.whl (45.0 kB view details)

Uploaded Python 3

File details

Details for the file emails_mcp-0.1.1.tar.gz.

File metadata

  • Download URL: emails_mcp-0.1.1.tar.gz
  • Upload date:
  • Size: 75.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.11

File hashes

Hashes for emails_mcp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f5fc977eec3bd9136c213e2486e8e04e85e966f68cc7f00276a261b7de64b0fd
MD5 6f439198daf19b64c6772e939a0479fb
BLAKE2b-256 e420d312ff20a3a1b05bca152489120199796aa4b1284146c6347b739b2bfb20

See more details on using hashes here.

File details

Details for the file emails_mcp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: emails_mcp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 45.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.11

File hashes

Hashes for emails_mcp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aed48f9d2a02ef12f1bec023e2c23b688d3bd8a204e1674c142b668658f2235a
MD5 8440a465404fe13ade2a4f30ec5b91a3
BLAKE2b-256 ef89867af4c464f3682f39c3ff529bb80d4e74400dd46a6d709355c163c03898

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page