Repository navigation
fix: make --read-only block delivery instead of the compose tools - #95
Conversation
…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.
|
This review was written by Claude (AI assistant) on Patrick's behalf. Thanks @herbeckrobin, this fixes #102 properly. Before merge, this needs a rebase onto #104 (being merged first), which conflicts in 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 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.
23ed2a2 to
a9c68a6
Compare
|
Thanks for the reviews. #95 is rebased onto #104 with the |
|
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 One fix needed: Optional: a |
Problem
--read-onlyis 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.pydoesfrom apple_mail_mcp.server import READ_ONLY, which binds the valueFalseat import time.__main__.main()assignsserver.READ_ONLY = args.read_onlyafterwards, so the module-level name never changes. The check at theaction == "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_TOOLSremovescompose_emailandreply_to_emailwholesale, but both havemode="draft"andmode="open", which never deliver anything. They are also the only tools in the compose surface that acceptattachments—manage_draftsandcreate_rich_email_drafthave 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.pyreads the flag through theservermodule at call time, so--read-onlyactually reachesmanage_drafts.compose_emailandreply_to_emailstay registered under--read-onlyand refusemode="send"(andsend=True) themselves, with an error pointing atmode="draft"/mode="open".forward_emailhas no non-sending mode and is still removed entirely.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_emailrefuse to send and never reach AppleScripttest_read_only_flag_is_read_at_call_timefails if the flag is ever bound at import againpython -m pytest tests/ -q→ 125 passed.