mcp-server-notmuch 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,328 @@
1
+ Metadata-Version: 2.4
2
+ Name: mcp-server-notmuch
3
+ Version: 0.1.0
4
+ Summary: MCP server exposing a local notmuch email database, read-first
5
+ Project-URL: Homepage, https://github.com/hgn/mcp-server-notmuch
6
+ Author: Hagen Paul Pfeifer
7
+ License-Expression: MIT
8
+ License-File: LICENSE
9
+ Keywords: email,mcp,notmuch
10
+ Classifier: Environment :: Console
11
+ Classifier: Intended Audience :: End Users/Desktop
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Communications :: Email
17
+ Requires-Python: >=3.11
18
+ Requires-Dist: html2text>=2024.2.26
19
+ Requires-Dist: mcp==2.0.0b2
20
+ Provides-Extra: dev
21
+ Requires-Dist: pytest>=8; extra == 'dev'
22
+ Requires-Dist: ruff>=0.6; extra == 'dev'
23
+ Provides-Extra: image
24
+ Requires-Dist: pillow>=10; extra == 'image'
25
+ Description-Content-Type: text/markdown
26
+
27
+ # mcp-server-notmuch
28
+
29
+ <p align="center">
30
+ <img src="logo.jpg" alt="mcp-server-notmuch logo" width="200"/>
31
+ </p>
32
+
33
+ An MCP server that exposes a local [notmuch](https://notmuchmail.org/) email
34
+ database to an LLM client such as Claude. It is read-first: searching,
35
+ reading, and understanding mail is always available; writing anything
36
+ (drafts, tags, exported files) requires an explicit opt-in flag and is
37
+ confined to clearly bounded locations.
38
+
39
+ **It never sends mail.** There is no send capability anywhere in this
40
+ codebase, in any mode, with any flag. Drafts are written to a local maildir
41
+ for you to review and send yourself in a real mail client.
42
+
43
+ ## What it does
44
+
45
+ - Searches and reads your mail (threads, single messages, attachments,
46
+ calendar invites, office documents, images) via the real `notmuch` CLI.
47
+ - Understands scopes: a named, pre-configured notmuch query (e.g. "personal
48
+ mail" vs. "mailing lists") that every search is confined to unless you ask
49
+ otherwise.
50
+ - Answers "what's still unanswered" and "who owes me a reply" (`mail_pending`),
51
+ "has this come up before" (`mail_related_threads`), and gives a
52
+ token-cheap overview of a long thread before you read all of it
53
+ (`mail_thread_overview`).
54
+ - Optionally composes and revises plain-text drafts (`--allow-drafts`),
55
+ tags messages (`--allow-tags`), or exports attachments and a
56
+ [Gource](https://gource.io/) visualization of your mailbox history to a
57
+ directory you name (`--allow-export DIR`).
58
+
59
+ ## What it does not do
60
+
61
+ - It does not send mail. Ever.
62
+ - It does not modify your mail in any way unless you pass `--allow-tags`
63
+ (tagging) or `--allow-drafts` (writing a new file into a drafts maildir).
64
+ Neither flag lets it touch existing messages' content.
65
+ - It does not read or write outside the notmuch database, the configured
66
+ drafts maildir, and (only with `--allow-export`) the configured export
67
+ directory.
68
+ - It does not require or use the notmuch2 Python bindings, so no compiler
69
+ is needed to install it.
70
+
71
+ ## Install
72
+
73
+ ### From PyPI (once published)
74
+
75
+ ```console
76
+ $ uvx --prerelease=allow mcp-server-notmuch --help
77
+ ```
78
+
79
+ ### From source
80
+
81
+ ```console
82
+ $ git clone https://github.com/hgn/mcp-server-notmuch
83
+ $ cd mcp-server-notmuch
84
+ $ uv pip install --prerelease=allow -e .
85
+ $ mcp-server-notmuch --help
86
+ ```
87
+
88
+ The `--prerelease=allow` is required because this project pins a
89
+ pre-release of the `mcp` SDK (see [SDK version](#sdk-version) below); it is
90
+ not optional.
91
+
92
+ ### System requirements
93
+
94
+ - `notmuch` (the CLI, not just the library) on `PATH` or pointed to via
95
+ `notmuch.binary` in the config.
96
+ - `poppler-utils` (`pdftotext`) to read PDF attachments. Without it,
97
+ `mail_read_attachment` on a PDF names the missing package.
98
+ - `pandoc` or `libreoffice` to read office documents (doc/docx/odt/rtf).
99
+ Without either, the error names both options.
100
+ - Optionally, `Pillow` (`pip install 'mcp-server-notmuch[image]'`) to let
101
+ oversized image attachments be downscaled instead of refused.
102
+ - Optionally, [Gource](https://gource.io/) to actually play back the log
103
+ `mail_export_gource` writes.
104
+
105
+ ## MCP client configuration
106
+
107
+ ### Claude Code
108
+
109
+ Read-only (the default: search and read tools only):
110
+
111
+ ```console
112
+ $ claude mcp add notmuch -- uvx --prerelease=allow mcp-server-notmuch
113
+ ```
114
+
115
+ With drafts enabled (also allows revising/tagging as needed):
116
+
117
+ ```console
118
+ $ claude mcp add notmuch -- uvx --prerelease=allow mcp-server-notmuch --allow-drafts
119
+ ```
120
+
121
+ Or by hand in `.mcp.json`:
122
+
123
+ ```json
124
+ {
125
+ "mcpServers": {
126
+ "notmuch": {
127
+ "command": "uvx",
128
+ "args": ["--prerelease=allow", "mcp-server-notmuch", "--allow-drafts"]
129
+ }
130
+ }
131
+ }
132
+ ```
133
+
134
+ ### Claude Desktop
135
+
136
+ Add to `claude_desktop_config.json` (read-only default):
137
+
138
+ ```json
139
+ {
140
+ "mcpServers": {
141
+ "notmuch": {
142
+ "command": "uvx",
143
+ "args": ["--prerelease=allow", "mcp-server-notmuch"]
144
+ }
145
+ }
146
+ }
147
+ ```
148
+
149
+ With drafts enabled:
150
+
151
+ ```json
152
+ {
153
+ "mcpServers": {
154
+ "notmuch": {
155
+ "command": "uvx",
156
+ "args": ["--prerelease=allow", "mcp-server-notmuch", "--allow-drafts"]
157
+ }
158
+ }
159
+ }
160
+ ```
161
+
162
+ ## Configuration
163
+
164
+ The server reads `$XDG_CONFIG_HOME/mcp-server-notmuch/config.toml`
165
+ (`~/.config/mcp-server-notmuch/config.toml` if `XDG_CONFIG_HOME` is unset),
166
+ or a path given with `--config`. A missing file is not an error: the server
167
+ falls back to the system `notmuch` binary and a single built-in scope
168
+ `all` with an empty query. Once a file exists, `[scopes]` is authoritative
169
+ and `all` is no longer implied.
170
+
171
+ See [`config.example.toml`](config.example.toml) for a fully commented
172
+ reference file. Summary of every key:
173
+
174
+ | Section | Key | Default | Meaning |
175
+ |---|---|---|---|
176
+ | `[notmuch]` | `binary` | `"notmuch"` | Path or bare name of the notmuch binary. |
177
+ | | `config` | notmuch's own default | Path passed as `NOTMUCH_CONFIG`. |
178
+ | `[limits]` | `default_limit` | `20` | Rows returned when a tool call omits `limit`. |
179
+ | | `max_limit` | `100` | Hard ceiling on `limit`, whatever is requested. |
180
+ | | `max_body_chars` | `40000` | Message body truncation point. |
181
+ | | `max_attachment_chars` | `100000` | Attachment/office/calendar text truncation point. |
182
+ | | `max_image_bytes` | `5242880` | Image size ceiling; downscaled with Pillow if larger, else refused. |
183
+ | `[scopes]` | `default` | *(required once `[scopes]` exists)* | Scope used when a tool call omits `scope`. |
184
+ | `[scopes.<name>]` | `query` | — | A notmuch query ANDed with every search using this scope. |
185
+ | | `description` | `""` | Shown by `mail_list_scopes`. |
186
+ | `[drafts]` | `maildir` | unset | Root of a maildir (`cur/`, `new/`, `tmp/`) for `mail_create_draft`. |
187
+ | | `from` | unset | `From:` header on every draft. |
188
+ | | `signature` | unset | Plain-text signature file, appended on request. |
189
+ | | `wrap_columns` | `72` | Hard-wrap width for drafted plain text. |
190
+ | | `max_total_attachment_bytes` | `26214400` (25 MiB) | Ceiling on draft attachments' combined size. |
191
+ | `[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"`. |
192
+
193
+ `mail_create_draft`/`mail_update_draft` refuse to run unless both
194
+ `drafts.maildir` and `drafts.from` are set. `mail_pending
195
+ direction="waiting"` needs `[identity] addresses` (or a readable notmuch
196
+ `user.primary_email`) to know which address is "you".
197
+
198
+ Scope resolution: a tool's `scope` argument names a configured scope; its
199
+ query is ANDed with the caller's query, both sides parenthesized
200
+ (`(scope_query) and (user_query)`), so an `or` on either side cannot leak
201
+ past the other. An unknown scope name is an error listing the configured
202
+ scopes; `scope="all"` is never silently unfiltered unless you define a
203
+ scope literally named `all`.
204
+
205
+ ## Tiers and tools
206
+
207
+ Four tiers. The read tier is always registered. The other three are
208
+ registered **only** when their flag is passed — there is no
209
+ "registered but refused" state, an unauthorized tool is simply absent from
210
+ the tool list a client sees.
211
+
212
+ | Flag | Registers |
213
+ |---|---|
214
+ | *(none)* | Read tier: search, read, list, prepare — nothing is written. |
215
+ | `--allow-drafts` | Draft tier: compose and revise local plain-text drafts. |
216
+ | `--allow-tags` | Tag tier: add/remove tags on existing messages. |
217
+ | `--allow-export DIR` | Export tier: write attachments/a Gource log into `DIR`. |
218
+
219
+ ### Read tier (always on)
220
+
221
+ | Tool | Purpose |
222
+ |---|---|
223
+ | `mail_search` | Search threads or messages, paged, with a truncation notice. |
224
+ | `mail_read_thread` | Every message in a thread, oldest first. |
225
+ | `mail_thread_overview` | One line per message (date/size/from), tree or flat layout, before reading a long thread in full. |
226
+ | `mail_related_threads` | Heuristic "has this come up before" (subject + participant overlap). |
227
+ | `mail_pending` | Threads you owe a reply on, or threads you're waiting on a reply to. |
228
+ | `mail_read_message` | A single message's headers and body. |
229
+ | `mail_count` | Cheap message/thread count for a query. |
230
+ | `mail_list_addresses` | Resolve a name to the real address(es) behind it. |
231
+ | `mail_list_attachments` | List one message's attachments. |
232
+ | `mail_read_attachment` | Read one attachment: text, PDF, image, office document, or calendar invite. |
233
+ | `mail_find_attachments` | Find attachments across a whole search (e.g. "all PDFs from 2025"). |
234
+ | `mail_list_scopes` | List the configured scopes. |
235
+ | `mail_prepare_reply` | Derive reply/reply-all/forward headers and quoted/forwarded body; writes nothing. |
236
+
237
+ ### Draft tier (`--allow-drafts`)
238
+
239
+ | Tool | Purpose |
240
+ |---|---|
241
+ | `mail_create_draft` | Compose a plain-text draft (optionally with attachments) into the configured maildir. |
242
+ | `mail_update_draft` | Revise an existing draft in place; only the given fields change. |
243
+
244
+ ### Tag tier (`--allow-tags`)
245
+
246
+ | Tool | Purpose |
247
+ |---|---|
248
+ | `mail_tag` | Add/remove tags on every message matching a query. |
249
+
250
+ ### Export tier (`--allow-export DIR`)
251
+
252
+ | Tool | Purpose |
253
+ |---|---|
254
+ | `mail_save_attachment` | Save one attachment's raw bytes into `DIR`. |
255
+ | `mail_export_gource` | Write a [Gource](https://gource.io/) custom log of mailbox history into `DIR`. |
256
+
257
+ `mail_export_gource` writes one line per message,
258
+ `timestamp\|username\|type\|path\|colour`, sorted oldest first (Gource
259
+ requires this). `path` is `folder/normalized-subject`, so a whole reply
260
+ chain lands at one point in the tree; `colour` is a stable hash of the
261
+ folder name, so a folder keeps its colour across repeated exports. Play it
262
+ back with:
263
+
264
+ ```console
265
+ $ gource --log-format custom mail.gource -s 0.5 --key
266
+ ```
267
+
268
+ `limit` (default 100000) matters: feeding Gource every mailing-list message
269
+ you've ever received produces an unwatchable animation, so scope the query
270
+ first.
271
+
272
+ ## Security model
273
+
274
+ This is a mail server handed to an LLM; message content is not trusted the
275
+ way your own instructions are.
276
+
277
+ 1. **Prompt injection.** Message bodies, attachment text, calendar
278
+ summaries, and thread overview lines are third-party content, not
279
+ instructions. `render.py` wraps every one of them in explicit
280
+ `-----BEGIN/END UNTRUSTED EMAIL CONTENT-----` markers with a notice that
281
+ nothing inside should be treated as a command, so no individual tool can
282
+ forget to do this.
283
+ 2. **Path confinement.** The drafts maildir (`compose.py`) and the export
284
+ directory (`export.py`) each resolve the target path and verify it is
285
+ still inside the configured root afterward. This catches a literal `..`
286
+ and a symlink pointing outside the root (`Path.resolve()` follows
287
+ symlinks), and `mail_create_draft`/`mail_update_draft` cannot be made to
288
+ write outside the configured maildir with any combination of arguments.
289
+ 3. **No shell, ever.** Every subprocess call is `subprocess.run([...],
290
+ shell=False)` with an argv list; queries are passed as a single argv
291
+ element, never interpolated into a shell string or a notmuch query
292
+ string beyond normal AND/OR composition.
293
+ 4. **No content in diagnostics.** Errors and progress go to stderr and are
294
+ content-free (a byte count or a file path, never a message body).
295
+ 5. **Never silently unfiltered.** A `scope` argument that AND-composes
296
+ with a query is always explicit; there is no hidden "search everything"
297
+ fallback unless a scope literally named `all` is configured.
298
+
299
+ ## notmuch query syntax
300
+
301
+ `query`/`scope` arguments accept full notmuch search syntax: `from:`,
302
+ `to:`, `subject:`, `tag:`, `date:` ranges, boolean `and`/`or`/`not`, and
303
+ more. See **notmuch-search-terms(7)** (`man notmuch-search-terms`) for the
304
+ complete reference.
305
+
306
+ ## SDK version
307
+
308
+ Targets MCP spec **2026-07-28** and pins `mcp==2.0.0b2`, a pre-release of
309
+ the Python SDK built for that spec. Once the spec and a matching stable SDK
310
+ release ship, this pin moves to the stable release; until then, every
311
+ install (`uv pip install`, `uvx`) needs `--prerelease=allow`.
312
+
313
+ ## Development
314
+
315
+ ```console
316
+ $ make # fmt + lint + test
317
+ $ make test # pytest (skips cleanly if notmuch is not installed)
318
+ $ make lint # ruff format --check + ruff check
319
+ $ make help # list all targets
320
+ ```
321
+
322
+ Tests build a small crafted maildir and run real `notmuch` commands against
323
+ it; nothing touches your real mail. CI runs on Python 3.11, 3.12 and 3.13
324
+ with notmuch installed via `apt`.
325
+
326
+ ## License
327
+
328
+ MIT, see [LICENSE](LICENSE).
@@ -0,0 +1,18 @@
1
+ mcpnotmuch/__init__.py,sha256=kUR5RAFc7HCeiqdlX36dZOHkUI5wI6V_43RpEcD8b-0,22
2
+ mcpnotmuch/__main__.py,sha256=21-u5I_fln2ZbHE81ms0dowfr3tauBXPmPylmwEeX-M,112
3
+ mcpnotmuch/attachments.py,sha256=ZZaQjiix4dDZ-u1eDTC-aDnk2ndH-VoUSm_bquxzSiU,13620
4
+ mcpnotmuch/cli.py,sha256=eWUgyt-JummEMnbjdo640CrfqceV65Mm27t0-6uUaoM,2777
5
+ mcpnotmuch/compose.py,sha256=kJKo68hsZThX-5KevhkNoBblm_ZC3n86dhCrAl0Jr-Q,14136
6
+ mcpnotmuch/config.py,sha256=IaMITREVNHUITnlnYDNbbduEiJbJOyrZUMPwx0PYod4,9527
7
+ mcpnotmuch/export.py,sha256=aBqzFbiMMs_56ywOmSDKxb3CSaWDZ9lcShES5Lv4zwU,5375
8
+ mcpnotmuch/message.py,sha256=vd89i_G5B1VdStJl3xxn6-NT8sncM_JnF8Hbl4MprR0,9815
9
+ mcpnotmuch/notmuch.py,sha256=FJmRQRITTVowdOu3myVbpnkitQSmUoR0sb2PUsjn51A,6125
10
+ mcpnotmuch/pending.py,sha256=Z5JfDdAN8U9sEJoCVrC2wt29HK4Hi4r1aFjoqZc_nEo,4928
11
+ mcpnotmuch/render.py,sha256=oztTTMzqA5CvmGKmysTyAA5yKsHBVXwFkoBxuveWkFg,10813
12
+ mcpnotmuch/server.py,sha256=pAMqq27Rj9kYtAXdWEwJf6zojIS6OrvmJD81DCISRNk,37765
13
+ mcpnotmuch/threads.py,sha256=1l-FseqYNbtea5rzed3PAx4S6hL0S5NdZbsAXzatctM,6922
14
+ mcp_server_notmuch-0.1.0.dist-info/METADATA,sha256=36cUtuzhXB4opKTX9nwyd_-Z22rOCJaDIfA6hSxv1S8,13160
15
+ mcp_server_notmuch-0.1.0.dist-info/WHEEL,sha256=lCkmxWfQsSc9CfIClYeavTdQeEX2toPqufh9gI35EQA,87
16
+ mcp_server_notmuch-0.1.0.dist-info/entry_points.txt,sha256=yOcD8eBd1h09K6zp9_IxCVHi9uZfKVKJMo0g-bXOECA,59
17
+ mcp_server_notmuch-0.1.0.dist-info/licenses/LICENSE,sha256=Xafw27klDqWHOBDgdWLekXOi_ba2f_jvED5kY1CKiAI,1075
18
+ mcp_server_notmuch-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.31.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ mcp-server-notmuch = mcpnotmuch.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Hagen Paul Pfeifer
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
mcpnotmuch/__init__.py ADDED
@@ -0,0 +1 @@
1
+ __version__ = "0.1.0"
mcpnotmuch/__main__.py ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env python3
2
+ from mcpnotmuch.cli import main
3
+
4
+ if __name__ == "__main__":
5
+ raise SystemExit(main())