Notmuch
A read-first MCP server providing access to a local Notmuch email database, enabling LLM clients to search, read, and analyze mail, with optional write capabilities for drafts, tags, and exports.
Core Capabilities (Always Available)
Search mail (
mail_search): Full notmuch query syntax, with paging, sorting, and thread/message granularity.Read threads/messages (
mail_read_thread,mail_read_message): Retrieve entire threads or individual messages.Thread overview (
mail_thread_overview): One-line-per-message summary (date, size, sender) for quick assessment.Find related threads (
mail_related_threads): Heuristic overlap of subject and participants.Pending mail (
mail_pending): Identify threads you owe a reply to or are waiting on.Count mail (
mail_count): Cheap message/thread counts without fetching content.Resolve addresses (
mail_list_addresses): Map names to actual email addresses, ranked by usage.Attachments: List (
mail_list_attachments), read content (mail_read_attachment– supports text, PDF, images, office docs, ICS), and find across searches (mail_find_attachments).Prepare reply (
mail_prepare_reply): Compute reply/reply-all/forward headers and quoted body (read-only).List scopes (
mail_list_scopes): Discover pre-configured search scopes.
Optional Write Capabilities (Require Flags)
Drafts (
--allow-drafts): Create (mail_create_draft) or update (mail_update_draft) plain-text drafts with attachments in a local maildir.Tagging (
--allow-tags): Add or remove tags on messages (mail_tag).Export (
--allow-export DIR): Save raw attachment bytes (mail_save_attachment) or generate a Gource visualization of mailbox history (mail_export_gource).
Limitations
Never sends email.
Never modifies message content (only tags and drafts).
Reads/writes only within the notmuch database, drafts maildir, and export directory.
mcp-server-notmuch
An MCP server that exposes a local notmuch email database to an LLM client such as Claude. It is read-first: searching, reading, and understanding mail is always available; writing anything (drafts, tags, exported files) requires an explicit opt-in flag and is confined to clearly bounded locations.
It never sends mail. There is no send capability anywhere in this codebase, in any mode, with any flag. Drafts are written to a local maildir for you to review and send yourself in a real mail client.
What it does
Searches and reads your mail (threads, single messages, attachments, calendar invites, office documents, images) via the real
notmuchCLI.Understands scopes: a named, pre-configured notmuch query (e.g. "personal mail" vs. "mailing lists") that every search is confined to unless you ask otherwise.
Answers "what's still unanswered" and "who owes me a reply" (
mail_pending), "has this come up before" (mail_related_threads), and gives a token-cheap overview of a long thread before you read all of it (mail_thread_overview).Optionally composes and revises plain-text drafts (
--allow-drafts), tags messages (--allow-tags), or exports attachments and a Gource visualization of your mailbox history to a directory you name (--allow-export DIR).
Related MCP server: notmuchproxy
What it does not do
It does not send mail. Ever.
It does not modify your mail in any way unless you pass
--allow-tags(tagging) or--allow-drafts(writing a new file into a drafts maildir). Neither flag lets it touch existing messages' content.It does not read or write outside the notmuch database, the configured drafts maildir, and (only with
--allow-export) the configured export directory.It does not require or use the notmuch2 Python bindings, so no compiler is needed to install it.
Install
From PyPI (once published)
$ uvx --prerelease=allow mcp-server-notmuch --helpFrom source
$ git clone https://github.com/hgn/mcp-server-notmuch
$ cd mcp-server-notmuch
$ uv pip install --prerelease=allow -e .
$ mcp-server-notmuch --helpThe --prerelease=allow is required because this project pins a
pre-release of the mcp SDK (see SDK version below); it is
not optional.
System requirements
notmuch(the CLI, not just the library) onPATHor pointed to vianotmuch.binaryin the config.poppler-utils(pdftotext) to read PDF attachments. Without it,mail_read_attachmenton a PDF names the missing package.pandocorlibreofficeto read office documents (doc/docx/odt/rtf). Without either, the error names both options.Optionally,
Pillow(pip install 'mcp-server-notmuch[image]') to let oversized image attachments be downscaled instead of refused.Optionally, Gource to actually play back the log
mail_export_gourcewrites.
MCP client configuration
Claude Code
Read-only (the default: search and read tools only):
$ claude mcp add notmuch -- uvx --prerelease=allow mcp-server-notmuchWith drafts enabled (also allows revising/tagging as needed):
$ claude mcp add notmuch -- uvx --prerelease=allow mcp-server-notmuch --allow-draftsOr by hand in .mcp.json:
{
"mcpServers": {
"notmuch": {
"command": "uvx",
"args": ["--prerelease=allow", "mcp-server-notmuch", "--allow-drafts"]
}
}
}Claude Desktop
Add to claude_desktop_config.json (read-only default):
{
"mcpServers": {
"notmuch": {
"command": "uvx",
"args": ["--prerelease=allow", "mcp-server-notmuch"]
}
}
}With drafts enabled:
{
"mcpServers": {
"notmuch": {
"command": "uvx",
"args": ["--prerelease=allow", "mcp-server-notmuch", "--allow-drafts"]
}
}
}Configuration
The server reads $XDG_CONFIG_HOME/mcp-server-notmuch/config.toml
(~/.config/mcp-server-notmuch/config.toml if XDG_CONFIG_HOME is unset),
or a path given with --config. A missing file is not an error: the server
falls back to the system notmuch binary and a single built-in scope
all with an empty query. Once a file exists, [scopes] is authoritative
and all is no longer implied.
See config.example.toml for a fully commented
reference file. Summary of every key:
Section | Key | Default | Meaning |
|
|
| Path or bare name of the notmuch binary. |
| notmuch's own default | Path passed as | |
|
| unset (unlimited) | Message body truncation point; unset means full body every time. |
| unset (unlimited) | Attachment/office/calendar text truncation point; unset means full text every time. | |
|
| Image size ceiling; downscaled with Pillow if larger, else refused. | |
|
| (required once | Scope used when a tool call omits |
|
| — | A notmuch query ANDed with every search using this scope. |
|
| Shown by | |
|
| unset | Root of a maildir ( |
| unset |
| |
| unset | Plain-text signature file, appended on request. | |
|
| Hard-wrap width for drafted plain text. | |
|
| Ceiling on draft attachments' combined size. | |
|
| notmuch's | Your own address(es); used to exclude yourself from reply-all and to detect |
mail_create_draft/mail_update_draft refuse to run unless both
drafts.maildir and drafts.from are set. mail_pending direction="waiting" needs [identity] addresses (or a readable notmuch
user.primary_email) to know which address is "you".
Nothing is truncated by default. This is a local, fast mailbox, not a
rate-limited API: mail_search, mail_pending, mail_related_threads,
mail_list_addresses, mail_find_attachments and mail_export_gource all
return every matching row unless a tool call passes an explicit limit,
and message bodies/attachment text come back in full unless
limits.max_body_chars/limits.max_attachment_chars are set. Whenever an
explicit limit or char cap does cut something, the output says so:
"Showing N of TOTAL ..." plus a hint to omit limit to see everything.
There is no silent, invisible ceiling anywhere in this server.
Scope resolution: a tool's scope argument names a configured scope; its
query is ANDed with the caller's query, both sides parenthesized
((scope_query) and (user_query)), so an or on either side cannot leak
past the other. An unknown scope name is an error listing the configured
scopes; scope="all" is never silently unfiltered unless you define a
scope literally named all.
Tiers and tools
Four tiers. The read tier is always registered. The other three are registered only when their flag is passed — there is no "registered but refused" state, an unauthorized tool is simply absent from the tool list a client sees.
Flag | Registers |
(none) | Read tier: search, read, list, prepare — nothing is written. |
| Draft tier: compose and revise local plain-text drafts. |
| Tag tier: add/remove tags on existing messages. |
| Export tier: write attachments/a Gource log into |
Read tier (always on)
Tool | Purpose |
| Search threads or messages, paged; returns everything unless |
| Every message in a thread, oldest first. |
| One line per message (date/size/from), tree or flat layout, before reading a long thread in full. |
| Heuristic "has this come up before" (subject + participant overlap). |
| Threads you owe a reply on, or threads you're waiting on a reply to. |
| A single message's headers and body. |
| Cheap message/thread count for a query. |
| Resolve a name to the real address(es) behind it. |
| List one message's attachments. |
| Read one attachment: text, PDF, image, office document, or calendar invite. |
| Find attachments across a whole search (e.g. "all PDFs from 2025"). |
| List the configured scopes. |
| Derive reply/reply-all/forward headers and quoted/forwarded body; writes nothing. |
Draft tier (--allow-drafts)
Tool | Purpose |
| Compose a plain-text draft (optionally with attachments) into the configured maildir. |
| Revise an existing draft in place; only the given fields change. |
Tag tier (--allow-tags)
Tool | Purpose |
| Add/remove tags on every message matching a query. |
Export tier (--allow-export DIR)
Tool | Purpose |
| Save one attachment's raw bytes into |
| Write a Gource custom log of mailbox history into |
mail_export_gource writes one line per message,
timestamp\|username\|type\|path\|colour, sorted oldest first (Gource
requires this). path is folder/normalized-subject, so a whole reply
chain lands at one point in the tree; colour is a stable hash of the
folder name, so a folder keeps its colour across repeated exports. Play it
back with:
$ gource --log-format custom mail.gource -s 0.5 --keyAll matching messages are included by default; limit matters when the
query is broad, since feeding Gource every mailing-list message you've
ever received produces an unwatchable animation, so scope the query first
or set limit explicitly.
Security model
This is a mail server handed to an LLM; message content is not trusted the way your own instructions are.
Prompt injection. Message bodies, attachment text, calendar summaries, and thread overview lines are third-party content, not instructions.
render.pywraps every one of them in explicit-----BEGIN/END UNTRUSTED EMAIL CONTENT-----markers with a notice that nothing inside should be treated as a command, so no individual tool can forget to do this.Path confinement. The drafts maildir (
compose.py) and the export directory (export.py) each resolve the target path and verify it is still inside the configured root afterward. This catches a literal..and a symlink pointing outside the root (Path.resolve()follows symlinks), andmail_create_draft/mail_update_draftcannot be made to write outside the configured maildir with any combination of arguments.No shell, ever. Every subprocess call is
subprocess.run([...], shell=False)with an argv list; queries are passed as a single argv element, never interpolated into a shell string or a notmuch query string beyond normal AND/OR composition.No content in diagnostics. Errors and progress go to stderr and are content-free (a byte count or a file path, never a message body).
Never silently unfiltered. A
scopeargument that AND-composes with a query is always explicit; there is no hidden "search everything" fallback unless a scope literally namedallis configured.Never silently truncated. This is a local, fast mailbox: result rows, message bodies and attachment text are returned in full unless a tool call passes an explicit
limitor the config sets an explicitlimits.max_body_chars/limits.max_attachment_chars. Whenever one of those does cut something, the output states the true total and how to see the rest, never a silent cut.
notmuch query syntax
query/scope arguments accept full notmuch search syntax: from:,
to:, subject:, tag:, date: ranges, boolean and/or/not, and
more. See notmuch-search-terms(7) (man notmuch-search-terms) for the
complete reference.
SDK version
Targets MCP spec 2026-07-28 and pins mcp==2.0.0b2, a pre-release of
the Python SDK built for that spec. Once the spec and a matching stable SDK
release ship, this pin moves to the stable release; until then, every
install (uv pip install, uvx) needs --prerelease=allow.
Development
$ make # fmt + lint + test
$ make test # pytest (skips cleanly if notmuch is not installed)
$ make lint # ruff format --check + ruff check
$ make help # list all targetsTests build a small crafted maildir and run real notmuch commands against
it; nothing touches your real mail. CI runs on Python 3.11, 3.12 and 3.13
with notmuch installed via apt.
License
MIT, see LICENSE.
Available Tools
13 toolsmail_countCount mailARead-only
Count messages or threads matching a query, without fetching any of them.
Cheap way to check whether a correspondent, subject or thread exists at all before running a full mail_search, e.g. "how many mails did I get from X" (count="messages", the right default) versus "how many separate conversations" (count="threads"). Not a substitute for mail_search when you need to see the matches themselves.
Args:
query: A notmuch query, e.g. 'from:alice'. See notmuch-search-terms(7)
for the full syntax, including relative date ranges such as
'date:this_year..', 'date:last_month..', 'date:1Y..' and
'date:2026-01-01..2026-06-30'.
scope: Name of a configured scope to AND with query (see
mail_list_scopes). Defaults to the configured default scope.
count: 'messages' or 'threads'.
Inputs: query (required), count, scope.
mail_find_attachmentsFind mail attachmentsARead-only
Find attachments across a whole search, not just within one message.
Use this for questions like "all invoices from 2025" or "which PDFs
did I get from the accountant", where the attachment itself, not the
message, is what you are looking for. For a single message's
attachments, use mail_list_attachments instead. Note that notmuch's
own query syntax already supports 'attachment:*.pdf' and
'tag:attachment' inside query if you want to filter at the notmuch
level too.
Args:
query: A notmuch query selecting the messages to scan for attachments.
scope: Name of a configured scope to AND with query (see
mail_list_scopes). Defaults to the configured default scope.
type: Filter by 'pdf', 'image', 'doc' (office documents), or a raw
filename extension such as 'png' or 'xlsx'. Omit for no filter.
limit: Maximum number of attachment rows to return. Omit for all
results (the default); set it only to cap the number returned,
and when it truncates the total is still reported.
Inputs: query (required), type, limit, scope.
mail_list_addressesList mail addressesARead-only
Resolve a name or query into the concrete email addresses behind it.
Searching from: directly is unreliable: it also matches mail that merely mentions the name in a display name (e.g. a share notification like "Kathrin Pietsch (via Google Keep) <keep-shares@ google.com>"), and a name can belong to more than one real address or person. Call this tool first whenever you only have a name, then search or count using the address(es) it returns.
Args:
query: A notmuch query, typically a name fragment, e.g. 'kathrin'.
scope: Name of a configured scope to AND with query (see
mail_list_scopes). Defaults to the configured default scope.
output: 'sender' (addresses this query's messages were From),
'recipients' (addresses in To/Cc/Bcc), or 'count' (sender
addresses ranked by occurrence count, the way to find
someone's most-used address among several).
limit: Maximum number of addresses to return. Omit for all results
(the default); set it only to cap the number returned, and
when it truncates the total is still reported.
Inputs: query (required), limit, scope, output.
mail_list_attachmentsList mail attachmentsARead-only
List a message's attachments (part index, filename, content type, size).
Call this before mail_read_attachment to learn valid part_index values; it does not return attachment content itself.
Args: message_id: A Message-ID as seen in mail_search/mail_read_thread output.
Inputs: message_id (required).
mail_list_scopesList mail scopesARead-only
List the configured scopes with their notmuch query and description.
Call this to discover valid scope values for mail_search/mail_count/
mail_tag instead of guessing scope names.
Inputs: no named parameters.
mail_pendingPending mailARead-only
Threads that need attention: mail owed by you, or mail you are waiting on.
direction='owed': threads matching scope that no message has ever
been tagged 'replied' on, i.e. mail you have not answered. Use this
for "what do I still need to reply to".
direction='waiting': threads where your own address sent the most recent message and nobody has responded since. Use this for "who owes ME a reply". Needs at least one address configured under [identity] addresses in the config (normally defaulted automatically from notmuch's own user.primary_email/user.other_email); without that, this direction raises an actionable error rather than guessing.
Both directions sort oldest (most overdue) first, since age is the point. This is not a substitute for mail_search when you want to see the messages themselves, only for triaging what is outstanding.
Args: direction: 'owed' (you have not replied) or 'waiting' (you are waiting on a reply). older_than: Only include threads whose relevant date is at least this old, e.g. '14d', '2w', '3m', '1y'. Omit for no age floor. scope: Name of a configured scope to restrict the search (see mail_list_scopes). Defaults to the configured default scope. limit: Maximum number of threads to return. Omit for all results (the default); set it only to cap the number returned, and when it truncates the total is still reported.
Inputs: limit, scope, direction, older_than.
mail_prepare_replyPrepare mail replyARead-only
Derive reply/forward headers and the quoted or forwarded body.
This is read-only: it computes what a reply or forward should look like but writes nothing. Pass the result's To/Cc/Subject/In-Reply-To to mail_create_draft (draft tier) if you want it actually saved as a draft.
Args: message_id: A Message-ID as seen in mail_search/mail_read_thread output. quote: Whether to include the original body (quoted with '> ' for reply/reply-all, or as a labelled forwarded block for forward). mode: 'reply' (sender only, honouring Reply-To), 'reply-all' (all original recipients minus your own configured addresses, honouring Mail-Followup-To, which is what mailing lists set and what makes the difference between a correct reply and an embarrassing one), or 'forward' (no In-Reply-To/References, subject gets exactly one 'Fwd:' prefix, body is a labelled forwarded block with the original headers, not an interleaved quote).
Inputs: message_id (required), mode, quote.
mail_read_attachmentRead mail attachmentARead-only
Read one attachment: text, PDF, image, office document or calendar invite.
Dispatches by content type: text/* and PDF (via pdftotext) come back as text; image/* comes back as an actual image the model can look at (downscaled if oversized and Pillow is installed, otherwise refused with its size); office documents (doc/docx/odt/rtf) are converted to text via pandoc or libreoffice; calendar invitations (text/calendar, .ics) are rendered as a readable summary (method, time, location, organizer, attendees with their response status). Call mail_list_attachments first to get a valid part_index. Archives and other binary formats are not supported and raise an explanatory error.
Args: message_id: A Message-ID as seen in mail_search/mail_read_thread output. part_index: The 1-based part index from mail_list_attachments.
Inputs: message_id (required), part_index (required).
mail_read_messageRead mail messageARead-only
Return a single message's headers and body.
Use this for one specific message. For an entire conversation in order, use mail_read_thread instead.
Args: message_id: A Message-ID as seen in mail_search/mail_read_thread output, with or without angle brackets or the 'id:' prefix. response_format: 'concise' (From/Date/Subject, short body) or 'detailed' (full headers, full body up to the configured limit).
Inputs: message_id (required), response_format.
mail_read_threadRead mail threadARead-only
Return every message in a thread, oldest first, with '--- [N/M] ---' separators.
Use this once mail_search has identified a thread_id and you need the conversation in order. For a single message, use mail_read_message instead. For a long thread, consider calling mail_thread_overview first: it shows one line per message (date, size, from, subject changes) so you can pick the one or two messages worth reading in full here, instead of pulling the whole thread.
Args: thread_id: A thread identifier as returned by mail_search (with or without the 'thread:' prefix). response_format: 'concise' (From/Date/Subject, short body) or 'detailed' (full headers, full body up to the configured limit).
Inputs: thread_id (required), response_format.
mail_searchSearch mailARead-only
Search notmuch and return a paged summary, at thread or message granularity.
Use granularity="threads" for "what conversations are there about Y": each row is one thread, dated by its newest (or oldest) matched message, with an authors column that can mix matched and unmatched participants (see the legend in the output). Use granularity="messages" for "the last mail from X" or "how many mails did X write": each row is one matching message with its own date, from and subject.
Do not use this to fetch full bodies (use mail_read_message / mail_read_thread) or to turn a person's name into addresses first (use mail_list_addresses; from: also matches notification mail that merely mentions the name).
Args:
query: A notmuch query, e.g. 'from:alice subject:invoice'. See
notmuch-search-terms(7) for the full syntax, including
'date:this_year..', 'date:last_month..', 'date:1Y..' and
'date:2026-01-01..2026-06-30' for date ranges.
scope: Name of a configured scope to AND with query (see
mail_list_scopes). Defaults to the configured default scope.
limit: Maximum number of rows to return. Omit for all results (the
default); set it only to cap the number returned, and when it
truncates the total is still reported.
offset: Number of matching rows to skip, for paging through
results already seen.
response_format: 'concise' (one line per row) or 'detailed' (adds
message counts/tags for threads, or the message_id for messages).
granularity: 'threads' (one row per conversation) or 'messages'
(one row per matching message).
sort: 'newest-first' or 'oldest-first'.
Inputs: query (required), sort, limit, scope, +3 more.
mail_thread_overviewThread overviewARead-only
One line per message: index, date, size, from, and a marker when the subject changes from the thread's root subject.
Use this before mail_read_thread on any thread you have not looked at yet, especially a long one: it costs a fraction of the tokens and lets you decide which one or two messages to actually read in full, instead of pulling all eighty. Do not use it in place of mail_read_thread when you already know you need the full content.
Args: thread_id: A thread identifier as returned by mail_search (with or without the 'thread:' prefix). layout: 'tree' (the actual reply nesting, from notmuch's own thread structure; for a patch series with parallel discussion strands this is materially different from linear order) or 'flat' (linear oldest-first order, matching mail_read_thread's [N/M] numbering).
Inputs: thread_id (required), layout.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 13 tools
Each tool targets a distinct operation: search, read single message, read thread, thread overview, related threads, pending, count, address resolution, attachment listing, attachment reading, attachment finding, scope listing, and reply preparation. Overlapping tools like mail_search and mail_count are clearly differentiated by output type.
All tools follow the mail_ prefix with snake_case, and most use a verb_noun structure (read_message, list_addresses, find_attachments). A few deviate slightly (mail_search, mail_pending, mail_related_threads) but the pattern is predictable and consistent in style.
13 tools is well-scoped for a mail search and retrieval server. Each tool serves a clear purpose, and the count neither feels excessive nor sparse. The set covers reading, searching, attachments, addresses, and reply preparation without unnecessary duplication.
The read-side coverage is strong, but there are gaps: mail_list_scopes references a mail_tag tool that is not present, and there is no way to modify tags, send mail, or create drafts within this server. The prepare_reply tool is a read-only dead end without a draft/send tool. These omissions will cause agent failures when trying to complete write operations.
Maintenance
Related MCP Connectors
Your IMAP mailbox as an MCP server: read, search and (if you allow it) organize mail. Open source.
Email infrastructure for AI agents — send, receive, search, and reply to email over MCP.
- ORANO MCP ServerDeprecatedio.github.infotik
Read-only MCP server exposing a user ORANO library to their own AI agent.
Related MCP Servers
- AlicenseAqualityDmaintenanceLocal MCP server for multi-account IMAP/SMTP email (iCloud + Gmail via app-specific passwords). Never marks mail read. Cross-folder search, idempotent sends, TLS verified.822 PyPIMIT
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to search and read email from a notmuch archive, providing tools for searching threads, retrieving messages, and listing tags through an MCP endpoint.MIT
- FlicenseNot gradedqualityCmaintenanceLocal IMAP/SMTP MCP server that lets Claude read, search, draft, send, flag, and move mail across multiple IMAP mailboxes. Credentials stay on your machine.-
- AlicenseNot gradedqualityDmaintenanceA minimal MCP server for reading, searching, managing, and sending email over IMAP and SMTP.MIT