Skip to main content
Glama
Notmuch

Notmuch

by hgn

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 notmuch CLI.

  • 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 --help

From source

$ git clone https://github.com/hgn/mcp-server-notmuch
$ cd mcp-server-notmuch
$ uv pip install --prerelease=allow -e .
$ mcp-server-notmuch --help

The --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) on PATH or pointed to via notmuch.binary in the config.

  • poppler-utils (pdftotext) to read PDF attachments. Without it, mail_read_attachment on a PDF names the missing package.

  • pandoc or libreoffice to 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_gource writes.

MCP client configuration

Claude Code

Read-only (the default: search and read tools only):

$ claude mcp add notmuch -- uvx --prerelease=allow mcp-server-notmuch

With drafts enabled (also allows revising/tagging as needed):

$ claude mcp add notmuch -- uvx --prerelease=allow mcp-server-notmuch --allow-drafts

Or 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

[notmuch]

binary

"notmuch"

Path or bare name of the notmuch binary.

config

notmuch's own default

Path passed as NOTMUCH_CONFIG.

[limits]

max_body_chars

unset (unlimited)

Message body truncation point; unset means full body every time.

max_attachment_chars

unset (unlimited)

Attachment/office/calendar text truncation point; unset means full text every time.

max_image_bytes

5242880

Image size ceiling; downscaled with Pillow if larger, else refused.

[scopes]

default

(required once [scopes] exists)

Scope used when a tool call omits scope.

[scopes.<name>]

query

—

A notmuch query ANDed with every search using this scope.

description

""

Shown by mail_list_scopes.

[drafts]

maildir

unset

Root of a maildir (cur/, new/, tmp/) for mail_create_draft.

from

unset

From: header on every draft.

signature

unset

Plain-text signature file, appended on request.

wrap_columns

72

Hard-wrap width for drafted plain text.

max_total_attachment_bytes

26214400 (25 MiB)

Ceiling on draft attachments' combined size.

[identity]

addresses

notmuch's user.primary_email/user.other_email

Your own address(es); used to exclude yourself from reply-all and to detect mail_pending direction="waiting".

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.

--allow-drafts

Draft tier: compose and revise local plain-text drafts.

--allow-tags

Tag tier: add/remove tags on existing messages.

--allow-export DIR

Export tier: write attachments/a Gource log into DIR.

Read tier (always on)

Tool

Purpose

mail_search

Search threads or messages, paged; returns everything unless limit caps it.

mail_read_thread

Every message in a thread, oldest first.

mail_thread_overview

One line per message (date/size/from), tree or flat layout, before reading a long thread in full.

mail_related_threads

Heuristic "has this come up before" (subject + participant overlap).

mail_pending

Threads you owe a reply on, or threads you're waiting on a reply to.

mail_read_message

A single message's headers and body.

mail_count

Cheap message/thread count for a query.

mail_list_addresses

Resolve a name to the real address(es) behind it.

mail_list_attachments

List one message's attachments.

mail_read_attachment

Read one attachment: text, PDF, image, office document, or calendar invite.

mail_find_attachments

Find attachments across a whole search (e.g. "all PDFs from 2025").

mail_list_scopes

List the configured scopes.

mail_prepare_reply

Derive reply/reply-all/forward headers and quoted/forwarded body; writes nothing.

Draft tier (--allow-drafts)

Tool

Purpose

mail_create_draft

Compose a plain-text draft (optionally with attachments) into the configured maildir.

mail_update_draft

Revise an existing draft in place; only the given fields change.

Tag tier (--allow-tags)

Tool

Purpose

mail_tag

Add/remove tags on every message matching a query.

Export tier (--allow-export DIR)

Tool

Purpose

mail_save_attachment

Save one attachment's raw bytes into DIR.

mail_export_gource

Write a Gource custom log of mailbox history into DIR.

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 --key

All 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.

  1. Prompt injection. Message bodies, attachment text, calendar summaries, and thread overview lines are third-party content, not instructions. render.py wraps 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.

  2. 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), and mail_create_draft/mail_update_draft cannot be made to write outside the configured maildir with any combination of arguments.

  3. 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.

  4. 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).

  5. Never silently unfiltered. A scope argument that AND-composes with a query is always explicit; there is no hidden "search everything" fallback unless a scope literally named all is configured.

  6. 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 limit or the config sets an explicit limits.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 targets

Tests 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 tools
mail_countCount mailA
Read-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 attachmentsA
Read-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 addressesA
Read-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 attachmentsA
Read-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 scopesA
Read-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 mailA
Read-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 replyA
Read-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 attachmentA
Read-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 messageA
Read-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 threadA
Read-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_thread_overviewThread overviewA
Read-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

    A4.5/5.0

    Scored across 13 tools

    Disambiguation5/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness3/5

    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

    ActivityInactive
    ResponsivenessLimited data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Local 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.
      8
      22 PyPI
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables 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
    • F
      license
      Not graded
      quality
      C
      maintenance
      Local IMAP/SMTP MCP server that lets Claude read, search, draft, send, flag, and move mail across multiple IMAP mailboxes. Credentials stay on your machine.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      A minimal MCP server for reading, searching, managing, and sending email over IMAP and SMTP.
      MIT