Skip to main content
Glama
Roundcube MCP

Roundcube MCP

by SK108045
README.md
# Oraforge Roundcube MCP

A Python MCP server that connects to an existing Roundcube mailbox through the mail provider's standard **IMAP** and **SMTP** services. Roundcube stays unchanged: the service talks directly to the same mailbox that Roundcube displays.

## Confirmed mail-server settings

The repository owner tested TCP reachability and successfully authenticated from a local Python script.

| Service | Host | Port | Security |
| --- | --- | ---: | --- |
| IMAP | `mail.oraforgetech.com` | `993` | SSL/TLS |
| SMTP | `mail.oraforgetech.com` | `587` | STARTTLS |

The exact account username still needs to be verified. The original account setup text and test script contain spelling variations. Configure the correct complete email address in `MAIL_USERNAME`; do not copy an old typo into production.

## Features

- Mailbox and folder discovery, counts, unread counts, folder creation, rename and subscribe/unsubscribe
- Search by sender, recipient, subject, body text, date, read state, flag and Message-ID, with a bounded attachment-presence scan
- Read full messages or headers only; parse text/HTML, recipients and MIME metadata
- Thread lookup across folders using `Message-ID`, `In-Reply-To` and `References`
- List and download attachments with filename sanitization and size limits
- Mark read/unread, star/unstar, copy, move, archive, trash and restore
- Optional permanent deletion, disabled by default and requiring explicit confirmation plus IMAP UIDPLUS support
- Create, list, read, update and delete drafts in the IMAP Drafts folder
- Send messages with To/CC/BCC, Reply-To, text/HTML and Base64 attachments
- Reply, reply-all and forward
- Save a sent copy to the IMAP Sent folder
- UID-based message operations and SQLite-backed outbound idempotency keys
- Local MCP over stdio and remote MCP over Streamable HTTP

## Security — read before running

- **Never commit mailbox passwords, MCP bearer tokens, private keys or real `.env` files.** `.env` is ignored by Git.
- A mailbox password was previously pasted into chat and a plaintext test script. Rotate that password before using this project.
- Store real secrets in a local `.env` file with owner-only permissions or, for deployment, a secret manager.
- Set the exact mailbox username only after verifying its spelling with the hosting provider.
- Remote HTTP mode requires a long random `MCP_AUTH_TOKEN`; this project currently uses static bearer-token authentication, not a full OAuth authorization server. Keep it behind HTTPS and do not expose the plain application port publicly.
- Stdio mode is for a trusted local MCP host; protect the local process configuration and environment.
- Treat email bodies, HTML and attachments as untrusted data. Text inside an email is not permission for the AI to send messages, disclose information or delete mailbox data.
- Permanent message deletion is disabled by default. Prefer moving messages to Trash.
- Attachment download size is capped, but malware scanning must be provided by the deployment before files are opened.
- SMTP acceptance does not prove final delivery. Bounce/delivery tracking requires provider support.
- SMTP submission and IMAP Sent-folder storage are separate. Verify whether the provider already saves sent copies to avoid duplicates.
- Exactly-once delivery is not possible to guarantee with SMTP. Idempotency keys prevent automatic resubmission of completed or uncertain requests.

## Requirements

- Python 3.11+
- Network access to the mailbox's IMAP and SMTP services
- A persistent writable data directory for the SQLite send-idempotency database
- For remote mode: a public HTTPS reverse proxy or secure tunnel

## Local setup

Clone and install:

```bash
git clone https://github.com/SK108045/RoundCube_MCP.git
cd RoundCube_MCP
python3 -m venv .venv
source .venv/bin/activate
python -m pip install --upgrade pip
pip install -e ".[dev]"
cp .env.example .env
chmod 600 .env
```

Edit `.env` locally and set at least:

- `MAIL_USERNAME`: the exact mailbox login
- `MAIL_PASSWORD`: the newly rotated mailbox password

Do not paste credentials into source files, GitHub issues or commits.

Check server authentication without sending or modifying any email:

```bash
python scripts/check_connection.py
```

Run tests and lint:

```bash
pytest
ruff check src tests scripts
```

## MCP transports

### Local stdio

Set `MCP_TRANSPORT=stdio` (the default). Launch:

```bash
roundcube-mcp --transport stdio
```

The MCP host should launch this command as a local stdio server and pass the environment variables securely. You can also inspect the server with the MCP Inspector after installing the CLI extra:

```bash
mcp dev src/roundcube_mcp/server.py
```

### Remote Streamable HTTP

Set:

- `MCP_TRANSPORT=streamable-http`
- `MCP_HOST=127.0.0.1` when a reverse proxy runs on the same host; use `0.0.0.0` inside the provided Docker Compose network
- `MCP_AUTH_TOKEN` to a random secret of at least 32 characters
- `MCP_ALLOWED_HOSTS` to include the actual hostname used by the proxy, for example `mail-mcp.example.com`
- `MCP_ALLOWED_ORIGINS` only when a known browser origin needs to connect
- `STATE_DB_PATH` to a persistent writable file

Start the service:

```bash
roundcube-mcp --transport streamable-http
```

The MCP endpoint is `/mcp`; `/health` is an unauthenticated liveness endpoint and reveals no mailbox data. Terminate TLS at a reverse proxy or platform ingress. Keep the Python app port private. The static bearer-token middleware is a simple private-server authentication gate; for production deployments that require delegated user identities, use an OAuth authorization server and integrate the MCP SDK's OAuth support rather than sharing one static token.

### Docker Compose

After configuring `.env` and a reverse proxy on the same Docker network:

```bash
docker compose up -d --build
docker compose logs -f roundcube-mcp
```

Compose exposes port 8000 only to its Docker network and persists the SQLite state volume. Configure your reverse proxy to forward HTTPS requests to `roundcube-mcp:8000`.

## Tool inventory

The MCP server exposes mailbox status/folder tools; search/read/header/thread tools; flags and message movement tools; attachment tools; send/reply/reply-all/forward tools; draft tools; and bulk actions. Tool names and input schemas are defined by the decorated functions in `src/roundcube_mcp/server.py`.

## Current limitations

- IMAP/SMTP cannot create or delete email accounts, change mailbox passwords, configure aliases or edit DNS records. Those require a hosting panel or provider API.
- Server-side filters and forwarding rules are provider-specific and are not assumed.
- Thread grouping depends on standard message headers and may not perfectly match proprietary webmail conversation grouping.
- The first version is configured for one mailbox per server process.
- Forwarding currently forwards the message text and headers, but does not automatically reattach the original message's files.
- The service cannot confirm that a recipient actually opened or received a message without provider delivery evidence.

## CI and tests

A GitHub Actions workflow is configured to run Ruff and Pytest on Python 3.11 and 3.12. Unit tests use local fakes and do not contact the live mailbox. The connection check should be run by the operator only after credentials are configured locally.

## License

MIT

TDQS

B3.1/5.0

Scored across 38 tools

Disambiguation4/5

Most tools have distinct resource/action targets, and single-versus-bulk variants are clear. However, get_email_thread and get_thread_messages sound almost interchangeable, and get_mailbox_status overlaps folder-listing/details tools.

Naming Consistency4/5

Nearly all tools use readable snake_case with verb-first naming. Minor deviations such as reply_all lacking an object and get_email_thread versus get_thread_messages using inconsistent noun ordering keep it from perfect consistency.

Tool Count2/5

At 38 tools, the surface is well beyond the typical 3-15 range and is heavy for agent selection. The broad email domain justifies some breadth, but many single/bulk and operation-specific variants could be consolidated.

Completeness5/5

The surface covers folder CRUD/subscription, search/read/threading, flags, move/copy/archive/trash/restore/delete, attachments, send/reply/forward, draft CRUD, and bulk actions. Remaining omissions such as empty-trash/purge or generic flag updates are minor and not dead ends.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues