Skip to content

Add a messages_send tool that asks before each send - #305

Open
mattt wants to merge 16 commits into
mainfrom
mattt/add-messages-send
Open

mattt wants to merge 16 commits into
mainfrom
mattt/add-messages-send

Conversation

@mattt

@mattt mattt commented Oct 26, 2026 •

Copy link
Copy Markdown
Owner

This PR adds messages_send to send text through Messages using Apple Events. It accepts a phone number or email address with an optional service (iMessage by default, SMS or RCS), or an existing chatId without a service override; iMCP must be able to read that conversation's participants and service from chat.db.

Each send needs confirmation in iMCP. The window shows the client name when available, recipient, service, and full text. Canceling or leaving it unanswered for 50 seconds sends nothing. Only one confirmation is shown at a time; a send requested while one is open fails without sending, and Send is disabled for half a second when the window appears. There's no "always allow" option. Success means Messages accepted the message. If exactly one new row in chat.db matches within 5 seconds, and no equivalent send overlapped, the result includes its @id (a best match, not a guarantee) and conversation for a delivery check with messages_fetch; otherwise, or for a phone number without a country code, the result has no @id.

Both app entitlements add com.apple.MobileSMS to the Apple Events exception, and the usage description now includes Messages. A prior Automation denial returns an error before confirmation; otherwise, macOS can ask for permission after Send. Messages scripts run on a background queue; #307 moves Music onto it.

Still needed: check the full iMCP confirmation and Automation flow, new recipients, iMessage and RCS sends, and the sent-message lookup and delivery fields against real sends. Client-name capture also needs a fix: handlers can capture the name before initialization supplies it. Attachments aren't supported by messages_send.

Part of #78.

@mattt
mattt marked this pull request as ready for review October 26, 2026 18:33
oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 17, 2026
Brings in messages_send from upstream PR 305 and puts it on this branch's
Allow writes setting and OutboundConfirming window:

- Messages writes start off, and each send is confirmed with no always-allow.
- The confirmation names the client from ToolCallContext, the exact recipient
  handles, the service, and the full text.
- The send script is called as an Apple event subroutine with typed
  parameters through NSAppleScript.Subroutine, which gains an enum code
  parameter and a beforeSending check.
- PR 305's own confirmation view, window controller, gate, and answer type
  are removed in favor of OutboundConfirmation.
oliverames pushed a commit to oliverames/iMCP that referenced this pull request Nov 17, 2026
Brings in messages_send from upstream PR 305 and puts it on this branch's
Allow writes setting and OutboundConfirming window:

- Messages writes start off, and each send is confirmed with no always-allow.
- The confirmation names the client from ToolCallContext, the exact recipient
  handles, the service, and the full text.
- The send script is called as an Apple event subroutine with typed
  parameters through NSAppleScript.Subroutine, which gains an enum code
  parameter and a beforeSending check.
- PR 305's own confirmation view, window controller, gate, and answer type
  are removed in favor of OutboundConfirmation.
@oliverames

Copy link
Copy Markdown
Contributor

@mattt In case it saves you a step when you pick this back up: #390 is the helper on this branch with the two changes you asked for there. The beforeSending hook is @Sendable without the nonisolated(unsafe) binding, and cancellation is checked again after the hook returns. The one difference is that it takes calling subroutine: Subroutine? and builds the Apple event itself, so SendRequest.handlerEvent and MessageService.handlerEvent here would become a Subroutine with the handler name and its arguments.

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.

2 participants