Repository navigation
iMCP for iPhone and iPad over Tailscale Funnel and Cloudflare Tunnel, served by public access - #386
Closed
oliverames wants to merge 48 commits into
Closed
oliverames wants to merge 48 commits into
oliverames wants to merge 48 commits into
Conversation
Clients on another device in the owner's tailnet can now use iMCP while the Mac keeps the data, permissions, and tool settings. iMCP listens on the Mac's tailnet address, accepts only untagged devices that belong to the Mac's Tailscale user, and requires a named access token on every request. Settings creates, edits, re-rolls, and deletes tokens, and a token can never use a service or tool that is off in iMCP.
Remote sessions pass a pre-approved ConnectionApprovalGate, because a valid access token takes the place of the approval dialog. The remote access test file moves to Tests/imcp-serverTests with the other tests.
Link TailscaleKit 0.2.0-imcp.1 from mattt/libtailscale into the app target, which embeds it like Sparkle. The framework is arm64-only and requires macOS 15.6, so the app target now builds only for arm64 with a deployment target of 15.6, and the app no longer runs on Intel Macs. The CLI, the helper, and the tests don't link the framework and keep their settings.
A sandboxed iMCP can't run the Tailscale command-line tool, and a listener on the Mac's shared tailnet address can be taken over by another local process. iMCP now runs an embedded Tailscale node with its own identity and address, and listens only on that address. The node keeps its state in the app's container and runs only while remote access is on. Settings shows the login link, the node's state, MagicDNS name, and tailnet address, and lets the owner log in with an auth key, rename the device, and log out. For each connection, the server asks the node who the peer is, and accepts only untagged devices of the node's own user. Access tokens, their permissions, and their binding to one device stay the same. The HTTP server reads and writes TailscaleKit connections, and runs their blocking calls on their own threads. The node is behind a small protocol, so the tests use a fake node to check authorization, Host and Origin validation, and the login states.
The README no longer asks for the Tailscale app on the Mac. It describes the login, auth keys, and logout, and says that WireGuard encrypts the plain HTTP traffic and that the node's address belongs only to iMCP. The download requirements now say macOS 15.6 on Apple silicon.
Link TailscaleKit 0.2.0-imcp.2 from mattt/libtailscale, which is universal (arm64 and x86_64) and requires macOS 15.1. The app target builds for the default architectures again, with a deployment target of macOS 15.1, as on main, and the README's download requirement is macOS 15.3 again. A later TailscaleKit release will drop the x86_64 slice.
TailscaleKit contains only a Swift interface that Swift 6.4 generated, so the app needs Xcode 27.1 or later. Of the GitHub-hosted images, only xcode-27 has Xcode 27.1; macos-26 stops at Xcode 26.6. CI now builds with Xcode 27.1 on xcode-27 and drops the Xcode 26.0 and 27.0 entries, which can't build the framework. The release workflow also moves from Xcode 26.0 on macos-26 to Xcode 27.1 on xcode-27.
…ailscalekit # Conflicts: # App/Controllers/ServerController.swift # iMCP.xcodeproj/project.pbxproj
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.
Cloud apps such as claude.ai can't join a tailnet, so iMCP can now serve its MCP endpoint at a public HTTPS address and authorize apps with OAuth 2.1. - OAuth 2.1 authority and endpoints (RFC 9728 and RFC 8414 metadata, RFC 7591 dynamic registration, Client ID Metadata Documents, PKCE S256, refresh token rotation), a native approval window bound to the starting browser, and a list of connected apps with revocation in Settings. - Tailscale Funnel through the embedded node, with stricter request limits for public traffic and guidance for the missing funnel ACL capability. - Cloudflare Tunnel: sign in, find the zone, create or reuse a named tunnel, set the ingress and DNS record, and supervise cloudflared. - The tunnel restarts with backoff when cloudflared exits, reconnects after wake and when the network returns, and retries after a discovery or provisioning failure.
… 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.
…e access With public access on, the Mac puts its Funnel and Cloudflare Tunnel WebSocket addresses in the pairing code and the route configuration, and takes them out when remote access stops. Upgraded WebSockets at /mobile on the public hosts go to the phone link, which closes a connection that doesn't send its hello within 15 seconds. A Cloudflare address typed in Settings still takes priority. Documents the link and adds tests on the public hosts.
Contributor
Author
|
Closing per #364. |
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. Needs #381 (iMCP for iPhone and iPad, which sits on #281) and #376 (public access, which sits on #308). This branch is #376 with #381 merged in, so until those merge the diff shows them too. Review only the two commits after #376's head 579308f: 3a7d790 is the merge of #381 into #376 (the conflicts were in
ServerController.swift,SettingsView.swiftandproject.pbxproj), and bb7ce96 is the change itself. It cannot merge before #381 and #376.What it does and why
#381 lets the iPhone and iPad choose Tailscale Funnel or Cloudflare Tunnel, and lets the Mac decide the phone's routes, but nothing on the Mac supplies a Funnel address or serves the phone on a public host, so those routes report "isn't available". #376 provides the public hosts. This connects the two.
What changed
wss://…/mobileURLs for Funnel and Cloudflare Tunnel toMobileService.updateRemoteEndpoints, so pairing codes and the route configuration carry them. Remote access stopping removes them.GET /mobileon an active public host with upgrade headers and noOriginheader gets a 101 and goes toMobileService.acceptWebSocket, with the route taken from theHostheader. The phone has a 15 second hello timeout./mobile, every other request for it returns 404, and no MCP session is created for it.acceptWebSocketdoes the device-key handshake, so an unpaired phone is refused. The existing public connection cap and request deadline still apply.updateRemoteEndpointsgained an optionalcloudflareURL. A Cloudflare address typed in Settings still wins.Testing
imcp-serverTests, full suite, on this branch: 411 passed, 1 skipped, 0 failed. New tests are inRemoteAccessTests: publishing and clearing the addresses, host-to-route mapping, and refusals for a wrong host, a loopback host, anOriginheader, no upgrade, a bearer token and a POST, with/mcpand OAuth still answering. Over a real loopback listener with a realMobileService, an unpaired device is refused, a wrong key is refused, a paired device gets an accepted welcome, and a silent phone is dropped.iMCPscheme builds for macOS and theiMCP iOSscheme builds for generic iOS, both Debug with signing off.swift format lint --strict --recursive .is clean.Not verified
HomeHelperPairingTeststhen reported "Connection cancelled". They passed when run alone, and a second full run passed with 411. I don't know what made the first run hang. Those tests are not in code this PR changes.Decisions to check
Replaces
#371.
Screenshots
The routes list on the Mac, with the Cloudflare Tunnel route this PR makes available to the phone.
This is from my integration build, whose Settings window is a separate redesign (#388). The phone connected through the Cloudflare Tunnel route in that build.