npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

read-email-mcp

v2.0.1

Published

Read-only MCP server that mirrors any IMAP mailbox into a local SQLite copy for browsing and searching email.

Readme

Read Email MCP

A read-only Model Context Protocol server that mirrors any IMAP mailbox into a local SQLite database, then lets AI clients browse, search, and read email without reconnecting to the server on every request.

It works with Gmail, Outlook, Yahoo, Fastmail, iCloud, Proton Mail Bridge, self-hosted mail, and any other provider that exposes standard IMAP.

Version 2.0.1. Please report issues.

Why use it

  • Fast browsing and search. Email is synced once into a local SQLite mirror with full-text search. Every browse, search, and read call hits the local copy, so it is quick and never re-logs-in to IMAP per request.
  • Read-only and safe. It never sends, deletes, moves, flags, or marks messages. IMAP mailboxes are opened with read-only locks. Your mailbox cannot be mutated by this server.
  • Provider agnostic. Works with any IMAP server. Common providers are auto-detected from the email domain, and custom/self-hosted servers get automatic discovery via autoconfig, DNS, and MX records.
  • Private by design. Credentials live in environment variables or your password manager's CLI — nothing requires storing passwords on disk. Raw .eml files live under your home directory and never leave your machine.
  • MCP native. Exposes a clean set of tools over stdio so any MCP-compatible client can read email on your behalf.

Requirements

  • Node.js 20 or newer
  • A mailbox with IMAP enabled
  • The mailbox email address and password. Most consumer providers (Gmail, Yahoo, iCloud, Outlook with 2FA) require an app-specific password instead of your normal sign-in password.

Quick start

The fastest path is the account wizard — it detects your provider, fills in the IMAP settings, verifies the connection, and writes the accounts file for you:

npx -y [email protected] accounts add
npx -y [email protected] init        # prints the MCP client config to paste

From source instead:

git clone <this-repo>
cd read-email-mcp
npm install
npm run build
node dist/index.js accounts add

Or run the server directly with credentials — the IMAP host is optional for known providers:

node dist/index.js --email "[email protected]" --password "your-app-password"

Or set environment variables and omit the flags:

$env:EMAIL = "[email protected]"
$env:PASSWORD = "your-app-password"
node dist/index.js

Configuration

All settings can be passed as CLI args or environment variables. CLI args take precedence over environment variables.

| Setting | Required | Env var | CLI arg | Default | | --- | --- | --- | --- | --- | | Email address | yes | EMAIL | --email | none | | Password | yes | PASSWORD | --password | none | | IMAP host | no* | IMAP_HOST | --imap-host | auto-detected for known providers | | IMAP port | no | IMAP_PORT | --imap-port | 993 | | IMAP TLS | no | IMAP_SECURE | --imap-secure | true | | IMAP login user | no | IMAP_USER | --imap-user | same as email | | TLS cert verification | no | IMAP_TLS_REJECT_UNAUTHORIZED | — | true (set false for self-signed certs) | | Accounts file | no | ACCOUNTS_FILE | --accounts | ~/.read-email-mcp/accounts.json if it exists | | Env file | no | ENV_FILE | --env-file | ./.env then ~/.read-email-mcp/.env if present |

*IMAP_HOST is only required when the email domain isn't a known provider (see "Common provider settings"). For gmail.com, outlook.com, icloud.com, and the other presets, host/port/TLS are filled in automatically — EMAIL + PASSWORD is enough.

IMAP_SECURE accepts true or false (also 1/0, yes/no, on/off). Use false with port 143 for STARTTLS or plain IMAP.

IMAP_USER is optional. Set it only when the IMAP login name differs from the mailbox email address. When omitted, the email address is used as the IMAP username.

.env files are loaded automatically: ./.env first, then ~/.read-email-mcp/.env, without overriding variables already set. Use --env-file/ENV_FILE to point at a specific file instead.

Prefer PASSWORD or a .env file over --password: CLI arguments are visible in process listings and shell history.

Managing accounts from the command line

The binary doubles as an account-management CLI — the fastest way to get set up:

read-email-mcp accounts add                # interactive wizard (prompts for what's missing)
read-email-mcp accounts list               # show configured accounts
read-email-mcp accounts remove work        # remove by name or email
read-email-mcp accounts test               # check IMAP connectivity for every account
read-email-mcp accounts test work          # check one account
read-email-mcp accounts discover [email protected]  # auto-detect IMAP settings
read-email-mcp init                        # print a ready-to-paste MCP client config

accounts add detects the provider from the email domain, fills in IMAP settings, and offers to store the password as an env-var reference (it can save it into the .env file for you). Non-interactive use works too — handy for scripts:

read-email-mcp accounts add --name work --email [email protected] `
  --imap-host imap.work.com --password-env WORK_IMAP_PASSWORD --group work

Before writing the file, accounts add tests the connection with your credentials and reports how many mailboxes it found — wrong passwords and typos get caught immediately instead of at first sync. Use --no-test to skip, or --test to enforce the check in scripts.

accounts test connects to each account, lists its mailboxes, and reports failures with provider hints — use it to verify credentials before wiring the server into a client.

Custom and self-hosted IMAP

For domains that don't match a provider preset, accounts add auto-detects the IMAP settings instead of making you look them up. It tries, in order:

  1. Mozilla autoconfig — autoconfig.<domain> and /.well-known/autoconfig, the standard most cPanel/Dovecot and hosted-IMAP setups publish.
  2. DNS SRV records — _imaps._tcp.<domain> / _imap._tcp.<domain> (RFC 6186).
  3. MX inference — a company domain hosted on Google Workspace or Microsoft 365 resolves to that provider's IMAP servers.
  4. Hostname probing — imap.<domain> and mail.<domain> on the standard ports.

Preview what would be found without creating an account:

read-email-mcp accounts discover [email protected]

You can always override the detected values with --imap-host, --imap-port, --imap-secure, and --imap-user. For servers with self-signed certificates, pass --allow-self-signed (or set "imapTlsRejectUnauthorized": false in the accounts file); if the connection test hits a certificate error, the wizard offers this retry automatically. Single-account env config supports the equivalent IMAP_TLS_REJECT_UNAUTHORIZED=false.

Multiple accounts

Point --accounts (or ACCOUNTS_FILE) at a JSON file to mirror several mailboxes in one server. Single-account env/CLI config is ignored when an accounts file is used.

{
  "accounts": [
    {
      "name": "work",
      "email": "[email protected]",
      "passwordEnv": "WORK_IMAP_PASSWORD",
      "imapHost": "imap.work.com",
      "groups": ["work"]
    },
    {
      "name": "personal",
      "email": "[email protected]",
      "passwordCommand": "op read op://Private/Gmail/app-password",
      "groups": ["personal"]
    }
  ]
}

The personal entry needs no imapHost — gmail.com resolves to the Gmail preset automatically. Easiest way to produce this file is read-email-mcp accounts add.

Each entry needs email plus one credential method. imapHost is optional when the domain (or an explicit provider) matches a preset — see "Common provider settings". Optional fields:

| Field | Purpose | | --- | --- | | name | Friendly name for the account tool parameter (defaults to the email; names and emails must be unique) | | provider | Preset id (gmail, outlook, yahoo, icloud, fastmail, zoho, aol, gmx, proton, yandex, mailcom) — fills in host/port/TLS | | passwordEnv | Name of an env var holding the password (preferred — secrets stay out of the file) | | passwordCommand | Shell command whose stdout is the password, e.g. op read op://Private/Email/password for 1Password CLI | | password | Inline password (discouraged — only for local testing) | | imapHost / imapPort / imapSecure / imapUser | Same meaning as the single-account settings | | imapTlsRejectUnauthorized | Set false for self-signed certificates (skip TLS verification — use only on servers you trust) | | groups | Labels like ["work", "clients"] — select several accounts at once via the accountGroup tool parameter |

Every account gets its own mirror under ~/.read-email-mcp/<account-hash>/. Tools accept account (name or email), accounts (a list, * wildcard supported), or accountGroup (matches groups):

  • sync_email without a selector syncs every configured account in parallel and reports per-account results; a selector scopes it to a subset.
  • get_recent_emails, list_emails, search_emails, and browse_email_dates without a selector merge results across accounts into one view; each item is tagged with its account.
  • get_email, get_emails, get_thread, list_attachments, get_attachment, and get_raw_email need a single account when resolving by id, ids, or mailbox+uid (ids are per-account). messageId lookups search all accounts automatically.
  • get_sync_status, list_mailboxes, get_storage_stats, optimize_email_store, get_inbox_summary, and check_accounts without a selector return a per-account summary.

list_accounts shows the configured accounts, their providers, groups, storage paths, and message counts.

Common provider settings

| Provider | IMAP host | Port | TLS | Notes | | --- | --- | --- | --- | --- | | Gmail | imap.gmail.com | 993 | true | Needs an app password with 2FA enabled | | Outlook / Office 365 | outlook.office365.com | 993 | true | Use your Microsoft account password or app password | | Yahoo | imap.mail.yahoo.com | 993 | true | Needs an app password | | iCloud | imap.mail.me.com | 993 | true | Needs an app password | | Fastmail | imap.fastmail.com | 993 | true | Use your Fastmail app password | | Proton Mail | 127.0.0.1 | 1143 | false | Requires the Proton Mail Bridge app running locally | | Self-hosted | your mail server | 993 or 143 | true or false | Depends on your server config |

MCP client configuration

The server speaks MCP over stdio. Add it to any MCP-compatible client — read-email-mcp init prints a ready-to-paste config block for your setup.

Claude Desktop

{
  "mcpServers": {
    "read-email": {
      "command": "npx",
      "args": [
        "-y",
        "read-email-mcp",
        "--email",
        "[email protected]",
        "--password",
        "your-app-password"
      ]
    }
  }
}

Codex CLI and other env-based clients

Set credentials in the server environment and pass only the binary:

{
  "mcpServers": {
    "read-email": {
      "command": "npx",
      "args": ["-y", "read-email-mcp"],
      "env": {
        "EMAIL": "[email protected]",
        "PASSWORD": "your-app-password"
      }
    }
  }
}

opencode

read-email-mcp init also prints this block. Add it to opencode.json (or .opencode.json):

{
  "mcp": {
    "read-email": {
      "type": "local",
      "command": ["npx", "-y", "read-email-mcp"],
      "enabled": true
    }
  }
}

Devin CLI

devin mcp add read-email -- npx -y read-email-mcp --accounts "C:\path\to\accounts.json"

Add -e [email protected] -e PASSWORD=app-password for a single-account env config instead of --accounts.

Pin a version (e.g. [email protected]) or install from source after building.

Tools

The server exposes 19 tools. All read from the local mirror except sync_email and check_accounts, which talk to IMAP.

  • sync_email: pull messages from IMAP into the local mirror. Call this first, or after a gap, before browsing or searching. Default is incremental (only new UIDs); pass uids, search, or since for a targeted fetch of specific messages, or refreshFlags to re-sync read/flagged state. Multiple accounts sync in parallel. See "How sync works" below.
  • list_accounts: list configured accounts with providers, groups, storage paths, and message counts.
  • check_accounts: test IMAP connectivity per account (connect, list mailboxes, disconnect) — diagnose auth or network problems.
  • get_sync_status: show account, storage path, total messages, latest message date, per-mailbox counts, and the last sync result. Good first check to see whether a sync is needed.
  • list_mailboxes: list locally known mailboxes (INBOX, Sent, Drafts, and so on) with message counts and last-sync time.
  • get_inbox_summary: one-call triage briefing per account — total/unread/flagged counts, mailbox count, latest message date, and the newest unread summaries.
  • get_recent_emails: show the latest emails, newest first, with optional unreadOnly, flaggedOnly, and last lookback windows. This is the everyday tool for checking what is new.
  • browse_email_dates: summarize message volume as counts per day, week, or month. Useful for finding a busy period before drilling in with a date range.
  • search_emails: full-text search across subject, sender and recipient addresses, preview, and body, with filters and pagination. sort: "relevance" ranks hits by match quality and interleaves each account's best results first.
  • list_emails: list email summaries in chronological order with filters and pagination, without full-text search. Prefer this when browsing by sender, date, or mailbox.
  • list_senders: rank senders by message count with per-sender unread counts, merged across the selected accounts — good for "who emails me most" or finding a person.
  • get_email: return metadata and body for a single message, by id, Message-ID, or mailbox plus UID. format (full/text/headers/summary) and maxBodyChars keep responses sized for context windows.
  • get_emails: read a group of up to 25 messages in one call by id. Prefer this over looping get_email for several full bodies.
  • get_thread: return all locally known messages in one conversation, matched by Message-ID, In-Reply-To, and References headers.
  • list_attachments: list a message's attachments (index, filename, type, size) without downloading them.
  • get_attachment: extract one attachment by index or filename — returns base64 up to maxBytes, or writes to disk with saveTo.
  • get_raw_email: return raw RFC822/MIME source for one message, byte-limited. Use this only when you need original headers or MIME structure.
  • get_storage_stats: report SQLite database, WAL, and page statistics for the local mirror.
  • optimize_email_store: run lightweight SQLite and FTS maintenance to keep queries fast. Safe to run after large syncs.

search_emails, list_emails, and get_recent_emails accept mailbox/mailboxes, unread, and flagged filters; search_emails and list_emails add from/to/cc/subject, date ranges (startDate/endDate) or relative last windows like "7d", and limit/cursor/nextCursor pagination — pagination works across merged multi-account results too.

Typical workflow

  1. Run check_accounts to verify credentials and connectivity (or read-email-mcp accounts test outside the client).
  2. Run sync_email with a small limit on one mailbox, then get_sync_status to confirm the mirror is fresh.
  3. Run get_inbox_summary for unread counts and the newest unread per account, or get_recent_emails with unreadOnly: true.
  4. Run get_email (with format/maxBodyChars to keep responses small) or get_thread to follow a conversation.
  5. Run search_emails (optionally sort: "relevance") or list_emails to find older messages by sender, subject, date range, or unread and flagged state.

How sync works

Sync connects to IMAP, lists selectable mailboxes, and fetches new messages by tracking the highest UID already seen per mailbox. If a mailbox UIDVALIDITY changes, the local copy for that mailbox is reset and refetched (stale raw files are removed). Raw RFC822 source is written to disk, parsed metadata and body text go into SQLite, and a full-text search index is maintained alongside.

Sync has two modes:

  • Incremental (default): only fetches UIDs above the stored high-water mark per mailbox. resetMailbox: true restarts the scan from UID 1 without losing the local copy (upserts refresh rows in place).
  • Targeted: pass uids (a set like "12,15,20-30", requires one mailbox), search (server-side IMAP criteria: from, to, cc, subject, since, before, unseen, flagged), or since (shorthand for search.since). Targeted syncs fetch exactly the matching messages and never move the incremental cursor, so they are safe for backfills and one-off fetches.

Mailbox selection: mailbox/mailboxes include specific folders, excludeMailboxes drops names (* wildcard supported), and excludeFlags drops folders by IMAP special-use flag — the default ["\\All"] avoids double-mirroring Gmail's All Mail. Pass excludeFlags: [] to sync everything.

Flag freshness: incremental sync does not revisit already-synced messages, so \Seen/\Flagged changes and server-side deletions go stale over time. refreshFlags: true performs a cheap flags-only pass over synced UIDs, updating stored flags; pruneExpunged (default true alongside refreshFlags) also removes local copies of messages deleted on the server.

Mailboxes are opened read-only, so flags and read state on the server are never changed.

Local storage

The mirror is stored under:

~/.read-email-mcp/<account-hash>/
  emails.sqlite
  raw/

The account hash is derived from the email address, so multiple accounts coexist without exposing the address in folder names. Passwords are never written to disk.

Raw .eml files contain full email content. Treat the storage directory as sensitive and protect it the same way you protect your mailbox.

Safety

  • The server is read-only. It does not send, delete, move, archive, mark read, or mutate flags.
  • IMAP mailboxes are opened with read-only locks during sync.
  • Credentials live only in the process environment and are never persisted by this server.
  • The SQLite mirror uses WAL mode, a busy timeout, keyset pagination, and periodic FTS optimization for local performance and concurrency.

Development

npm test          # unit tests (no real mailbox needed)
npm run typecheck # TypeScript checks
npm run build     # compile to dist/
npm run smoke:mcp # start the built server over stdio and verify all tools
npm run verify    # runs all of the above

Tests use fixtures and fake IMAP clients, so they do not require real credentials or a live mail server.

Limitations

  • No sending, replying, or composing email.
  • No deleting, moving, flagging, or marking messages read.
  • No OAuth. App passwords, direct passwords, or passwordCommand credential helpers only.
  • No background daemon. Sync runs when the client calls sync_email.
  • Threads are assembled within one account's mirror; conversations spanning accounts are not merged.
  • get_attachment re-parses the stored .eml on demand, so extraction speed depends on message size.

License

MIT