Skip to content

Reach iMCP from cloud apps: Tailscale Funnel and Cloudflare Tunnel with OAuth 2.1 - #376

Closed
oliverames wants to merge 19 commits into
mattt:mainfrom
oliverames:pr/remote-access
Closed

oliverames wants to merge 19 commits into
mattt:mainfrom
oliverames:pr/remote-access

Conversation

@oliverames

@oliverames oliverames commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #308. This branch includes #308's commits, because public access builds on its embedded Tailscale node and HTTP server. Only the last two commits are new here, so review git diff 0771351..HEAD (the merge of main aside). Once #308 merges, this diff is the whole change.

What and why

Cloud apps such as claude.ai, Claude Duet, Muse and Gemini can't join a tailnet, so #308 doesn't reach them. This adds two public routes to the same loopback HTTP server, and an OAuth 2.1 authorization server so a cloud app is approved once in a window on the Mac instead of with a pasted token.

What changed

  • OAuth 2.1 (OAuthAuthority, OAuthEndpoints, OAuthGrant, ClientMetadataFetcher): RFC 9728 and RFC 8414 metadata, RFC 7591 dynamic client registration, Client ID Metadata Documents, PKCE S256, refresh token rotation. A native window approves each new app. The approval is bound to the browser that started it (a 6-character code and an HttpOnly cookie), and the metadata fetch pins the resolved address to limit SSRF. Grants keep only a hash of the refresh token, in the Keychain.
  • Tailscale Funnel (FunnelAccess, RemoteAccess): one toggle for https://<node>.<tailnet>.ts.net/mcp, smaller request limits for public traffic, and guidance on the nodeAttrs entry when the funnel capability is missing.
  • Cloudflare Tunnel (CloudflareTunnel): sign in with cloudflared tunnel login, a cert.pem, or an API token. It finds the zone, creates or reuses a per-Mac named tunnel, sets the ingress to the loopback server, creates or updates the proxied DNS CNAME, and supervises cloudflared tunnel run. It needs cloudflared installed (brew install cloudflared).
  • Tunnel self-healing: the tunnel restarts with backoff when cloudflared exits, reconnects after wake and when the network returns, and retries after a discovery or provisioning failure.
  • Settings: the existing Remote Access pane gets the Funnel and Cloudflare controls, and the Clients pane lists connected cloud apps with Revoke. I kept the UI to what is needed to reach the feature.
  • README section, and tests (OAuthTests, RemoteAccessTests).

How to turn it on

In Settings, choose Remote Access, then either Public Access (Cloudflare Tunnel) or, after logging in to Tailscale, Public Access (Tailscale Funnel). Add the address that Settings shows as a custom connector in the app (in claude.ai: Settings, Connectors) and approve it in the window that opens on the Mac.

One thing to decide

Funnel needs enableFunnel and disableFunnel on TailscaleKit's node, which the mattt/libtailscale 0.2.0-imcp.2 release doesn't have. This branch pins oliverames/libtailscale at 0.2.0-imcp.2-funnel.1, which adds them. If you'd rather keep the pin on mattt/libtailscale, the Funnel API needs to land there first. Cloudflare Tunnel doesn't use it.

Testing

  • Debug build of the iMCP scheme succeeds. swift format lint --strict is clean.
  • imcp-serverTests: 271 tests, 1 skipped, 0 failures, run locally on macOS 26. OAuthTests.testFullFlowThroughTheEndpoints runs the whole OAuth flow against the local endpoints.
  • CI: see the checks on this PR.
  • Live, in a build from my fork's integration branch (not this branch alone): the Cloudflare Tunnel hostname served /mcp and the /.well-known/oauth-* metadata. claude.ai (Claude Web) completed OAuth consent through the tunnel on 2026-11-18 and called tools live: Weather, Music, and a read-only sweep of Reminders, Notes, Files, Home, Calendar, Contacts and Maps all answered. The restart-after-exit behavior was added after the tunnel was seen to drop.

Not verified

  • Funnel has not been exercised end to end, including long-lived or streaming responses.
  • OAuth consent from Claude Duet, Muse and Gemini has not been tried.
  • The NWConnection TLS path for the metadata fetch and the browser cookie binding are covered by unit tests only.
  • Wake and network-return reconnects were not re-tested on this branch.

Replaces #352, which carried the same change together with the Setup Assistant and Settings reorganization. Those are left out and will come separately.

Screenshots

Clients in Settings, with a cloud app connected through the tunnel and the connector address to copy.

Clients settings: AI apps, the connector address and a connected cloud app

This is from the Settings window of my integration build, which has a sidebar redesign and the AI app list that are not part of this PR. The connected cloud app (Claude, used seconds before the capture) is the live connection this PR makes possible.

mattt and others added 19 commits October 26, 2026 11:21
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
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.
@mattt

mattt commented Nov 20, 2026

Copy link
Copy Markdown
Owner

Following up from #364, the two things that stood out to me here: the public routes accept tailnet tokens that aren't bound to a device yet, and Cloudflare setup can replace a tunnel's existing ingress and CNAME.

@oliverames

Copy link
Copy Markdown
Contributor Author

Closing per #364. Thanks for catching the unbound tailnet token and Cloudflare ingress issues. I will fix those on my fork.

@oliverames oliverames closed this Nov 20, 2026
@oliverames
oliverames deleted the pr/remote-access branch November 20, 2026 21:34
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