Skip to main content

IMAP Model Context Protocol server for interactive email processing

Project description

IMAP MCP Server

A Model Context Protocol (MCP) server that enables AI assistants to check email, process messages, and learn user preferences through interaction.

Overview

This project implements an MCP server that interfaces with IMAP email servers to provide the following capabilities:

  • Email browsing and searching
  • Email organization (moving, tagging, marking)
  • Email composition and replies
  • Interactive email processing and learning user preferences
  • Automated email summarization and categorization
  • Support for multiple IMAP providers

The IMAP MCP server is designed to work with Claude or any other MCP-compatible assistant, allowing them to act as intelligent email assistants that learn your preferences over time.

Features

  • Email Authentication: Secure access to IMAP servers with various authentication methods
  • Email Browsing: List folders and messages with filtering options
  • Email Content: Read message contents including text, HTML, and attachments
  • Email Actions: Move, delete, mark as read/unread, flag messages
  • Email Composition: Draft and save replies to messages with proper formatting
    • Support for plain text and HTML replies
    • Reply-all functionality with CC support
    • Proper threading with In-Reply-To and References headers
    • Save drafts to appropriate folders
  • Search: Basic search capabilities across folders
  • Interaction Patterns: Structured patterns for processing emails and learning preferences (planned)
  • Learning Layer: Record and analyze user decisions to predict future actions (planned)

Current Project Structure

The project is currently organized as follows:

.
├── examples/              # Example configurations
│   └── config.yaml.example
├── imap_mcp/              # Source code
│   ├── __init__.py
│   ├── config.py          # Configuration handling
│   ├── imap_client.py     # IMAP client implementation
│   ├── models.py          # Data models
│   ├── resources.py       # MCP resources implementation
│   ├── server.py          # Main server implementation
│   └── tools.py           # MCP tools implementation
├── tests/                 # Test suite
│   ├── __init__.py
│   └── test_models.py
├── INSTALLATION.md        # Detailed installation guide
├── pyproject.toml         # Project configuration
└── README.md              # This file

Getting Started

Prerequisites

  • Python 3.8 or higher
  • An IMAP-enabled email account (Gmail recommended)
  • uv for package management and running Python scripts

Installation

  1. Install uv if you haven't already:

    curl -LsSf https://astral.sh/uv/install.sh | sh
    
  2. Clone and install the package:

    git clone https://github.com/non-dirty/imap-mcp.git
    cd imap-mcp
    uv venv
    source .venv/bin/activate  # On Windows: .venv\Scripts\activate
    uv pip install -e ".[dev]"
    

Gmail Configuration

  1. Create a config file:

    cp config.sample.yaml config.yaml
    
  2. Set up Gmail OAuth2 credentials:

    • Go to Google Cloud Console
    • Create a new project or select existing one
    • Enable the Gmail API
    • Create OAuth2 credentials (Desktop Application type)
    • Download the client configuration
  3. Update config.yaml with your Gmail settings:

    imap:
      host: imap.gmail.com
      port: 993
      username: your-email@gmail.com
      use_ssl: true
      oauth2:
        client_id: YOUR_CLIENT_ID
        client_secret: YOUR_CLIENT_SECRET
        refresh_token: YOUR_REFRESH_TOKEN
    

Usage

Checking Email

To list emails in your inbox:

uv run list_inbox.py --config config.yaml --folder INBOX --limit 10

Available options:

  • --folder: Specify which folder to check (default: INBOX)
  • --limit: Maximum number of emails to display (default: 10)
  • --verbose: Enable detailed logging output

Starting the MCP Server

To start the IMAP MCP server:

uv run imap_mcp.server --config config.yaml

For development mode with debugging:

uv run imap_mcp.server --dev

Managing OAuth2 Tokens

To refresh your OAuth2 token:

uv run imap_mcp.auth_setup refresh-token --config config.yaml

To generate a new OAuth2 token:

uv run imap_mcp.auth_setup generate-token --config config.yaml

Development

Setting Up Development Environment

# Set up virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install development dependencies
pip install -e ".[dev]"

Running Tests

pytest

Security Considerations

This MCP server requires access to your email account, which contains sensitive personal information. Please be aware of the following security considerations:

  • Store email credentials securely using environment variables or secure credential storage
  • Consider using app-specific passwords instead of your main account password
  • Limit folder access to only what's necessary for your use case
  • Review the permissions granted to the server in your email provider's settings

Project Roadmap

  • Project initialization and repository setup
  • Basic IMAP integration
  • Email resource implementation
  • Email tool implementation
  • Email reply and draft functionality
  • User preference learning implementation
  • Advanced search capabilities
  • Multi-account support
  • Integration with major email providers

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

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

iflow_mcp_imap_mcp-0.1.0.tar.gz (76.7 kB view details)

Uploaded Source

Built Distribution

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

iflow_mcp_imap_mcp-0.1.0-py3-none-any.whl (38.7 kB view details)

Uploaded Python 3

File details

Details for the file iflow_mcp_imap_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: iflow_mcp_imap_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 76.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_imap_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d1aac570edd9fb8713c3d4fa23096b5e25bb6a28454f4c7d902e3516f77aa022
MD5 0848ebde307f6b03d44aebe95ce04edf
BLAKE2b-256 8321744d94b29a8ab45c0920502c51526a5560a87225234443d7ded2b8740a92

See more details on using hashes here.

File details

Details for the file iflow_mcp_imap_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_imap_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 38.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.10 {"installer":{"name":"uv","version":"0.9.10"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_imap_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 921947772091921a13fefde7d6af2cfaa532f71d4676fc222dafbe31492b7b61
MD5 b352544f3757227415963175c8791657
BLAKE2b-256 67146d599695681a4676245fc105fb43a5474493512ec0c099f83a259a6fd30a

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