Notmuch
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 | |
|
|
| Rows returned when a tool call omits |
|
| Hard ceiling on | |
|
| Message body truncation point. | |
|
| Attachment/office/calendar text truncation point. | |
|
| 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".
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, with a truncation notice. |
| 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 --keylimit (default 100000) matters: feeding Gource every mailing-list message
you've ever received produces an unwatchable animation, so scope the query
first.
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.
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.
Maintenance
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/hgn/mcp-server-notmuch'
If you have feedback or need assistance with the MCP directory API, please join our Discord server