Skip to content

Approve client connections from iMCP for iPhone and iPad - #367

Closed
oliverames wants to merge 27 commits into
mattt:mainfrom
oliverames:feat/ios-approve-on-iphone
Closed

oliverames wants to merge 27 commits into
mattt:mainfrom
oliverames:feat/ios-approve-on-iphone

Conversation

@oliverames

@oliverames oliverames commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Stack. Stacked on #366 (which sits on #365 and #281). Review only the two commits after #366. Merge order is in #364.

What it does and why

When iMCP waits for you to approve a new client connection, you have to be at the Mac. This offers the same request to your paired iPhone or iPad so you can answer from the phone. The Mac still shows its own dialog, and the first answer wins.

What changed

  • If you answer on the Mac, it withdraws the request from the phone. If the phone answers first, the Mac closes its dialog.
  • A phone approval allows that one connection and never trusts the client permanently. Requests nobody answers expire as denials. Answers from a device that is no longer paired are rejected.
  • Phone: an approval_sync tool, a "Waiting for You" section with Approve and Deny, and a notification when the app is in the background. Approving happens in the in-app sheet.
  • Mac: an "Approve on iPhone" setting in the iPhone & iPad pane (on by default).
  • The plug-in point is the existing connection approval queue in ServerController (presentApproval, finishApproval, expiry and cancel), so it works without Add an Allow writes setting for each service #342 or Send messages behind Allow writes and a shared confirmation #344.

Testing

  • imcp-serverTests, full suite: 262 tests, 1 skipped, 0 failures. RemoteApprovalTests has 13 tests, 7 new here: both orders of the Mac and phone race plus a 200-round concurrent race, replayed and unknown IDs, unpaired devices, revocation by unpairing, expiry denying exactly once, the wire format round trip, the phone inbox including answers from a notification, and syncApprovals against a fake connected phone.
  • macOS and iOS targets build. swift format lint --strict is clean on the changed files.
  • CI: the macOS 26 (Xcode 26.0) and macOS 27 (Xcode 27.0) builds both pass on this branch. Earlier runs of some of these branches failed on a stale Clang module cache on the macOS 26 runner and passed when rerun; no code changed for that.

Not verified

This is out of draft with these gaps stated, not because they are closed:

  • I have not approved or denied a connection from a real iPhone or iPad with this code.
  • Notification delivery, the Approve and Deny buttons in the sheet, and the 25 second background grace period have not run on a device.
  • The Mac dialog closing when the phone answers is an AppKit path with no test seam and has not been exercised.
  • The phone side has no unit tests (no iOS test target).

Follow-ups, not in this PR

Offering outbound sends (messages_send) to the phone needs the confirmation window from #342. The protocol already has the .send case and the change is about 20 lines against MacOutboundConfirmer, so the wire format won't change when it lands. A tool-call approval from #354 would be one more offer in its confirmation path.

mattt and others added 27 commits November 6, 2026 10:20
Define the Health, Finance, and Alarms tools once in Shared/Companion,
store what the iPhone sends in an encrypted SQLite cache,
and answer read-only calls from that cache with synced_at and stale.
Generalize HomeInput into ToolInput so both services validate arguments.
The iPhone app dials the Mac over TLS with pre-shared keys,
pairs with a one-time code from a QR code in Settings > Companion,
and serves the companion tools as an MCP server on that connection.
The Mac calls tools live when the phone is connected,
retries a lost read or an alarm change that carries its ID,
and pulls queued changes from the phone's outbox into its cache.
Scripts/install-companion.sh builds and installs the app with your team.
Answer the Health tools live from HealthKit,
let the user allow each group of types from the app,
and queue anchored changes for the Mac: daily statistics for quantity types
and full records for sleep, workouts, and health records.
When HealthKit is locked, the Mac answers reads from its cache.
Create one-time, weekly, and countdown alarms with the ID the Mac sends,
so a retried call returns the existing alarm instead of a second one.
A widget extension shows a running timer as a Live Activity with a stop button,
the app lists the alarms that AI apps created and cancels them,
and the phone sends its alarm list to the Mac whenever AlarmKit reports a change.
Answer the Finance tools live and queue account, balance, and transaction
changes for the Mac with FinanceKit history tokens.
A background delivery extension queues changes while the app isn't running.
The code stays inactive until a build carries the FinanceKit entitlement,
which Scripts/install-companion.sh --finance requests;
without it, the Finance tools say why they're unavailable.
Add Alarms, Finance, and Health to the README and its hero image,
describe how to install, pair, and use the companion,
add Scripts/check-companion.py for read-only checks through imcp-server,
and build the companion unsigned in CI.
When the iPhone drops a connection, disconnect the Mac's MCP client,
so pending calls fail over to the cache and syncing resumes on the next connection.
Keep lines that arrive before MCP reads them, end a closed channel's stream
with an error, and enforce read and open time limits.
Reject outbox writes from a sync that a cache reset overtook, run each
service's sync one at a time, and give the FinanceKit reason in cached answers.
The Mac used to send the device key inside the pairing session,
so anyone with the QR secret who recorded that session could recover it.
Now each side sends a one-time X25519 public key, both derive the device key
from the shared secret salted with the pairing key, and each side's proof
covers the public keys so neither can be swapped.
The iOS app is now iMCP on the device and builds for iPhone and iPad.
Targets, folders, and shared code use iOS and Mobile names,
the Mac's Settings pane is iPhone & iPad,
and the Bonjour type, pairing link, and status tool drop the companion name.
The name no longer collides with the separate Companion debugging app
that the README describes.
The macOS 26 runner's Xcode 26.0 has no iOS platform,
so the iOS app's build couldn't find a destination.
Download the platform when it's missing and allow time for the download.
AlarmKit shows its own stop control on the alarm alert,
so the app doesn't need an App Intent for it.
The timer Live Activity now shows the countdown without a stop button.
The phone can dial the Mac from two places at once (the foreground loop and a
background flush). Replacing the live link cancelled the sync in progress and
started the same race again. attach() now keeps the current link for the same
device while it answers a status call within a short time, and replaces it
when it doesn't. A cancelled sync is logged at debug instead of as an error.
The foreground loop, a background flush, and pull to refresh each dialed the
Mac on their own, and the Mac treats two connections from one device as a
conflict. They now join a single dial, and the channel is served by one task
that the loop waits on. Pull to refresh reuses the open connection, retries the
dial now instead of waiting out the backoff, and returns within eight seconds
whatever the Mac or HealthKit is doing. The retry delay tops out at ten seconds,
and the status shows when the phone last connected.
…e phone

Every tool call a client makes (succeeded, failed, or denied) is recorded with
the client, service, tool, whether it writes, and how long it took. The Mac
keeps the last 500 in Application Support, tracks what each paired device has
acknowledged, and pushes the rest over the existing link with a new
activity_sync call. The store opens from disk, so events recorded before a
relaunch reach the phone, and activity syncs before the pull so a short
connection still delivers it.
The phone accepts activity_sync, keeps the events in its own Application Support
folder, and lists them under Activity with a filter for reads, writes, and
denied or failed calls, search by client, service, or tool, and Clear. Unpairing
removes the history, because the next Mac numbers its events again.
The Mac asks a connected iPhone or iPad to approve a connection request.
The first answer from either device wins; the Mac withdraws the request
from the phone when it answers first and closes its dialog when the phone
answers first. An answer from the phone allows one connection and never
trusts the client. Requests expire as denials, and answers count only
from a paired device.
Adds the approval_sync tool, a Waiting for You section with Approve and
Deny, and a notification when a request arrives while the app is in the
background. Approving from a notification needs device authentication.
The app stays connected for a short grace period after it is backgrounded,
so the Mac can still reach it.
@oliverames

Copy link
Copy Markdown
Contributor Author

Replaced by #381, the same change cut as one PR so it can merge on its own.

@oliverames oliverames closed this Nov 18, 2026
@oliverames
oliverames deleted the feat/ios-approve-on-iphone branch November 18, 2026 21:44
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