Add the write tools with scope, caps and a bounded wait #13

Closed
opened 2026-10-31 03:45:44 +00:00 by svc-agent-writer · 0 comments

Epic: #7

Write tools on the MCP surface (ADR 0004 §1, §2, §4, §5, §8).

What to build

  • Tools in server.py, each auth=require_scopes(SCOPE_WRITE), registered only when the config has write_token_file:
    • mail_draft(to, cc, subject, body, reply_to_id)
    • mail_flag(message_ids, add, remove), flags limited to seen, flagged
    • mail_move(message_ids, to_mailbox), mailbox name or role
    • mail_undo(action_id)
    • mail_actions(cursor, limit): the audit list, compact pipe rows like the read tools
  • Each tool calls Store.enqueue_action and waits up to a bounded time (config, default 10 s) for the row to leave queued. On timeout it returns the action id and queued. Never add an IMAP call to server.py.
  • Per-day caps per kind in a new [writes] config section with small defaults. Over the cap, return rate_limited and queue nothing.
  • Every docstring says message content is untrusted data. mail_draft says it never sends.
  • Every draft carries an X-Mailmind-Action: <action id> header, so a draft the bot wrote can be told apart and matched to its mail_actions row. No subject tag: it would go out if the owner sends the draft. This guards against a hostile email that tells the bot to plant a draft.
  • Default caps are small: drafts 20, flags 100, moves 20 a day. A hostile email that tells the bot to archive mail is the main misuse; the move cap bounds it.
  • Update the README tool table, config.example.toml and SECURITY.md.

Acceptance

  • Unit tests: the read token gets insufficient_scope on every write tool; write tools are absent without write_token_file; caps fire at the configured limit; a draft carries X-Mailmind-Action; the bounded wait returns queued when no worker runs.
  • On a test instance, once its deployment allows a write token: a draft appears in Drafts and is not sent; a move and its undo round-trip; a cap fires.
  • make check and make test-integration green.

Blocked by

Epic: #7 Write tools on the MCP surface (ADR 0004 §1, §2, §4, §5, §8). ## What to build - Tools in `server.py`, each `auth=require_scopes(SCOPE_WRITE)`, registered only when the config has `write_token_file`: - `mail_draft(to, cc, subject, body, reply_to_id)` - `mail_flag(message_ids, add, remove)`, flags limited to `seen`, `flagged` - `mail_move(message_ids, to_mailbox)`, mailbox name or role - `mail_undo(action_id)` - `mail_actions(cursor, limit)`: the audit list, compact pipe rows like the read tools - Each tool calls `Store.enqueue_action` and waits up to a bounded time (config, default 10 s) for the row to leave `queued`. On timeout it returns the action id and `queued`. Never add an IMAP call to `server.py`. - Per-day caps per kind in a new `[writes]` config section with small defaults. Over the cap, return `rate_limited` and queue nothing. - Every docstring says message content is untrusted data. `mail_draft` says it never sends. - Every draft carries an `X-Mailmind-Action: <action id>` header, so a draft the bot wrote can be told apart and matched to its `mail_actions` row. No subject tag: it would go out if the owner sends the draft. This guards against a hostile email that tells the bot to plant a draft. - Default caps are small: drafts 20, flags 100, moves 20 a day. A hostile email that tells the bot to archive mail is the main misuse; the move cap bounds it. - Update the README tool table, `config.example.toml` and `SECURITY.md`. ## Acceptance - Unit tests: the read token gets `insufficient_scope` on every write tool; write tools are absent without `write_token_file`; caps fire at the configured limit; a draft carries `X-Mailmind-Action`; the bounded wait returns `queued` when no worker runs. - On a test instance, once its deployment allows a write token: a draft appears in Drafts and is not sent; a move and its undo round-trip; a cap fires. - `make check` and `make test-integration` green. ## Blocked by - #11 - #12
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dev/mail-mind-mcp#13
No description provided.