mail-mcp-server
You can search, browse, read, and summarize a locally synced, read-only copy of one or more Exchange/IMAP mailboxes.
List configured mailboxes and their local data availability.
Start background mailbox syncs, check sync progress/results, and inspect failures or sign-in rejection.
List local folders and browse messages newest-first with paging and date filters.
Read message headers, body chunks, attachment lists, and attachment text chunks with local file paths.
Search full-text across subject, body, addresses, labels, attachment names, and extracted attachment text, with Russian/English word forms, filters, snippets, and deduplicated copies.
Follow conversations across folders using reply headers.
Summarize message counts by sender address or domain, including dates and folders.
Work offline from the local index; mailbox changes are not made, and attachments from PDF, Office, ZIP, and attached messages can be searchable.
Syncs a Gmail mailbox over IMAP using an app password, downloads messages locally, converts bodies and attachments to Markdown, indexes them, and lets the agent search and read mail and attachments without modifying the mailbox.
Syncs a Mail.ru mailbox over IMAP, builds a local searchable copy of messages and attachments, and provides read-only search, message reading, folder listing, and attachment access tools.
Mail MCP Server
Give your AI agent your whole mailbox, including on-premises Exchange, with no way to change it.
MCP server (stdio) for on-premises Microsoft Exchange over EWS and any IMAP mailbox with password sign-in, tested on Mail.ru and Gmail. It downloads every message once, converts bodies and attachments to Markdown on your machine, builds a Lucene search index, and answers the agent from that copy, so text inside PDF, Office and ZIP attachments is searchable in Russian and English.
Status: version 0.1.1 is published. Checked end to end on Exchange 2013 (about 8
thousand messages), Mail.ru (about 34 thousand) and Gmail with an app password. Developed and
tested on Windows.
Contents: Features · How it works · Typical Scenarios · Quickstart · MCP Tools · Commands · Build · Stack · Documentation · License
Features
Works with on-premises Exchange. EWS with NTLM and your normal domain password, tested on Exchange 2013. No Microsoft Graph needed. Other mailboxes work over IMAP, tested on Mail.ru and Gmail.
Attachments are searchable too. Text from PDF, Word, Excel, PowerPoint, ZIP archives, attached emails, Outlook
.msgandwinmail.datis extracted and indexed, so the agent can find the contract inside the attachment, not just the message that carried it.Search that understands word forms. Russian and English, across subject, body, addresses and attachments. Copies of one message appear once, and conversations are followed across folders (search).
Cannot change your mailbox. Read-only is enforced at the protocol level: write commands are rejected before they are sent, and downloading a message does not mark it as read (security).
Careful with your account. One sign-in per sync and no retries. After a rejected password, it stops trying until you fix it, which reduces the risk of a domain lockout.
Fast, and works offline. The agent reads a local copy, so answers don't depend on the mail server. Sync runs only when you ask for it.
Your mail stays on your machine. No cloud service of its own: conversion and indexing are local, and the local copy is unfiltered. Your AI client still sees what the tools return, and an optional secret filter masks passwords and codes in responses.
Several mailboxes, one server. Passwords can stay out of the config, in Windows Credential Manager, a password manager or an environment variable (connections).
Related MCP server: work-assistant
How it works
Download all mail. The
synctool copies the included folders of each mailbox as original.emlfiles, then only changes on later runs.Convert it locally to Markdown. Bodies and attachments — PDF, Office documents, archives, attached messages — are converted with pandoc (required), PDFBox and Apache POI.
Index it. A Lucene index per mailbox with Russian and English word forms.
Use it from MCP. Tools search and read the local copy only; they never contact a mail server.
MCP client (Claude Code, Codex, OpenCode, VS Code, ...)
| JSON-RPC over stdin / stdout
v
mail-mcp-server --- search, read ---> Lucene index + <data-dir>/<connection>/messages/
| ^
+--- sync (on request) --- EWS / IMAP --+--> .eml -> Markdown -> indexTypical Scenarios
The agent picks the tools itself; these are the chains it usually follows.
Scenario | Example request | Tools |
Find mail on a topic | "Find the letters about the supply contract in |
|
Mail of a period | "What came to my work mail yesterday?" |
|
Follow a conversation | "Show the whole discussion around this letter." |
|
Read an attachment | "What does the price list in the last letter from the supplier say?" |
|
Bring mail up to date | "Update my work mail and tell me what is new." |
|
Browse a folder | "List the latest messages in my inbox." |
|
Organize a mailbox | "Who sends the most mail to my inbox, and where is it filed?" |
|
Quickstart
1. Install JDK 25 and pandoc 3.x. Pandoc is required
and must be on PATH. Check in a new terminal:
java -version
pandoc --version2. Get the jar: download mail-mcp-server.jar from the
latest release, or build it yourself:
.\gradlew.bat bootJar # -> build\libs\mail-mcp-server.jarNo local JDK or pandoc? Use the Docker image ghcr.io/igorolv/mail-mcp-server instead, with fewer
ways to store passwords: see Docker. To skip the manual download and the
JDK, but not pandoc, start the server with JBang:
jbang --quiet mail-mcp-server@igorolv/mail-mcp-server.
3. Describe your mailboxes in %USERPROFILE%\.mail-mcp-server\connections.json
(~/.mail-mcp-server/connections.json elsewhere), one entry per mailbox. Keep only the ones you
need and replace the example addresses:
{
"connections": {
"work": {
"type": "ews",
"url": "https://webmail.example.com/EWS/Exchange.asmx",
"auth": "ntlm",
"username": "user",
"windowsCredential": "mail-mcp/work",
"description": "Work mail, Exchange 2013"
},
"mailru": {
"type": "imap",
"host": "imap.mail.ru",
"port": 993,
"tls": true,
"auth": "app-password",
"username": "user@mail.ru",
"passwordCommand": ["security", "find-generic-password", "-s", "mail-mcp", "-a", "mailru", "-w"],
"description": "Personal Mail.ru"
},
"gmail": {
"type": "imap",
"host": "imap.gmail.com",
"port": 993,
"tls": true,
"auth": "app-password",
"username": "user@gmail.com",
"password": "${MAIL_GMAIL_PASSWORD}",
"description": "Personal Gmail"
}
}
}Each entry shows a different password source: work reads Windows Credential Manager, mailru
runs a command that prints the password (here the macOS Keychain; 1Password, pass and others
work the same way), and gmail reads an environment variable, which must be set wherever the
server starts. A literal password works too. Which password each provider needs (domain password, Mail.ru or Gmail
app password, Gmail OAuth2) and how to store it: docs/connections.md.
4. Register the server with your MCP client, with an absolute path to the jar. Claude Code:
claude mcp add --scope user mail -- java -jar C:/path/to/mail-mcp-server.jarOther clients and environment variables: docs/clients.md. If you installed
pandoc or changed PATH while the client was running, fully restart the client.
5. Download your mail. Ask the agent: "Sync my work mailbox and tell me when it's done."
The first sync downloads the whole mailbox and can take a long time, so keep the client open. If it
stops, ask again and it continues. A password manager must be unlocked or ask in its own window,
because the server has no terminal to ask in. For a large mailbox, or to see progress in a
terminal, use mail-sync.
6. Try it. Ask the agent: "Which mailboxes can you read?" or "Find the letters about the
supply contract in work from last week."
Something went wrong: docs/troubleshooting.md.
MCP Tools
Every tool except listConnections takes a required connection argument.
Tool | What it does |
| Configured mailboxes with type, sign-in method, description and configuration errors |
| Starts a background synchronization and returns at once |
| Progress and result of the current or last run |
| Local folders with message counts |
| Message cards of one folder, newest first, in pages |
| Headers, the body in chunks, attachments with file paths |
| The text of one attachment in chunks, and the file path |
| Full-text search with Russian and English word forms, fields, folder and date filters |
| Message counts by sender address or domain, with dates and folders |
| The conversation of a message across folders, oldest first |
Query syntax and results: docs/search.md. Arguments and limits: docs/tools-agent.md.
Commands
Offline maintenance, sign-in recovery and Gmail OAuth2 consent run in a terminal: docs/commands.md.
Build
.\gradlew.bat build # compile, all tests, bootJar -> build\libs\mail-mcp-server.jarThe build needs a JDK 25 toolchain; Gradle can download one. Tests never contact a mail server:
they use loopback fakes and the synthetic data sets in testdata/. Tests that need pandoc are
skipped when it is not installed.
Stack
Java 25, Gradle 9 with a version catalog
Spring Boot
4.2.0-RC1, Spring AI2.1.0-RC1MCP server (stdio)Apache HttpClient 5.6.5 (EWS with NTLM), StAX for SOAP
Eclipse Angus Mail 2.0.5 (IMAP and MIME parsing)
Apache Lucene 10.5.2 (index, Russian and English analysis, highlighting)
pandoc 3.x (external process), Apache PDFBox 3.0.5, Apache POI 5.4.1
Documentation
Document | Contents |
The connections file, passwords, Exchange, Mail.ru and Gmail setup | |
Registering the server with MCP clients, environment variables | |
User-run commands, their output and exit codes | |
Search syntax, dates, copies, conversations, word forms | |
Read-only protection, sign-in policy, credentials, local data, secret filter | |
Common problems and what to check first | |
Rules for AI agents changing this repository, and the map of engineering documents ( | |
Plan, decisions and real-mailbox results |
License
This project is licensed under the Apache License, Version 2.0. Dependencies keep their own licenses: THIRD_PARTY_NOTICES.md.
Available Tools
10 toolsgetAttachmentgetAttachmentARead-onlyIdempotent
Read an attachment's saved extracted text as Markdown, in chunks, with its metadata and local file paths. This reads existing text; it does not convert the file on demand. If text is absent, extracted text is unavailable, not proof that the original attachment is empty. The original may still be available at path; path is absent if the file is missing.
Get file from getMessage's attachments[].file or a search hit's snippetAttachmentFile, keeping that message's connection and key. To continue a long text, call this tool again with the same connection, key and file and offset=nextOffset. Stop when there is no nextOffset.
Inputs: key (required), file (required), connection (required), offset, +1 more. Returns: An attachment and a chunk of its text.
getMessagegetMessageARead-onlyIdempotent
Read one locally stored message: headers, a body chunk as Markdown, and an attachment list. nextOffset continues only the body; headers and the attachment list are returned on each call. If body is absent, saved body text is unavailable; inspect state and error rather than assuming the original message was empty.
When reviewing many messages, do not open every card; choose from the list first. To check a message, use a small maxChars, and continue with nextOffset if it looks relevant.
To read an attachment, call getAttachment with the same connection and key, and file=attachments[].file. Use file, not name or path. The list includes files extracted from attached archives and messages; parent is the containing attachment's file. For the conversation, call getThread with the same connection and key.
Inputs: key (required), connection (required), offset, maxChars. Returns: A message: headers, a body chunk and attachments.
getThreadgetThreadARead-onlyIdempotent
List the locally indexed conversation containing a message, across all folders of one connection. Returns cards without bodies, oldest first, with undated messages last. Only locally indexed messages can appear. Messages are linked by reply headers (Message-ID, In-Reply-To, References), not by subject or participants.
Read each message with getMessage using the same connection and that card's key. Recognized copies are returned once, with other keys and folders under copies; total and paging count groups.
Inputs: key (required), connection (required), limit, offset. Returns: A page of a conversation.
listConnectionslistConnectionsARead-onlyIdempotent
List the configured mailboxes. Call first when the mailbox to use is not known yet: name is the value for the 'connection' argument of every other tool, description says what the mailbox is for, configError explains why an entry cannot be used. This reads local configuration without signing in. localDataAvailable indicates a local data directory, not complete or up-to-date mail; use listFolders and syncStatus to inspect coverage.
Inputs: no named parameters. Returns: Configured mailboxes.
listFolderslistFoldersARead-onlyIdempotent
List locally known folders in one connection, with folder keys, paths and local indexed message counts. Pass a folder's key as folder to listMessages or search; keep the same connection. synced=false means a completed folder sync has not been recorded and messages may be missing. synced=true does not guarantee current mail; use syncStatus for the latest sync's time and outcome. This tool does not discover folders on the server.
Inputs: connection (required). Returns: Folders of the local copy.
listMessageslistMessagesARead-onlyIdempotent
Browse locally indexed messages in one folder, newest first, optionally within a date range. Undated messages come last without date bounds and are excluded with bounds. For keyword search use search; for a date range across all folders use search without query.
Returns cards without bodies. Choose from the cards before opening anything: pass a chosen card's key and the same connection to getMessage to read it, or to getThread for its conversation. Every stored copy counts separately here; search and getThread group recognized copies. read/flagged describe the last sync observation.
Inputs: folder (required), connection (required), limit, since, +2 more. Returns: A page of a folder's messages.
searchsearchARead-onlyIdempotent
Search locally synced messages in one connection. Choose query and field for text search; optionally restrict by folder and dates. Text results are most relevant first. To list a period's mail across all folders, omit query and supply since or until; results are cards without bodies, newest first, without snippets. To combine a sender with words in another field, use from with query and field; from alone lists that sender's cards the same way.
To review many messages, list the cards first and choose from sender, subject, date, read status and the attachment flag. Then search text for what cards cannot show, such as the user's name, and open only the chosen messages with getMessage. Automated mail can hold assignments, questions or errors, so a routine subject does not prove a message is unimportant. When reporting, say which messages you did not open.
Subject, body and attachment text support Russian and English word forms; irregular forms and synonyms may be missed. If results are sparse, try fewer words, other forms, synonyms or the other language in separate calls. An empty result does not prove the mail is absent: only synced, indexed content is searched.
Read a hit with getMessage using the same connection and the hit's key. Snippets mark matches as word, but may show only part of a match or body context. If a hit has snippetAttachmentFile, read that attachment with getAttachment using the same connection, the hit's key and file=snippetAttachmentFile. Recognized copies are returned once; copies lists other matching keys and folders. total and paging count these groups.
Inputs: connection (required), from, field, limit, +5 more. Returns: A page of search results.
summarizeSenderssummarizeSendersARead-onlyIdempotent
Count locally synced messages by sender address or domain in one connection, with each sender's dates and folders, to see who sends how much and where it is filed. Without filters it covers the whole local mailbox; optionally restrict by folder and dates, or by query and field with the same syntax as search, for example to preview what a mail rule would match; from adds one sender address to a query. The totals state what the counts cover, including messages without a date or a parsable sender.
Counts do not show mailbox rules or when messages were moved: old messages left in a folder do not prove that a rule fails, so compare each folder's dates. A sender does not define a message's purpose; list or search that sender's cards with search before recommending anything.
messages counts recognized copies once; folders counts every stored copy, so its sum can exceed messages.
Inputs: connection (required), from, field, limit, +6 more. Returns: A page of sender counts, with totals for everything the filters matched.
syncsyncARead-only
Refresh one connection's local mail copy from the mail server, including new messages, removals, moves and read/flag states. The remote mailbox is not changed. Call when the user needs newer mail than the local copy. Runs in the background; the first sync can take a long time.
status=started means launched, not finished. For started or alreadyRunning, check syncStatus with the same connection while state is running; do not call sync again to check progress. lockedByOtherProcess means another process holds the local write lock and this call started no sync. That process may be an offline command; syncStatus reports sync runs only.
For refused, relay message to the user and do not retry: after a rejected sign-in, the user must fix the credentials and run mail-sync in a terminal.
Inputs: connection (required). Returns: Result of the sync request.
syncStatussyncStatusARead-onlyIdempotent
Read local progress or the result of the current or last sync; this does not start a sync or contact the mail server. state=running means still working; completed means the run finished; failed means the run stopped with an error; interrupted means the syncing process ended before finishing; never means no sync is recorded. phase is the stage reached; checkingLocal and checkingFolders can take minutes with no folder progress yet.
While running, other tools may see incomplete results. Check state to decide whether to keep waiting. The failed count is a count of messages: completed can still have failed>0. Inspect error and signInRejected for a failed run. If signInRejected is true, tell the user to fix credentials and run mail-sync in a terminal; repeated sync calls cannot recover it. Timestamps describe this run, not a guarantee that the local mail is current now.
Inputs: connection (required). Returns: Status of the current or last sync.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 10 tools
Each tool has a distinct role: search for keyword text, listMessages for folder browsing, getMessage/getAttachment/getThread for reading, summarizeSenders for aggregates, and sync/syncStatus for refresh vs. progress. The main risk is search vs listMessages, which both return message cards, but the descriptions explicitly separate text search from folder listing. sync vs syncStatus could also be confused but is clearly delineated as action vs. read-only status.
Mostly consistent camelCase verb_noun: getMessage, listMessages, getAttachment, getThread, listConnections, listFolders, summarizeSenders. Deviations are the bare verb 'search' (no noun) and the action/state pair 'sync'/'syncStatus', which break the pattern slightly but remain readable and predictable.
Ten tools is well within the sweet spot and each earns its place, covering discovery, sync, browsing, reading and attachments. No redundant or trivial tools are present.
For a local read-only mail mirror the surface is thorough: connection/folder discovery, sync plus progress, folder browsing, cross-folder search, message/thread/attachment reading, and sender aggregation. The clear gaps are write-side operations (send, draft, reply, move, mark read/unread), though the descriptions imply the server is deliberately read-only against the remote mailbox.
Maintenance
Related MCP Connectors
Your own AI reads, searches and drafts in your mailbox, on your Windows computer.
Email for AI agents: read, search and send from your Gmail, Outlook, Yahoo, iCloud or IMAP inbox.
Private, EU-hosted email for AI agents over JMAP: read, search, reply, draft, organize, send.
Email on your own domains for AI agents: read, search, draft, reply and send from real mailboxes.
Related MCP Servers
- AlicenseAqualityCmaintenanceReads and searches local email archives (.mbox or .eml) with full MIME parsing, enabling queries about senders, subjects, dates, and bodies while keeping all data on your machine.3MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to search and read a local, provider-independent email archive, reconstruct contacts and interactions, and prepare draft responses without sending anything.1MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to search and read email, inspect attachments, and optionally send messages and organize folders through existing IMAP and SMTP mailboxes. Supports Docker, stdio, and HTTPS OAuth deployment with read-only or full-access modes.MIT
- AlicenseNot gradedqualityBmaintenanceEnables an AI agent to search and read a single IMAP mailbox through a local, read-only index and write Markdown drafts without ever sending mail.32 PyPIMIT