Control a real USB-connected iPhone from Linux (no Mac, no paid developer account) and expose it to AI agents as MCP tools
Rust ai-agentautomationclaudeclaude-codedockeriosiphonelinuxmcpmcp-servermodel-context-protocolrustwebdriveragent
README:改为 iphone-control-toolkit / podux 的样式
Derrors0bb879eae8e7
diff --git a/README.md b/README.mdindex d2def61..5bd0df1 100644--- a/README.md+++ b/README.md@@ -1,181 +1,168 @@-# iphone-control+<a name="readme-top"></a>-**English** | [简体中文](README.zh-CN.md)+<div align="right">+ <b>English</b> | <a href="README.zh-CN.md">简体中文</a>+</div>-[](https://github.com/Derrors/iphone-control/actions/workflows/ci.yml)-[](LICENSE)+<div align="center">+ <a href="https://github.com/Derrors/iphone-control">+ <img src="website/public/logo.svg" alt="Logo" width="120">+ </a>-**Documentation: [derrors.github.io/iphone-control](https://derrors.github.io/iphone-control/en/)**+ <h3 align="center">iphone-control</h3>-Control a real, USB-connected iPhone from Linux — no Mac, no paid Apple developer account — and hand it to AI agents as [MCP](https://modelcontextprotocol.io) tools. One Rust binary plus the system `usbmuxd`.+ <p align="center">+ Let an AI agent operate a real iPhone plugged into a Linux machine — one Rust binary, no Mac, no paid developer account, no jailbreak.+ </p>-> **Status: early (0.x).** Everything below works end to end on one device: iPhone 15 Pro Max, iOS 27.0.1. Other models and iOS 17+ should work but are untested — reports are welcome.->-> The CLI, `doctor` output and MCP tool results are currently in **Simplified Chinese**. Agents handle this fine; a human reading the logs may need a translator.--## What it does--- **Agent tools** — screenshots (with zoom-in regions), on-screen element lists, tap by coordinates or by text, swipe, long press, typing (including Chinese), hardware buttons, launch/terminate apps, open URLs, wait for text to appear, and batches of steps. Any action can also return the resulting screen, saving the agent a round trip. See [docs/tools.md](docs/tools.md).-- **Keeps itself running** — pairs with the phone, mounts the Developer Disk Image, signs WebDriverAgent with your free Apple ID and re-signs it before the 7-day profile expires, restarts WDA when it dies, and recovers after the phone is unplugged or rebooted.-- **Fallback path** — when WDA is down, taps, swipes, key presses and screenshots still work through CoreDevice HID.-- **Tells you when it needs you** — Bark or Telegram notifications for a failed re-sign, an expired Apple ID session, a reboot that needs the passcode, or the phone going offline.-- **Optional auto-unlock** — off by default; read [SECURITY.md](SECURITY.md) before turning it on.-- **No open ports** — WDA is reached through usbmuxd; nothing listens on the network.--```-AI agent ──stdio──▶ iphone-control mcp ──unix socket──▶ iphone-control daemon ──usbmuxd/USB──▶ iPhone (WebDriverAgent)-```--One long-running daemon owns the device (tunnel, HID session, WDA session); each agent session gets a thin MCP client. Details: [docs/architecture.md](docs/architecture.md) (Chinese).--## Requirements+ <p align="center">+ <a href="https://github.com/Derrors/iphone-control/releases/latest"><img src="https://img.shields.io/github/v/release/Derrors/iphone-control?style=flat-square" alt="Release"></a>+ <a href="https://github.com/Derrors/iphone-control/pkgs/container/iphone-control"><img src="https://img.shields.io/badge/ghcr.io-derrors%2Fiphone--control-2496ED?style=flat-square&logo=docker&logoColor=white" alt="Docker"></a>+ <img src="https://img.shields.io/badge/iOS-17%2B-black?style=flat-square&logo=apple" alt="iOS">+ <img src="https://img.shields.io/badge/MCP-15%20tools-8A2BE2?style=flat-square" alt="MCP">+ <a href="Cargo.toml"><img src="https://img.shields.io/badge/Rust-1.88%2B-CE422B?style=flat-square&logo=rust&logoColor=white" alt="Rust"></a>+ <a href="https://github.com/Derrors/iphone-control/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/Derrors/iphone-control/ci.yml?branch=main&style=flat-square&label=CI" alt="CI"></a>+ <a href="LICENSE"><img src="https://img.shields.io/github/license/Derrors/iphone-control?style=flat-square" alt="License"></a>+ </p>-- A Linux host (x86_64 or arm64) with a USB port.-- Docker with Compose v2 — or, without Docker, Rust 1.88+, a C compiler and `usbmuxd` ([install from source](#install-from-source-without-docker)).-- An iPhone on iOS 17 or later with a data cable. Setup walks you through Developer Mode.-- A free Apple ID. Using a dedicated one is recommended (see [Security](#security-and-privacy)).-- Internet access to Apple, to the anisette server, and to GitHub (the Developer Disk Image and WebDriverAgent are downloaded on first use).+ <p align="center">+ <a href="#quick-start"><strong>🚀 Quick Start</strong></a>+ · + <a href="https://derrors.github.io/iphone-control/en/"><strong>📖 Docs</strong></a>+ · + <a href="https://github.com/Derrors/iphone-control/releases">📦 Releases</a>+ · + <a href="https://github.com/Derrors/iphone-control/issues">🐛 Issues</a>+ </p>+</div>-## Quick start (Docker)+> [!NOTE]+> Early release (0.x), tested on an **iPhone 15 Pro Max (iOS 27.0.1)**. Other models and iOS 17+ should work but are untested — reports are welcome. The CLI, `doctor` output and MCP tool results are currently in Simplified Chinese; agents handle this fine.-```bash-git clone https://github.com/Derrors/iphone-control && cd iphone-control-cp .env.example .env # optional: proxy, notifications, auto-unlock settings-docker compose up -d --build # the first build compiles Rust and takes a few minutes-docker exec -it iphone-control iphone-control setup-docker exec -it iphone-control iphone-control mcp-config # prints the command to register the MCP server-```--Once a release is published you can skip the build: set `IMAGE=ghcr.io/derrors/iphone-control:latest` in `.env`, then run `docker compose pull && docker compose up -d --no-build`.--`setup` can be re-run at any time. It walks through:+## Overview-1. **Connect** the phone and unlock it.-2. **Pair** — tap *Trust* on the phone and enter the passcode.-3. **Developer Mode** — *Settings → Privacy & Security → Developer Mode → On*, restart, then confirm after unlocking.-4. **Apple ID login** — the password and two-factor code are typed into this terminal only.-5. **Sign and install WebDriverAgent** — keep the phone unlocked.-6. **Start WebDriverAgent** — the first time, trust your Apple ID under *Settings → General → VPN & Device Management*. If the phone asks you to *enter the iPhone passcode for "XCTest"* (Enable UI Automation), enter it.+AI agents can drive browsers and desktops, but a real iPhone is harder: Apple's automation tools need a Mac and Xcode, and the open-source alternatives come as separate pieces that each need their own setup, signing and babysitting.-The container is not `privileged`: it only gets USB character devices (`device_cgroup_rules: "c 189:* rmw"`) plus a bind mount of `/dev/bus/usb`. Don't run two copies (or another usbmuxd-based tool) against the same phone.+iphone-control does it all in **one Rust binary** on Linux, built on [idevice](https://github.com/jkcoxson/idevice), [Impactor](https://github.com/claration/impactor) and [WebDriverAgent](https://github.com/appium/WebDriverAgent). A long-running daemon owns the phone — tunnel, HID session, WebDriverAgent session — and exposes it to Claude Code or any MCP client. It succeeds [iphone-control-toolkit](https://github.com/Derrors/iphone-control-toolkit) and keeps its MCP tools compatible.-## Connect an MCP client--Claude Code (this is what `mcp-config` prints for the container):--```bash-claude mcp add iphone -s user -- docker exec -i iphone-control iphone-control mcp```--Other clients (Claude Desktop, Cursor, …) take the same command in their JSON config:--```json-{- "mcpServers": {- "iphone": { "command": "docker", "args": ["exec", "-i", "iphone-control", "iphone-control", "mcp"] }- }-}+Claude Code / any MCP client+ │ MCP over stdio+ ▼+┌──────── iphone-control daemon (Docker or systemd) ────────┐+│ WebDriverAgent (primary) │+│ CoreDevice HID (fallback) │+│ supervisor: usbmuxd · reconnect · re-sign · notify │+└─────────────────────────────┬──────────────────────────────┘+ │ USB (no network port opened)+ iPhone```-For a source install, use `iphone-control --socket <path> mcp` instead; `iphone-control mcp-config` prints the exact command.+## Features-## Install from source (without Docker)+- **See and touch the screen**: screenshots with region zoom, tap, swipe, long-press, text input (including Chinese), hardware buttons+- **Work with UI elements**: read the element tree, tap by text (on a part not covered by floating bars or the keyboard), launch and close apps, open URLs, wait for text to appear+- **Fewer round trips**: any action can return the resulting screen once it has settled, flagging pages still loading and blocking alerts; `iphone_batch` runs up to 20 steps in one call+- **Automatic fallback**: when WebDriverAgent is down, screenshots, taps, swipes and keys switch to Apple's CoreDevice HID service+- **Runs unattended**: recovers from replugging, phone reboots and WebDriverAgent crashes; re-signs WebDriverAgent with a free Apple ID before the 7-day profile expires+- **Alerts**: Telegram or Bark notifications when re-signing fails, the Apple ID session expires, the phone goes offline, or a passcode is needed after a reboot+- **Optional auto-unlock**: every passcode digit is verified, and a wrong passcode disables auto-unlock after one attempt+- **Diagnostics**: `doctor` checks every layer from USB to WebDriverAgent and tells you how to fix each failure-Debian/Ubuntu example:--```bash-sudo apt install build-essential git usbmuxd # udev starts usbmuxd when the phone is plugged in-git clone https://github.com/Derrors/iphone-control && cd iphone-control-cargo install --path apps/iphone-control --locked # installs ~/.cargo/bin/iphone-control-iphone-control daemon # foreground; see below for a systemd user service-iphone-control setup # in a second terminal-iphone-control mcp-config-```+## Quick Start-To keep it running, use the systemd user service in [deploy/iphone-control.service](deploy/iphone-control.service):+You need a Linux host (x86_64 or arm64) with Docker (Compose v2), an iPhone on iOS 17+ connected by a **data** USB cable, and a free Apple ID (use a dedicated one, not your main account).```bash-mkdir -p ~/.config/systemd/user ~/.config/iphone-control-cp deploy/iphone-control.service ~/.config/systemd/user/-cp .env.example ~/.config/iphone-control/env # CONTAINER_NAME, IMAGE and DATA_DIR are compose-only-systemctl --user daemon-reload && systemctl --user enable --now iphone-control-loginctl enable-linger "$USER" # start at boot without logging in+git clone https://github.com/Derrors/iphone-control.git+cd iphone-control+cp .env.example .env # optional: proxy, notifications+docker compose up -d --build # the first build compiles Rust, a few minutes+docker exec -it iphone-control iphone-control setup # guided setup; safe to re-run+claude mcp add iphone -s user -- docker exec -i iphone-control iphone-control mcp```-| | Container | Source install (regular user) |-|---|---|---|-| Data directory | `./data` (`/var/lib/iphone-control` inside) | `~/.local/share/iphone-control` |-| Control socket | `/run/iphone-control/ctl.sock` inside the container | `$XDG_RUNTIME_DIR/iphone-control/ctl.sock` |-| usbmuxd | started and supervised by the daemon (no udev in the container) | the system service; the daemon does not start it |-| Pairing records | `lockdown/` in the data directory | the system's `/var/lib/lockdown` |-| Unsigned WDA | shipped in the image | downloaded (sha256-checked) before the first signing |-| Configuration | `.env` | environment variables, e.g. the systemd `EnvironmentFile` |--Run the daemon, the CLI and the MCP server as the same user; for another user, point them at it with `--socket` and `--data-dir` (or `ICTL_SOCKET`, `ICTL_DATA_DIR`). Run as root, the defaults match the container and the daemon starts its own usbmuxd — set `ICTL_MANAGE_USBMUXD=0` if the host already runs the usbmuxd service. With a host `usbmuxd` installed, `sudo systemctl mask usbmuxd` before going back to the container, or the two will fight over the phone.--## Commands+`setup` walks you through pairing, Developer Mode, signing in to your Apple ID, and signing and installing WebDriverAgent. On the phone you tap *Trust*, turn on Developer Mode, and trust your Apple ID under *Settings → General → VPN & Device Management* — see the [step-by-step guide](https://derrors.github.io/iphone-control/en/guide/getting-started).-| Command | Purpose |-|---|---|-| `daemon` | The long-running daemon (container entry point) |-| `mcp` | MCP stdio server; talks to the daemon over the control socket |-| `mcp-config` | Print the command that registers the MCP server with Claude Code |-| `status` / `doctor` | State snapshot and recent log / layer-by-layer diagnosis with fixes |-| `setup` | First-run wizard (re-runnable) |-| `login` | Log in to an Apple ID (no echo; two-factor and SMS supported) |-| `sign` / `resign [--force]` | Sign and install WDA now / re-sign only if the profile is close to expiring |-| `passcode set\|clear`, `unlock-reset` | Auto-unlock (off by default) |-| `wda-bridge --port 8100` | Expose WDA on 127.0.0.1 for other tools — unauthenticated, stop it when done |-| `notify-test` | Send one test notification per event type |+Open a new Claude Code session and ask, for example:-## Configuration+> Open the Clock app, switch to the stopwatch, and show me a screenshot.-Everything is configured through environment variables; all of them are optional. See [.env.example](.env.example) for the full list. The common ones:--| Variable | Meaning |-|---|---|-| `HTTP_PROXY`, `HTTPS_PROXY` | Proxy for Apple, anisette, Developer Disk Image and notification traffic |-| `IPHONE_UDID` | Which phone to use when several are connected |-| `BARK_KEY`, `BARK_SERVER`, `TG_BOT_TOKEN`, `TG_CHAT_ID` | Notifications |-| `RESIGN_MIN_DAYS`, `RESIGN_CHECK_HOURS` | When to re-sign WebDriverAgent |-| `ICTL_ANISETTE_URL` | Your own anisette server instead of the default third-party one |-| `ICTL_DDI_URL`, `ICTL_DDI_DIR` | Where the Developer Disk Image comes from |--## Security and privacy--Read [SECURITY.md](SECURITY.md) before deploying. In short:--- The data directory holds your Apple ID session, the development signing key, pairing records and — only if you enable auto-unlock — the phone passcode in plain text. Back it up, and never commit or share it.-- The container runs as root, because it needs the USB device nodes and must be able to restart `usbmuxd` after the phone is unplugged.-- Apple ID logins use an anisette server. The default is a public third-party server; set `ICTL_ANISETTE_URL` to use your own.-- Anyone who can reach the control socket, or a running `wda-bridge`, can control the phone.+> [!TIP]+> Other MCP clients: the server speaks stdio through `docker exec` and opens no network port.+>+> ```json+> { "mcpServers": { "iphone": { "command": "docker", "args": ["exec", "-i", "iphone-control", "iphone-control", "mcp"] } } }+> ```++Once a release is out you can skip the build: set `IMAGE=ghcr.io/derrors/iphone-control:latest` in `.env` and run `docker compose pull && docker compose up -d --no-build`. Without Docker, use a [prebuilt binary or build from source](https://derrors.github.io/iphone-control/en/deploy/source) and run it as a systemd user service.++## MCP Tools++| Tool | Description |+| --- | --- |+| `iphone_status` | Connection, lock state, foreground app, screen size |+| `iphone_screenshot` | Screenshot scaled to points; pass `x/y/width/height` to zoom into a region |+| `iphone_list_elements` | Elements with text and their center coordinates; filter by text or type |+| `iphone_tap` / `iphone_tap_element` | Tap by coordinates or by element text |+| `iphone_swipe` / `iphone_long_press` | Swipe (returns once the list stops), long-press |+| `iphone_type_text` | Type into the focused field; reads it back and fixes dropped characters |+| `iphone_press_button` | `home`, `volume_up`, `volume_down`, `lock` |+| `iphone_list_apps` / `iphone_launch_app` / `iphone_terminate_app` | Manage apps by name or bundle ID |+| `iphone_open_url` | Open a URL or URL scheme |+| `iphone_wait_for` | Wait until some text appears instead of polling with screenshots |+| `iphone_batch` | Run up to 20 steps in one call, stopping at the first error |++Action tools accept `then: "elements" | "screenshot"` to return the screen after the action. Screenshot pixels are tap coordinates, so the agent can tap what it sees. Games, maps and video players draw their own UI and have no element tree — use screenshots and coordinates there. Full parameters: [docs/tools.md](docs/tools.md).++## Everyday Commands++Run them as `docker exec -it iphone-control iphone-control <command>`, or directly for a source install.++| Command | What it does |+| --- | --- |+| `status` | Daemon state, time left on the signing profile, recent log |+| `doctor` | Layer-by-layer health check with a fix for each failure |+| `setup` | Guided setup; re-run any time |+| `login` | Sign in to the Apple ID again when the session expires |+| `resign [--force]` | Re-sign WebDriverAgent if it expires soon (or now) |+| `passcode set\|clear` | Turn auto-unlock on or off |+| `notify-test [event]` | Send test notifications |+| `mcp-config` | Print the command that registers the MCP server |++Upgrade with `git pull && docker compose up -d --build` (or `docker compose pull` for the prebuilt image). Settings live in `.env` — see [configuration](https://derrors.github.io/iphone-control/en/guide/configuration). All state lives in `data/`: pairing records, the Apple ID session and signing key, and the passcode if auto-unlock is on. **Back it up; never commit or share it.**-## Disclaimer+## Documentation-This project is not affiliated with, endorsed by, or sponsored by Apple Inc. iPhone, iOS and Xcode are trademarks of Apple Inc.+| | |+| --- | --- |+| Guide | [What is it](https://derrors.github.io/iphone-control/en/guide/what-is-iphone-control) · [Getting started](https://derrors.github.io/iphone-control/en/guide/getting-started) · [AI clients](https://derrors.github.io/iphone-control/en/guide/mcp-clients) · [Tools](https://derrors.github.io/iphone-control/en/guide/tools) |+| Usage | [Configuration](https://derrors.github.io/iphone-control/en/guide/configuration) · [Notifications](https://derrors.github.io/iphone-control/en/guide/notifications) · [Auto-unlock](https://derrors.github.io/iphone-control/en/guide/auto-unlock) |+| Deployment | [Docker](https://derrors.github.io/iphone-control/en/deploy/docker) · [Source / binary](https://derrors.github.io/iphone-control/en/deploy/source) · [Data and backups](https://derrors.github.io/iphone-control/en/deploy/backup) |+| Problems | [FAQ](https://derrors.github.io/iphone-control/en/troubleshoot/faq) · [Troubleshooting](docs/troubleshooting.md) · [Issues](https://github.com/Derrors/iphone-control/issues) |+| Security | [SECURITY.md](SECURITY.md): what is stored, who can reach it, reporting vulnerabilities |+| Development | [Contributing](CONTRIBUTING.md) · [Architecture](docs/architecture.md) · [Decisions](docs/decisions.md) · [Changelog](CHANGELOG.md) |+| Licensing | [THIRD_PARTY.md](THIRD_PARTY.md): vendored components, versions and licenses |-Use it only with devices and accounts you own or are authorized to control. Automating third-party apps may violate their terms of service, and Apple may limit or suspend developer accounts — consider a dedicated Apple ID. The software is provided "as is", without warranty of any kind (see [LICENSE](LICENSE)).+The architecture and design documents are in Chinese for now.-Nothing here bypasses iOS security: trusting the computer, enabling Developer Mode, trusting the developer certificate and enabling UI automation all require the owner on the phone.+## Limitations-## Documentation+- One phone per host; don't run two instances (or other usbmuxd-based tools) against the same phone+- Free Apple ID profiles last 7 days. Re-signing is automatic, but an expired Apple ID session needs `login`+- After the phone reboots, you must unlock it and enter the passcode once to allow UI automation — iOS requires this+- Apple ID logins use a public third-party anisette server by default; set `ICTL_ANISETTE_URL` to use your own+- The container runs as root: it needs the USB device nodes and must restart usbmuxd after replugging-| Document | Contents |-|---|---|-| [docs/tools.md](docs/tools.md) | MCP tools and their parameters |-| [docs/troubleshooting.md](docs/troubleshooting.md) | What each state means and how to fix common problems |-| [SECURITY.md](SECURITY.md) | Threat model, hardening, reporting vulnerabilities |-| [CONTRIBUTING.md](CONTRIBUTING.md) | Building, testing (with and without a phone), pull requests |-| [CHANGELOG.md](CHANGELOG.md) | Release notes |-| [docs/architecture.md](docs/architecture.md) | Architecture, daemon state machine, modules, data layout (Chinese) |-| [docs/decisions.md](docs/decisions.md) | Key design decisions (Chinese) |-| [docs/licensing.md](docs/licensing.md), [THIRD_PARTY.md](THIRD_PARTY.md) | License analysis and third-party components (Chinese) |-| [docs/dev/](docs/dev/) | Development history: spike results, roadmap, regression cases (Chinese) |+> [!WARNING]+> This tool can fully control your phone. An agent may tap payment, delete or send buttons — keep tool-call confirmation on in your MCP client. Not affiliated with Apple; use it only with devices and accounts you own. Read [SECURITY.md](SECURITY.md) before enabling auto-unlock.-## Acknowledgements+## Contributing-Built on [idevice](https://github.com/jkcoxson/idevice) (device protocols), [Impactor](https://github.com/claration/impactor) (Apple ID and signing), [apple-codesign](https://github.com/indygreg/apple-platform-rs), [WebDriverAgent](https://github.com/appium/WebDriverAgent) (on-device automation), [usbmuxd](https://github.com/libimobiledevice/usbmuxd) and the [Rust MCP SDK](https://github.com/modelcontextprotocol/rust-sdk).+Bug reports and suggestions are welcome in [Issues](https://github.com/Derrors/iphone-control/issues); please include the output of `doctor` with your UDID removed. Pull requests are welcome too — see the [contributing guide](CONTRIBUTING.md).## License-The code in this repository is [MIT](LICENSE). Vendored components keep their own licenses (MPL-2.0 and MIT); see [THIRD_PARTY.md](THIRD_PARTY.md). Apple files such as the Developer Disk Image are downloaded at runtime and never distributed.+[MIT](LICENSE) for this project's code. Vendored signing components keep their own licenses (MPL-2.0 and MIT), and the Docker image also contains Debian's usbmuxd (GPL-3.0, run as a separate process). Apple files such as the Developer Disk Image are downloaded at runtime and never distributed. See [THIRD_PARTY.md](THIRD_PARTY.md).++<p align="right">(<a href="#readme-top">back to top</a>)</p>diff --git a/README.zh-CN.md b/README.zh-CN.mdindex 67f0baf..065a334 100644--- a/README.zh-CN.md+++ b/README.zh-CN.md@@ -1,179 +1,166 @@-# iphone-control+<a name="readme-top"></a>-[English](README.md) | **简体中文**+<div align="right">+ <a href="README.md">English</a> | <b>简体中文</b>+</div>-[](https://github.com/Derrors/iphone-control/actions/workflows/ci.yml)-[](LICENSE)+<div align="center">+ <a href="https://github.com/Derrors/iphone-control">+ <img src="website/public/logo.svg" alt="Logo" width="120">+ </a>-**文档站:[derrors.github.io/iphone-control](https://derrors.github.io/iphone-control/)**+ <h3 align="center">iphone-control</h3>-在 Linux 上控制一台通过 USB 连接的真实 iPhone(不需要 Mac,不需要付费开发者账号),并把能力以 [MCP](https://modelcontextprotocol.io) 工具的形式交给 AI agent。用 Rust 写成,产物是一个二进制,外加系统的 `usbmuxd`。+ <p align="center">+ 让 AI agent 操作一台接在 Linux 上的真实 iPhone:一个 Rust 二进制,不需要 Mac,不需要付费开发者账号,不越狱。+ </p>-> **状态:早期版本(0.x)。** 下面的功能都在一台真机上完整跑通:iPhone 15 Pro Max,iOS 27.0.1。其他机型和 iOS 17 以上应该也能用,但没测过,欢迎反馈。+ <p align="center">+ <a href="https://github.com/Derrors/iphone-control/releases/latest"><img src="https://img.shields.io/github/v/release/Derrors/iphone-control?style=flat-square" alt="Release"></a>+ <a href="https://github.com/Derrors/iphone-control/pkgs/container/iphone-control"><img src="https://img.shields.io/badge/ghcr.io-derrors%2Fiphone--control-2496ED?style=flat-square&logo=docker&logoColor=white" alt="Docker"></a>+ <img src="https://img.shields.io/badge/iOS-17%2B-black?style=flat-square&logo=apple" alt="iOS">+ <img src="https://img.shields.io/badge/MCP-15%20tools-8A2BE2?style=flat-square" alt="MCP">+ <a href="Cargo.toml"><img src="https://img.shields.io/badge/Rust-1.88%2B-CE422B?style=flat-square&logo=rust&logoColor=white" alt="Rust"></a>+ <a href="https://github.com/Derrors/iphone-control/actions/workflows/ci.yml"><img src="https://img.shields.io/github/actions/workflow/status/Derrors/iphone-control/ci.yml?branch=main&style=flat-square&label=CI" alt="CI"></a>+ <a href="LICENSE"><img src="https://img.shields.io/github/license/Derrors/iphone-control?style=flat-square" alt="License"></a>+ </p>-## 能做什么+ <p align="center">+ <a href="#快速开始"><strong>🚀 快速开始</strong></a>+ · + <a href="https://derrors.github.io/iphone-control/"><strong>📖 文档</strong></a>+ · + <a href="https://github.com/Derrors/iphone-control/releases">📦 版本发布</a>+ · + <a href="https://github.com/Derrors/iphone-control/issues">🐛 问题反馈</a>+ </p>+</div>-- **给 agent 的工具**:截图(可放大某块区域)、列出屏幕上的元素、按坐标或按文字点击、滑动、长按、输入文字(支持中文)、硬件按键、启动/结束 App、打开链接、等某段文字出现、一次执行多步。任何操作都可以顺带返回操作后的界面,省一次往返。见 [docs/tools.md](docs/tools.md)。-- **自己维持运行**:配对、挂载开发者镜像、用免费 Apple ID 给 WebDriverAgent 签名,并在 7 天描述文件过期前自动重签;WDA 挂了自动重启;拔插、手机重启后自动恢复。-- **后备路线**:WDA 不可用时,点击、滑动、按键、截图仍可经 CoreDevice HID 完成。-- **需要你时会通知**:重签失败、Apple ID 会话失效、手机重启后要输密码、手机离线时,经 Bark 或 Telegram 推送。-- **可选的自动解锁**:默认关闭;开启前先读 [SECURITY.md](SECURITY.md)。-- **不开端口**:WDA 经 usbmuxd 直连,本机不监听任何网络端口。+> [!NOTE]+> 早期版本(0.x),在 **iPhone 15 Pro Max(iOS 27.0.1)** 上完整测试过。其他机型和 iOS 17 以上应该也能用,但还没测过,欢迎反馈。-```-AI agent ──stdio──▶ iphone-control mcp ──unix socket──▶ iphone-control daemon ──usbmuxd/USB──▶ iPhone(WebDriverAgent)-```--一个常驻守护进程独占设备(隧道、HID 会话、WDA 会话常驻复用);每个 agent 会话是一个薄的 MCP 客户端。详见 [docs/architecture.md](docs/architecture.md)。+## 简介-## 需要什么+AI agent 已经能操作浏览器和电脑桌面,但真实的 iPhone 难得多:苹果的自动化工具需要 Mac 和 Xcode,开源替代品又是零散的几块,每一块都要单独安装、签名、看护。-- 一台有 USB 口的 Linux 主机(x86_64 或 arm64)。-- Docker(Compose v2);不用 Docker 时需要 Rust 1.88 以上、C 编译器和 `usbmuxd`(见[从源码运行](#从源码运行不用-docker))。-- iOS 17 以上的 iPhone 和数据线;开发者模式由 `setup` 引导打开。-- 一个免费 Apple ID,建议专门注册一个(见[安全与隐私](#安全与隐私))。-- 能访问苹果服务器、anisette 服务和 GitHub(首次使用时下载开发者镜像和 WebDriverAgent)。国内网络一般要在 `.env` 里配代理。+iphone-control 在 Linux 上用**一个 Rust 二进制**把这些事都做了,基于 [idevice](https://github.com/jkcoxson/idevice)、[Impactor](https://github.com/claration/impactor) 和 [WebDriverAgent](https://github.com/appium/WebDriverAgent)。一个常驻守护进程独占手机(隧道、HID 会话、WebDriverAgent 会话常驻复用),把它交给 Claude Code 或任何 MCP 客户端。它是 [iphone-control-toolkit](https://github.com/Derrors/iphone-control-toolkit) 的继任者,MCP 工具保持兼容。-## 快速开始(Docker)--```bash-git clone https://github.com/Derrors/iphone-control && cd iphone-control-cp .env.example .env # 可选:代理、通知、自动解锁-docker compose up -d --build # 首次构建要编译 Rust,需要几分钟-docker exec -it iphone-control iphone-control setup-docker exec -it iphone-control iphone-control mcp-config # 打印注册 MCP 的命令+```+Claude Code / any MCP client+ │ MCP over stdio+ ▼+┌──────── iphone-control daemon (Docker or systemd) ────────┐+│ WebDriverAgent (primary) │+│ CoreDevice HID (fallback) │+│ supervisor: usbmuxd · reconnect · re-sign · notify │+└─────────────────────────────┬──────────────────────────────┘+ │ USB (no network port opened)+ iPhone```-发布版本后可以不自己构建:在 `.env` 里设 `IMAGE=ghcr.io/derrors/iphone-control:latest`,然后 `docker compose pull && docker compose up -d --no-build`。--`setup` 可以重复运行,依次是:--1. **连接**:用数据线接好手机并解锁。-2. **配对**:手机上点「信任」,输入锁屏密码。-3. **开发者模式**:设置 → 隐私与安全性 → 开发者模式 → 打开 → 重新启动;重启解锁后在弹窗里确认。-4. **登录 Apple ID**:密码和双重认证验证码只在这个终端里输入。-5. **签名并安装 WebDriverAgent**:期间手机保持解锁。-6. **启动 WebDriverAgent**:首次要在 设置 → 通用 → VPN 与设备管理 里信任你的 Apple ID;如果弹出「为 XCTest 输入 iPhone 密码」(Enable UI Automation),输入锁屏密码。+## 功能特性-容器不用 `privileged`:只开放 USB 字符设备(`device_cgroup_rules: "c 189:* rmw"`),`/dev/bus/usb` 绑定挂载。不要同时运行两份(或其他基于 usbmuxd 的工具)连同一部手机。+- **看屏幕、点屏幕**:截图(可放大某块区域)、点击、滑动、长按、输入文字(支持中文)、硬件按键+- **按界面元素操作**:读元素树、按文字点击(自动避开悬浮栏、键盘挡住的部分)、启动和结束 App、打开链接、等某段文字出现+- **省往返**:任何操作都可以等界面稳定后顺带返回操作后的样子,并提示页面是否还在加载、有没有弹窗挡着;`iphone_batch` 一次执行最多 20 步+- **自动后备**:WebDriverAgent 不可用时,截图、点击、滑动、按键改走苹果的 CoreDevice HID 服务+- **无人值守**:拔插、手机重启、WebDriverAgent 崩溃后自动恢复;用免费 Apple ID 签名,7 天描述文件过期前自动重签+- **告警通知**:重签失败、Apple ID 会话失效、手机离线、重启后需要输密码时,经 Telegram 或 Bark 推送+- **可选的自动解锁**:每输一位都核对,密码错了只试一次就停用+- **诊断**:`doctor` 从 USB 到 WebDriverAgent 逐层检查,每项失败都告诉你怎么修-## 接入 MCP 客户端+## 快速开始-Claude Code(容器部署时 `mcp-config` 打印的就是这条):+需要一台装了 Docker(Compose v2)的 Linux 主机(x86_64 或 arm64)、一部 iOS 17 以上的 iPhone 和能**传数据**的线,以及一个免费 Apple ID(建议专门注册一个,不要用主账号)。```bash+git clone https://github.com/Derrors/iphone-control.git+cd iphone-control+cp .env.example .env # 可选:代理、通知;国内网络一般要配代理+docker compose up -d --build # 首次构建要编译 Rust,需要几分钟+docker exec -it iphone-control iphone-control setup # 安装向导,可重复运行claude mcp add iphone -s user -- docker exec -i iphone-control iphone-control mcp```-其他客户端(Claude Desktop、Cursor 等)在 JSON 配置里写同一条命令:+`setup` 会引导完成配对、打开开发者模式、登录 Apple ID、签名并安装 WebDriverAgent。手机上要做的是点「信任」、打开开发者模式,以及在 设置 → 通用 → VPN 与设备管理 里信任你的 Apple ID,详见[分步指南](https://derrors.github.io/iphone-control/guide/getting-started)。-```json-{- "mcpServers": {- "iphone": { "command": "docker", "args": ["exec", "-i", "iphone-control", "iphone-control", "mcp"] }- }-}-```+打开一个新的 Claude Code 会话,试着说:-从源码运行时改为 `iphone-control --socket <路径> mcp`,具体命令用 `iphone-control mcp-config` 打印。+> 打开时钟,切到秒表,给我看一下截图。-## 从源码运行(不用 Docker)+> [!TIP]+> 其他 MCP 客户端:服务经 `docker exec` 走 stdio,不开任何网络端口。+>+> ```json+> { "mcpServers": { "iphone": { "command": "docker", "args": ["exec", "-i", "iphone-control", "iphone-control", "mcp"] } } }+> ```-以 Debian/Ubuntu 为例:--```bash-sudo apt install build-essential git usbmuxd # usbmuxd 由 udev 在插上手机时拉起-git clone https://github.com/Derrors/iphone-control && cd iphone-control-cargo install --path apps/iphone-control --locked # 装到 ~/.cargo/bin/iphone-control-iphone-control daemon # 前台运行;常驻用下面的 systemd 用户服务-iphone-control setup # 另开一个终端-iphone-control mcp-config-```+发布正式版本后可以不自己构建:在 `.env` 里设 `IMAGE=ghcr.io/derrors/iphone-control:latest`,然后 `docker compose pull && docker compose up -d --no-build`。不用 Docker 的话,可以用[预编译二进制或从源码编译](https://derrors.github.io/iphone-control/deploy/source),以 systemd 用户服务运行。-常驻运行用 [deploy/iphone-control.service](deploy/iphone-control.service)(systemd 用户服务):+## MCP 工具-```bash-mkdir -p ~/.config/systemd/user ~/.config/iphone-control-cp deploy/iphone-control.service ~/.config/systemd/user/-cp .env.example ~/.config/iphone-control/env # CONTAINER_NAME、IMAGE、DATA_DIR 只给 compose 用-systemctl --user daemon-reload && systemctl --user enable --now iphone-control-loginctl enable-linger "$USER" # 不登录也随开机启动-```+| 工具 | 作用 |+| --- | --- |+| `iphone_status` | 连接状态、是否锁屏、前台 App、屏幕尺寸 |+| `iphone_screenshot` | 截图(单位为点);给出 `x/y/width/height` 时放大这块区域 |+| `iphone_list_elements` | 带文字的元素和中心点坐标;可按文字或类型筛选 |+| `iphone_tap` / `iphone_tap_element` | 按坐标或按元素文字点击 |+| `iphone_swipe` / `iphone_long_press` | 滑动(列表停稳后返回)、长按 |+| `iphone_type_text` | 在当前输入框输入文字;输完读回核对,丢字会补上 |+| `iphone_press_button` | `home`、`volume_up`、`volume_down`、`lock` |+| `iphone_list_apps` / `iphone_launch_app` / `iphone_terminate_app` | 按名字或 Bundle ID 管理 App |+| `iphone_open_url` | 打开链接或 URL Scheme |+| `iphone_wait_for` | 等某段文字出现,代替反复截图 |+| `iphone_batch` | 一次执行最多 20 步,出错就停 |-| | 容器 | 从源码(普通用户) |-|---|---|---|-| 数据目录 | `./data`(容器内 `/var/lib/iphone-control`) | `~/.local/share/iphone-control` |-| 控制接口 | 容器内 `/run/iphone-control/ctl.sock` | `$XDG_RUNTIME_DIR/iphone-control/ctl.sock` |-| usbmuxd | 守护进程拉起并看护(容器里没有 udev) | 系统服务,守护进程不拉起 |-| 配对记录 | 数据目录的 `lockdown/` | 系统的 `/var/lib/lockdown` |-| 未签名的 WDA | 镜像自带 | 第一次签名前下载同一版本(核对 sha256) |-| 配置 | `.env` | 环境变量,例如 systemd 的 `EnvironmentFile` |+操作类工具可以带 `then: "elements" | "screenshot"`,顺带返回操作后的界面。截图的像素就是点击坐标,agent 看到哪里就能点哪里。游戏、地图、视频自己绘制界面,没有元素树,只能看截图按坐标操作。完整参数见 [docs/tools.md](docs/tools.md)。-守护进程、命令行和 MCP 要用同一个用户运行;别的用户要用 `--socket`、`--data-dir`(或 `ICTL_SOCKET`、`ICTL_DATA_DIR`)指过去。以 root 运行时默认路径和容器里一样,守护进程会自己拉起 usbmuxd;宿主机已有 usbmuxd 服务时设 `ICTL_MANAGE_USBMUXD=0`。装了系统 usbmuxd 又要用回容器版时,先 `sudo systemctl mask usbmuxd`,否则两边会抢设备。+## 常用命令-## 命令+用 `docker exec -it iphone-control iphone-control <命令>` 运行;从源码运行时直接调用。| 命令 | 作用 |-|---|---|-| `daemon` | 常驻守护进程(容器入口) |-| `mcp` | MCP stdio 服务,经控制接口调用守护进程 |-| `mcp-config` | 打印把 MCP 注册到 Claude Code 的命令 |-| `status` / `doctor` | 状态快照和最近日志 / 逐层诊断,每项失败都给出修复办法 |-| `setup` | 首次安装向导(可重复运行) |-| `login` | 登录 Apple ID(密码不回显,支持双重认证和短信) |-| `sign` / `resign [--force]` | 立即签名安装 WDA / 描述文件快过期才重签 |-| `passcode set\|clear`、`unlock-reset` | 自动解锁(默认关闭) |-| `wda-bridge --port 8100` | 把 WDA 桥接到 127.0.0.1 给别的工具用:没有认证,用完就停 |-| `notify-test` | 每类事件发一条测试通知 |--## 配置--全部通过环境变量配置,都可以不填。完整列表见 [.env.example](.env.example),常用的:--| 变量 | 含义 |-|---|---|-| `HTTP_PROXY`、`HTTPS_PROXY` | 访问苹果、anisette、开发者镜像和推送通知时用的代理 |-| `IPHONE_UDID` | 接了多台手机时指定用哪台 |-| `BARK_KEY`、`BARK_SERVER`、`TG_BOT_TOKEN`、`TG_CHAT_ID` | 通知 |-| `RESIGN_MIN_DAYS`、`RESIGN_CHECK_HOURS` | 什么时候重签 WebDriverAgent |-| `ICTL_ANISETTE_URL` | 用自建 anisette 服务代替默认的第三方服务 |-| `ICTL_DDI_URL`、`ICTL_DDI_DIR` | 开发者镜像从哪里来 |+| --- | --- |+| `status` | 守护进程状态、描述文件还剩多久、最近日志 |+| `doctor` | 逐层诊断,每项失败都给出修复办法 |+| `setup` | 安装向导,随时可以重新运行 |+| `login` | Apple ID 会话失效时重新登录 |+| `resign [--force]` | 快过期才重签 WebDriverAgent(或立即重签) |+| `passcode set\|clear` | 开启或关闭自动解锁 |+| `notify-test [事件]` | 发送测试通知 |+| `mcp-config` | 打印注册 MCP 的命令 |++升级:`git pull && docker compose up -d --build`(用预构建镜像时改为 `docker compose pull`)。配置写在 `.env`,见[配置说明](https://derrors.github.io/iphone-control/guide/configuration)。所有状态都在 `data/`:配对记录、Apple ID 会话和签名私钥,开启自动解锁时还有锁屏密码。**要备份,不要提交或分享。**-## 安全与隐私--部署前请读 [SECURITY.md](SECURITY.md)。要点:--- 数据目录里有 Apple ID 会话、开发签名私钥、配对记录;开启自动解锁时还有明文的锁屏密码。要备份,不要提交或分享。-- 容器以 root 运行:要访问 USB 设备节点,拔插后还要能重启 `usbmuxd`。-- 登录 Apple ID 要用 anisette 服务,默认是公共的第三方服务;可用 `ICTL_ANISETTE_URL` 换成自建服务。-- 能访问控制接口(Unix socket)或正在运行的 `wda-bridge` 的人,都能操控手机。--## 免责声明+## 文档-本项目与 Apple Inc. 没有任何关联,也未获其认可或赞助。iPhone、iOS、Xcode 是 Apple Inc. 的商标。+| | |+| --- | --- |+| 入门 | [什么是 iphone-control](https://derrors.github.io/iphone-control/guide/what-is-iphone-control) · [快速开始](https://derrors.github.io/iphone-control/guide/getting-started) · [接入 AI 客户端](https://derrors.github.io/iphone-control/guide/mcp-clients) · [工具一览](https://derrors.github.io/iphone-control/guide/tools) |+| 使用 | [配置](https://derrors.github.io/iphone-control/guide/configuration) · [通知](https://derrors.github.io/iphone-control/guide/notifications) · [自动解锁](https://derrors.github.io/iphone-control/guide/auto-unlock) |+| 安装 | [Docker](https://derrors.github.io/iphone-control/deploy/docker) · [从源码 / 二进制](https://derrors.github.io/iphone-control/deploy/source) · [数据与备份](https://derrors.github.io/iphone-control/deploy/backup) |+| 问题 | [常见问题](https://derrors.github.io/iphone-control/troubleshoot/faq) · [排错(英文)](docs/troubleshooting.md) · [Issues](https://github.com/Derrors/iphone-control/issues) |+| 安全 | [SECURITY.md](SECURITY.md):存了什么、谁能访问、怎么报告漏洞 |+| 开发 | [贡献指南](CONTRIBUTING.md) · [架构](docs/architecture.md) · [关键取舍](docs/decisions.md) · [更新日志](CHANGELOG.md) |+| 许可证 | [THIRD_PARTY.md](THIRD_PARTY.md):vendor 组件、版本和许可证 |-只在你自己拥有或获得授权的设备和账号上使用。自动操作第三方 App 可能违反其服务条款;苹果可能限制或停用开发者账号,建议使用专门的 Apple ID。本软件按「原样」提供,不提供任何担保(见 [LICENSE](LICENSE))。+## 限制-本项目不绕过任何 iOS 安全机制:信任电脑、开启开发者模式、信任开发者证书、启用 UI 自动化都需要机主本人在手机上操作。+- 一台主机接一部手机;不要同时运行两份(或其他基于 usbmuxd 的工具)连同一部手机+- 免费 Apple ID 的描述文件 7 天有效。重签是自动的,但 Apple ID 会话失效后要运行 `login`+- 手机重启后,要人工解锁一次,并输一次密码允许 UI 自动化,这是 iOS 的要求+- 登录 Apple ID 默认用公共的第三方 anisette 服务;可设 `ICTL_ANISETTE_URL` 换成自建服务+- 容器以 root 运行:要访问 USB 设备节点,拔插后还要能重启 usbmuxd-## 文档+> [!WARNING]+> 这个工具能完全控制你的手机,agent 可能点到付款、删除、发送这类按钮,请在 MCP 客户端里保持工具调用确认。本项目与 Apple 无关;只在你自己的设备和账号上使用。开启自动解锁前请先读 [SECURITY.md](SECURITY.md)。-| 文档 | 内容 |-|---|---|-| [docs/tools.md](docs/tools.md) | MCP 工具和参数(英文) |-| [docs/troubleshooting.md](docs/troubleshooting.md) | 各状态的含义和常见问题的处理(英文,附中文状态原文) |-| [SECURITY.md](SECURITY.md) | 威胁模型、加固建议、漏洞报告(英文) |-| [CONTRIBUTING.md](CONTRIBUTING.md) | 构建、测试(有无手机两种)、提交 PR(英文,PR 和 issue 可以用中文) |-| [CHANGELOG.md](CHANGELOG.md) | 版本记录 |-| [docs/architecture.md](docs/architecture.md) | 架构、守护进程状态机、模块划分、数据目录 |-| [docs/decisions.md](docs/decisions.md) | 关键取舍记录 |-| [docs/licensing.md](docs/licensing.md)、[THIRD_PARTY.md](THIRD_PARTY.md) | 许可证分析、第三方组件 |-| [docs/dev/](docs/dev/) | 开发过程:spike 结果、路线图、回归用例 |+## 参与贡献-## 致谢+欢迎通过 [Issues](https://github.com/Derrors/iphone-control/issues) 反馈问题或提出建议,请附上去掉 UDID 后的 `doctor` 输出。也欢迎提交 Pull Request,构建、测试和提交前检查见[贡献指南](CONTRIBUTING.md)。-基于 [idevice](https://github.com/jkcoxson/idevice)(设备协议)、[Impactor](https://github.com/claration/impactor)(Apple ID 与签名)、[apple-codesign](https://github.com/indygreg/apple-platform-rs)、[WebDriverAgent](https://github.com/appium/WebDriverAgent)(手机端自动化)、[usbmuxd](https://github.com/libimobiledevice/usbmuxd) 和 [Rust MCP SDK](https://github.com/modelcontextprotocol/rust-sdk)。+## License-## 许可证+本项目的代码使用 [MIT](LICENSE)。vendor 进来的签名组件保留各自的许可证(MPL-2.0 和 MIT),Docker 镜像里还有 Debian 的 usbmuxd(GPL-3.0,作为独立进程运行)。开发者镜像等苹果文件在运行时下载,从不分发。详见 [THIRD_PARTY.md](THIRD_PARTY.md)。-本仓库的代码使用 [MIT](LICENSE)。vendor 进来的组件保留各自的许可证(MPL-2.0 和 MIT),见 [THIRD_PARTY.md](THIRD_PARTY.md)。开发者镜像等苹果文件在运行时下载,从不分发。+<p align="right">(<a href="#readme-top">回到顶部</a>)</p>