Skip to content

feat: Remote Access via Tailscale Funnel & Cloudflare Tunnel with OAuth 2.1 - #352

Closed
oliverames wants to merge 30 commits into
mattt:mainfrom
oliverames:fork/funnel-spike
Closed

oliverames wants to merge 30 commits into
mattt:mainfrom
oliverames:fork/funnel-spike

Conversation

@oliverames

@oliverames oliverames commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

An early spike, opened for discussion. It depends on #308 and includes its commits. Once #308 lands I plan to split what is left into Funnel, OAuth 2.1 (#330) and Cloudflare Tunnel PRs, tracked in #364. It is out of draft so it can be read and commented on, not because it is ready to merge.

What it does

Lets remote MCP clients reach iMCP from outside the local Mac: claude.ai, Claude Duet, Muse, and other devices on the user's tailnet. It builds on #308's embedded Tailscale node and adds two public routes, Tailscale Funnel and Cloudflare Tunnel, plus an OAuth 2.1 authorization server so a cloud client can be approved on the Mac instead of pasting a token.

What changed

  1. Tailscale Funnel (FunnelAccess.swift, RemoteAccess.swift): one toggle for public access at https://<node>.<tailnet>.ts.net/mcp, with guidance on the ACL nodeAttrs entry when the Funnel capability is missing. Needs the TailscaleKit build from oliverames/libtailscale (release 0.2.0-imcp.2-funnel.1), pinned in this branch.
  2. Cloudflare Tunnel (CloudflareTunnel.swift): sign in with cloudflared tunnel login, an existing cert.pem, or an API token in the Keychain. It finds the zone, creates or reuses a per-Mac named tunnel, sets the ingress to the loopback HTTP server, creates or updates the proxied DNS CNAME, and supervises cloudflared tunnel run, restarting it with backoff and after wake.
  3. OAuth 2.1 server (OAuthAuthority.swift, OAuthEndpoints.swift, OAuthGrant.swift): RFC 9728 and RFC 8414 metadata, RFC 7591 dynamic client registration, Client ID Metadata Documents, PKCE S256, refresh token rotation. A native Mac window approves each new client, and connected apps can be revoked in Settings. 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.
  4. Setup Assistant and Settings reorganization (OnboardingGate.swift, OnboardingWizard.swift, SettingsView.swift, RemoteAccessSettingsView.swift): a guided setup for services, remote tunnels and connecting AI apps, and a reorganized Clients pane with technical overrides under "Developer & Advanced". This part is early and is expected to move to its own PR.

Testing

  • OAuthTests and RemoteAccessTests cover the OAuth endpoints, the approval binding, the metadata fetch checks and the remote access paths. OAuthTests.testFullFlowThroughTheEndpoints runs the whole flow against the local endpoints.
  • CI: the macOS 27 job (Xcode 27.1) passes. It runs lint, a Debug build and the imcp-serverTests suite.
  • Live on my Mac, in a build from my fork's integration branch (not this branch alone): through the Cloudflare Tunnel hostname, claude.ai completed the OAuth consent for the iMCP connector, the approved app showed under Connected cloud apps in Settings, and tool calls through that connector worked. I checked the Weather and Music tools this way. The tunnel hostname also served /mcp and the /.well-known/oauth-* metadata (200 and 401 as expected). The restart-after-exit behavior was added after the tunnel was seen to drop.

Not verified

  • OAuth consent from Claude Duet, Muse and Gemini has not been tried.
  • Tool calls through the claude.ai connector were checked for Weather and Music only, not every service.
  • Tailscale Funnel has not been exercised end to end, including long-lived or streaming responses through a Funnel public address.
  • The NWConnection TLS path for the metadata fetch and the browser cookie binding were tested in unit tests only.
  • The Setup Assistant and the reorganized Settings have not been reviewed here against macOS design conventions.
  • The Funnel path needs a Funnel grant in the user's tailnet policy and the custom libtailscale build; neither is something upstream CI exercises.

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
Off by default. Funnel forwards public HTTPS traffic to a listener on
127.0.0.1, so those requests are treated as internet traffic: a bearer
token is required on every request (no whois or loopback trust), only the
node's public ts.net name is accepted as Host and Origin, requests and
connections have smaller limits, and repeated bad tokens get 429.
Tokens bound to a tailnet device are rejected on this path. Funnel's
saved serve config is cleared whenever the node stops or starts without
public access. The tailnet-only path is unchanged.

Needs the libtailscale funnel branch (ACME enabled, enableFunnel and
disableFunnel).
Public access now works without a copied token. iMCP is its own OAuth
authorization server (MCP authorization spec 2025-11-25): protected
resource metadata (RFC 9728), authorization server metadata (RFC 8414),
dynamic client registration (RFC 7591), Client ID Metadata Documents,
PKCE S256 only, and resource indicators (RFC 8707). The owner approves
each app in a native window, and Settings lists connected apps with a
Revoke button. Access tokens last an hour and live in memory. Refresh
tokens rotate, are stored hashed in the Keychain, and a reused one ends
the grant.

Also adds a 15 second total deadline for requests on Funnel connections,
and clears Funnel's saved configuration when the node starts and after a
stop that raced a pending enable.
Oliver Ames added 6 commits November 16, 2026 18:13
…h address

Authorization requests get a 6-character confirmation code shown on the waiting page and in the approval request, plus a 256-bit poll secret in an HttpOnly, Secure, SameSite=Lax cookie. Only a poll with the cookie can get the code redirect. The approval shows the full client ID and redirect URI.

The Client ID metadata fetch resolves once, checks every address, and connects to the checked address with Network.framework, using the hostname for SNI and certificate verification. It also blocks 64:ff9b::/96, 64:ff9b:1::/48, 2002::/16, fec0::/10 and ::/96.
URL.path and URL.query decode %0D%0A into a line break, so a client ID
URL could inject headers into the pinned HTTP/1.0 request. Use the
encoded forms and refuse any target byte outside printable ASCII.
@oliverames oliverames changed the title Add public access through Tailscale Funnel with OAuth 2.1 feat: Remote Access via Tailscale Funnel & Cloudflare Tunnel with OAuth 2.1 Nov 17, 2026
@oliverames

Copy link
Copy Markdown
Contributor Author

Replaced by #376, 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 fork/funnel-spike 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