Repository navigation
iMCP for iPhone and iPad: keep the link alive, activity history, approvals, outbox fix, and routes the Mac chooses - #381
Closed
oliverames wants to merge 27 commits into
Closed
oliverames wants to merge 27 commits into
oliverames wants to merge 27 commits into
Conversation
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.
… crash The Mac keeps a live link when the same device connects twice, and the phone shares one in-flight dial and bounds pull to refresh to 8 seconds. The Mac records each tool call in an activity history that syncs to the phone, which shows it under Activity. Syncs run under a background task assertion and the outbox moves out of the App Group container, which ended the app with 0xdead10cc when it suspended holding a SQLite lock.
Adds the transport modes, an encrypted WebSocket channel, candidate dialing with per-route and total time budgets, the Connection Mode screen on the phone, and route settings in the Mac's iPhone & iPad pane.
The Mac numbers its route list with a revision, sends it in the welcome and with config_apply when its settings change, and shows the revision each phone has applied. The phone follows the Mac's route order.
The Mac offers each connection request to the paired phone as well as showing its own dialog, and the first answer wins. Approving on the phone allows one connection and never trusts the client. The Mac withdraws the request when it answers, expires an unanswered one as a denial, and ignores answers from devices that aren't paired. The phone lists waiting requests and can answer from a notification after device authentication.
This was referenced Nov 18, 2026
This was referenced Nov 18, 2026
Closed
Closed
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack. Stacked on #281. Review only the commits after 25ffc7e, which is #281's head merged with current
main. It replaces #365, #366, #367, #368, #369, #370 and #372 (listed at the end). Nothing here needs #376.What it does and why
iMCP for iPhone and iPad (#281) can serve Health and Alarms, but the link is fragile, the Mac gives no sign of what agents asked for, and the phone can only reach the Mac on the local network. This adds, on top of #281:
0xdead10ccwhen it was suspended holding a SQLite lock in the App Group container.What changed
Five commits, in this order:
attachkeeps a live link when the same device connects again (a ping check decides), and cancellation is logged at debug, not error.readOnlyHint), outcome and duration for the last 500 calls and pushes unsent events with a newactivity_synccall. The phone acknowledges the highest sequence it stored. The store opens from disk when a phone connects, and activity syncs before the batch drain. The phone has an Activity screen with filters, search and Clear.iOS/Backend.swiftopens the outbox. A migration checkpoints and moves an old outbox with its-waland-shmfiles, so queued batches and HealthKit anchors survive. Syncs run under a background task assertion and an expired assertion cancels the sync so the transaction rolls back.MobileTransportMode, the pairing code and welcome carry route addresses, an encrypted WebSocket channel (X25519, HKDF, ChaChaPoly with counter nonces), candidate dialing with a 6 second budget per route, the Connection Mode screen and "Via" row on the phone, and Connection Route settings on the Mac. Tailscale VPN dials the Mac's own Tailscale interface address (or a typed host) on the port the TLS listener bound. It does not use the embedded tailnet node from Serve MCP over HTTP to your other devices on Tailscale #308. Cloudflare Tunnel uses a loopback WebSocket listener that is off unless you turn it on and enter the tunnel's public address.MobileConfiguration(revision that only goes up, ordered routes, features) is sent in the welcome and with aconfig_applycall when the Mac's settings change. The phone applies only newer revisions and follows the Mac's order. The Mac shows the revision each phone has applied and has drag to reorder and a toggle per route. Older phones that ignore it still use the addresses from pairing.I also ported the fix for the timing assertion in
MobileRetryTests(wait for the replaced link to close before checking it).What needs #376
Nothing in this PR. The Tailscale Funnel route exists in the phone and in the configuration, but nothing on the Mac supplies a Funnel address here, so the phone lists it as unavailable and Automatic skips it. The follow-up PR (stacked on this one and #376) lets the Mac advertise its Funnel and Cloudflare Tunnel addresses from remote access and accept the phone's WebSocket on those hosts.
Testing
imcp-serverTests, full suite, on this branch: 306 passed, 1 skipped, 0 failed. New tests are inMobileRetryTests,MobileActivityTests,MobileOutboxTests,MobileTransportTests,MobileConfigurationTestsandRemoteApprovalTests. The outbox tests fail without the fix: with the move stubbed out the container and migration tests fail, and withTask.checkCancellation()removed fromenqueuethe cancellation test fails.iMCPscheme builds for macOS and theiMCP iOSscheme builds for generic iOS, both Debug with signing off, as in CI.swift format lint --strict --recursive .is clean.Not verified
0xdead10cccrash. The evidence is one TestFlight crash report on build 26 and no reports since the same change shipped in build 27.MobileFeatures.approvalsis not set by the Mac yet and the phone does not read it.UserDefaults. If those are reset, the numbers restart low and a paired phone ignores them until it re-pairs.Replaces
#365, #366, #367, #368, #369, #370 and #372. #371 stays open and is replaced by the follow-up that builds on #376.
Screenshots
The Mac side of the phone connection: the paired device, the routes the phone tries in order, the connection mode, approvals and activity history.
This is from my integration build, whose Settings window is a separate redesign (#388), and its Cloudflare Tunnel route is the one #386 adds. The Cloudflare Tunnel and Tailscale public address rows are not part of this PR.