Skip to content

fix: make --read-only block delivery instead of the compose tools - #95

Merged
patrickfreyer merged 4 commits into
patrickfreyer:mainfrom
herbeckrobin:feat/read-only-allows-drafts
Oct 15, 2026
Merged

patrickfreyer merged 4 commits into
patrickfreyer:mainfrom
herbeckrobin:feat/read-only-allows-drafts

Conversation

@herbeckrobin

Copy link
Copy Markdown
Contributor

Problem

--read-only is implemented by removing tools, not by gating the sending path. That has two consequences.

1. The guard on manage_drafts(action="send") never fires.

tools/compose.py does from apple_mail_mcp.server import READ_ONLY, which binds the value False at import time. __main__.main() assigns server.READ_ONLY = args.read_only afterwards, so the module-level name never changes. The check at the action == "send" branch is dead code today, and a draft can be sent in read-only mode.

2. Read-only mode leaves no way to attach a file to a draft.

SEND_TOOLS removes compose_email and reply_to_email wholesale, but both have mode="draft" and mode="open", which never deliver anything. They are also the only tools in the compose surface that accept attachments — manage_drafts and create_rich_email_draft have no such parameter. So a read-only user who wants a draft with a PDF attached has to drop out of the server and write AppleScript by hand, which is what prompted this PR.

Change

  • compose.py reads the flag through the server module at call time, so --read-only actually reaches manage_drafts.
  • compose_email and reply_to_email stay registered under --read-only and refuse mode="send" (and send=True) themselves, with an error pointing at mode="draft" / mode="open".
  • forward_email has no non-sending mode and is still removed entirely.
  • README and CHANGELOG updated to describe the flag as "blocks delivery" rather than "disables tools".

The security property is unchanged: with --read-only, nothing leaves the machine. What changes is that drafting and reviewing, including attachments, keep working.

Tests

Five regression tests in tests/test_compose_tools.py, all of which fail without the change:

  • compose_email / reply_to_email refuse to send and never reach AppleScript
  • both still draft normally
  • test_read_only_flag_is_read_at_call_time fails if the flag is ever bound at import again

python -m pytest tests/ -q → 125 passed.

…rickfreyer#97)

server.py imported FastMCP from mcp.server.fastmcp, the v1 SDK's bundled
module, while pyproject.toml only declares fastmcp>=3.1.0. Since
fastmcp 4.x depends on mcp>=2, where that module was removed, every
fresh install now dies at import time.

Import from the declared dependency instead. --read-only also relied on
FastMCP.remove_tool(), deprecated in 3.x and removed in 4.x; route it
through local_provider.remove_tool(), which 3.1.0 through 4.x all
provide and which raises KeyError on a miss in each.

Verified on fastmcp 3.1.0, 3.4.7 and 4.0.5: test suite passes with
DeprecationWarning as error, and a stdio session completes initialize,
tools/list (27 tools) and a live list_accounts call; --read-only lists
24 tools with the three send tools absent.
@patrickfreyer

Copy link
Copy Markdown
Owner

This review was written by Claude (AI assistant) on Patrick's behalf.

Thanks @herbeckrobin, this fixes #102 properly. compose.py:12 now reads server.READ_ONLY at call time, and on the merged tree manage_drafts(action="send"), compose_email send (plain and HTML) and reply_to_email's default send=True all refuse, with AppleScript/subprocess mocked to raise if reached. 125 tests pass on fastmcp 3.4.7.

Before merge, this needs a rebase onto #104 (being merged first), which conflicts in __main__.py and CHANGELOG.md. The resolution we tested:

for name in SEND_ONLY_TOOLS:
    _remove_tool(mcp, name)

Keep both changelog entries. With that, #104 + #94 + #95 together pass 133 tests on fastmcp 4.1.0, and --read-only exposes 26 tools (only forward_email removed). The current mcp.remove_tool call (__main__.py:62) crashes on fastmcp 4.

Smaller nits:

Note for the maintainer: read-only users can now create drafts with attachments, and drafts sync to IMAP, so the path validation gaps in #103 become a bit more relevant.

Two problems, one cause: the flag was applied by deleting tools rather
than by gating the sending path.

1. The guard in manage_drafts(action="send") never fired. compose.py did
   `from apple_mail_mcp.server import READ_ONLY`, binding the value False
   at import, while __main__ assigns server.READ_ONLY afterwards. The
   module now reads the flag through the server module at call time.

2. --read-only removed compose_email and reply_to_email outright, even
   though their "draft" and "open" modes never deliver anything. Those
   two are also the only tools in the compose surface that accept
   attachments, so read-only mode left no supported way to attach a file
   to a draft. They now stay registered and refuse mode="send"
   themselves. forward_email has no non-sending mode and is still
   removed.

Adds regression coverage for both, including one test that fails if the
flag is ever bound at import time again.
@herbeckrobin
herbeckrobin force-pushed the feat/read-only-allows-drafts branch from 23ed2a2 to a9c68a6 Compare October 14, 2026 20:25
@herbeckrobin

Copy link
Copy Markdown
Contributor Author

Thanks for the reviews. #95 is rebased onto #104 with the _remove_tool loop and both changelog entries. The read-only check in reply_to_email now runs first, so no temp files are left behind, and there's a test for manage_drafts(action="send") under read-only. 129 tests pass on fastmcp 3.4.7 and 4.1.0.
I split the four fixes out of #98 into #107, #108, #109 and #110. The reply/draft part I'd rebuild as one PR against #80 once #91/#92 are in. I'll put a short plan on #80 first. Is that the order you want?

@patrickfreyer

Copy link
Copy Markdown
Owner

This review was written by Claude (AI assistant) on Patrick's behalf.

Thanks @herbeckrobin, the rebase and all three review points look good: send is refused at call time in compose_email, reply_to_email and manage_drafts.

One fix needed: test_reply_still_drafts (tests/test_compose_tools.py:953) patches only run_applescript, but reply_to_email calls subprocess.run(["osascript", ...]) directly (compose.py:950). On Linux CI it fails with FileNotFoundError, and on a Mac it actually drives Mail.app (which is why you saw 129 passing). Could you also patch apple_mail_mcp.tools.compose.subprocess.run (returncode 0, stdout b"DRAFT SAVED")?

Optional: a server.READ_ONLY check at the top of forward_email would keep it safe even if the tool removal ever fails.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants