mcp-imap-server

mcp-imap-server

Enables LLMs to read, search, and manage emails via IMAP with secure, read-only access to email accounts.

Category
Visit Server

README

MCP IMAP Server

A Model Context Protocol (MCP) server that enables Claude and other LLM applications to read emails via the IMAP protocol. This server provides secure, read-only access to email accounts from popular providers like Gmail, Outlook, Yahoo, and custom IMAP servers.

Features

  • šŸ” Secure Authentication: Support for username/password authentication with secure credential handling
  • šŸ“§ Email Operations: Search, read, and manage emails with comprehensive filtering options
  • šŸ“ Folder Management: List and navigate email folders/mailboxes
  • šŸ·ļø Email Status: Mark emails as read/unread
  • šŸ” Advanced Search: Search by sender, subject, date range, content, and read status
  • 🌐 Provider Support: Pre-configured for Gmail, Outlook, Yahoo, iCloud, and custom IMAP servers
  • šŸ›”ļø Security First: Read-only access, no email sending or deletion capabilities
  • ⚔ Performance: Efficient connection pooling and error handling

Quick Start

Installation

git clone <repository-url>
cd mcp-imap-server
npm install
npm run build

Configuration

Create a .env file in the project root:

# Required: IMAP server configuration
IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_USER=your-email@gmail.com
IMAP_PASSWORD=your-app-password
IMAP_TLS=true

# Optional: Connection settings
IMAP_AUTH_TIMEOUT=3000
IMAP_CONN_TIMEOUT=10000
IMAP_KEEPALIVE_INTERVAL=10000
IMAP_IDLE_INTERVAL=300000
IMAP_FORCE_NOOP=false

Popular Email Provider Settings

Gmail

IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_TLS=true

Outlook/Hotmail

IMAP_HOST=outlook.office365.com
IMAP_PORT=993
IMAP_TLS=true

Yahoo Mail

IMAP_HOST=imap.mail.yahoo.com
IMAP_PORT=993
IMAP_TLS=true

iCloud Mail

IMAP_HOST=imap.mail.me.com
IMAP_PORT=993
IMAP_TLS=true

Running the Server

# Development mode
npm run dev

# Production mode
npm run build
npm start

MCP Tools

The server exposes the following tools to MCP clients:

search_emails

Search for emails based on various criteria.

Parameters:

  • sender (optional): Filter by sender email address or name
  • subject (optional): Filter by subject line (partial match)
  • dateFrom (optional): Start date for date range filter (ISO format: YYYY-MM-DD)
  • dateTo (optional): End date for date range filter (ISO format: YYYY-MM-DD)
  • content (optional): Search within email content/body text
  • unread (optional): Filter by read status (true for unread only, false for read only)
  • folder (optional): Folder to search in (defaults to INBOX)
  • limit (optional): Maximum number of emails to return (1-100)

Example:

{
  "name": "search_emails",
  "arguments": {
    "sender": "notifications@github.com",
    "unread": true,
    "limit": 10
  }
}

get_email

Retrieve the full content of a specific email by its message ID.

Parameters:

  • messageId (required): The message ID or UID of the email to retrieve
  • folder (optional): Folder containing the email (defaults to INBOX)

Example:

{
  "name": "get_email",
  "arguments": {
    "messageId": "12345",
    "folder": "INBOX"
  }
}

list_folders

List all available email folders/mailboxes in the account.

Parameters:

  • includeSpecial (optional): Include special folders like Sent, Drafts, etc.

Example:

{
  "name": "list_folders",
  "arguments": {
    "includeSpecial": true
  }
}

get_recent_emails

Get the most recent emails from a specific folder.

Parameters:

  • folder (optional): Folder to get emails from (defaults to INBOX)
  • limit (optional): Number of recent emails to retrieve (1-50, default: 10)
  • unreadOnly (optional): Only return unread emails

Example:

{
  "name": "get_recent_emails",
  "arguments": {
    "folder": "INBOX",
    "limit": 5,
    "unreadOnly": true
  }
}

mark_as_read

Mark an email as read or unread.

Parameters:

  • messageId (required): The message ID or UID of the email to mark
  • folder (optional): Folder containing the email (defaults to INBOX)
  • read (optional): Mark as read (true) or unread (false). Default: true

Example:

{
  "name": "mark_as_read",
  "arguments": {
    "messageId": "12345",
    "read": true
  }
}

Security Considerations

Email Provider Setup

Gmail

  1. Enable 2-factor authentication
  2. Generate an App Password (not your regular password)
  3. Use the App Password as IMAP_PASSWORD

Outlook/Hotmail

  1. Enable 2-factor authentication
  2. Generate an App Password
  3. Use the App Password as IMAP_PASSWORD

Other Providers

Consult your email provider's documentation for IMAP access and app password setup.

Best Practices

  • Never log credentials: The server is designed to never log sensitive information
  • Use app passwords: Always use app-specific passwords, never your main account password
  • Read-only access: The server only provides read operations for security
  • Secure storage: Store credentials securely and never commit them to version control
  • Network security: Always use TLS/SSL connections (enabled by default)

Development

Project Structure

src/
ā”œā”€ā”€ config/          # Configuration management
ā”œā”€ā”€ services/        # IMAP connection and management
ā”œā”€ā”€ tools/           # MCP tool implementations
ā”œā”€ā”€ types/           # TypeScript type definitions
└── index.ts         # Main server entry point

Available Scripts

npm run build        # Build TypeScript to JavaScript
npm run dev          # Run in development mode with auto-reload
npm start            # Run the built server
npm test             # Run tests
npm run lint         # Lint the code
npm run typecheck    # Type check without building
npm run clean        # Clean build directory

Adding New Tools

  1. Define types in src/types/index.ts
  2. Add Zod validation schema
  3. Implement the tool logic in src/tools/index.ts
  4. Register the tool in src/index.ts

Error Handling

The server includes comprehensive error handling for:

  • Authentication failures: Clear messages for invalid credentials
  • Connection issues: Timeout and network error handling
  • IMAP protocol errors: Detailed error messages for debugging
  • Validation errors: Input validation with helpful error messages

Troubleshooting

Common Issues

  1. Authentication Failed

    • Verify your email and app password are correct
    • Ensure 2FA is enabled and you're using an app password
    • Check if IMAP is enabled in your email provider settings
  2. Connection Timeout

    • Verify the IMAP host and port settings
    • Check your firewall and network settings
    • Try increasing the connection timeout values
  3. TLS/SSL Errors

    • Ensure IMAP_TLS=true for secure connections
    • Verify your email provider supports the specified port with TLS

Debug Mode

Set NODE_ENV=development to enable debug logging:

NODE_ENV=development npm run dev

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with proper tests
  4. Ensure all tests pass and code is properly typed
  5. Submit a pull request

License

MIT License - see LICENSE file for details.

Support

For issues and questions:

  1. Check the troubleshooting section above
  2. Review your email provider's IMAP documentation
  3. Open an issue on GitHub with detailed error messages and configuration (without credentials)

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