Metadata-Version: 2.5
Name: phonectl-mcp
Version: 0.2.0
Summary: MCP server that lets AI agents see and drive a real iPhone over USB: screenshots, on-screen text, taps, swipes, typing, apps.
Project-URL: Homepage, https://github.com/jiefeng-ai/phonectl-mcp
Project-URL: Issues, https://github.com/jiefeng-ai/phonectl-mcp/issues
Author: jiefeng-ai
License-Expression: MIT
License-File: LICENSE
Keywords: agent,automation,ios,iphone,mcp,model-context-protocol
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: MacOS X
Classifier: Intended Audience :: Developers
Classifier: Operating System :: MacOS
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.13
Requires-Dist: mcp<3,>=2.3.0
Requires-Dist: pillow>=13.0.0
Requires-Dist: pymobiledevice3==11.50.0
Requires-Dist: pyobjc-framework-vision>=13.0
Description-Content-Type: text/markdown

<p align="center">English · <a href="https://github.com/jiefeng-ai/phonectl-mcp/blob/main/README.zh-CN.md">中文</a></p>

<h1 align="center"><picture><source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jiefeng-ai/phonectl-mcp/main/docs/logo-dark.svg?v=5"><img src="https://raw.githubusercontent.com/jiefeng-ai/phonectl-mcp/main/docs/logo-light.svg?v=5" height="54" align="middle" alt=""></picture> phonectl-mcp</h1>

<p align="center"><b>Let AI agents see and drive a real iPhone from your Mac, over USB or Wi-Fi.</b></p>

<p align="center">
  <a href="https://pypi.org/project/phonectl-mcp/"><img src="https://img.shields.io/pypi/v/phonectl-mcp?logo=pypi&logoColor=white" alt="PyPI"></a>
  <img src="https://img.shields.io/badge/macOS-only-000?logo=apple&logoColor=white" alt="macOS only">
  <img src="https://img.shields.io/badge/iOS-27%2B-000?logo=ios&logoColor=white" alt="iOS 27+">
  <a href="https://modelcontextprotocol.io"><img src="https://img.shields.io/badge/MCP-server-000?logo=modelcontextprotocol&logoColor=white" alt="MCP server"></a>
  <a href="https://github.com/jiefeng-ai/phonectl-mcp/actions/workflows/test.yml"><img src="https://github.com/jiefeng-ai/phonectl-mcp/actions/workflows/test.yml/badge.svg?branch=main" alt="Tests"></a>
  <a href="https://github.com/jiefeng-ai/phonectl-mcp/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue" alt="License: MIT"></a>
</p>

<p align="center"><a href="#install">Install</a> · <a href="#tools">Tools</a> · <a href="#several-agents-one-phone">Sharing</a> · <a href="#scripts">Scripts</a> · <a href="#troubleshooting">Troubleshooting</a> · <a href="#security">Security</a></p>

An MCP server for screenshots, on-screen text, taps, swipes, typing, buttons, apps and the clipboard on an iPhone connected to your Mac. Nothing to install on the phone.

<table align="center">
  <tr>
    <td align="center" width="50%"><img src="https://raw.githubusercontent.com/jiefeng-ai/phonectl-mcp/main/docs/demo-rednote.gif?v=2" width="260" alt="An AI agent makes a rednote post through phonectl-mcp: text card, template, stickers, filter, title and caption"></td>
    <td align="center" width="50%"><img src="https://raw.githubusercontent.com/jiefeng-ai/phonectl-mcp/main/docs/demo.gif?v=5" width="260" alt="A script applies to one job in the BOSS Zhipin app through phonectl-mcp, reading the screen with read_text and tapping"></td>
  </tr>
  <tr>
    <td align="center"><sub>An AI agent makes a rednote post: text card, template, stickers, filter, caption. It stops before <b>Post</b>. Sped up.</sub></td>
    <td align="center"><sub>A script applies to a job in a recruiting app: <code>read_text</code> finds the buttons, <code>tap</code> presses them. 2× speed.</sub></td>
  </tr>
</table>

## Requirements

- A Mac with [uv](https://docs.astral.sh/uv/)
- An iPhone on **iOS 27 or later**, with Developer Mode on
- A USB data cable for the first setup. After that, Wi-Fi works too

Tested on an iPhone 17 Pro with iOS 27.2 and macOS 27.

## Install

### Let your agent install it

Paste this to your coding agent (Claude Code, Codex, Cursor…):

> Install phonectl-mcp by following https://github.com/jiefeng-ai/phonectl-mcp#install-by-hand and add it to your MCP config. Run `phonectl doctor` until it passes. When I need to do something on the phone, tell me step by step and wait for me. Finally, tell me how to restart you so the phone tools load.

After the restart, ask the agent for a screenshot of the phone.

### Install by hand

Run all three:

```sh
uv tool install phonectl-mcp
phonectl install-service   # runs the server at login on http://127.0.0.1:47321/mcp
phonectl doctor            # checks cable, trust, Developer Mode, disk image and server
```

`install-service` also creates an access token in `~/.config/phonectl/token`. Then connect the agent you use, one command per agent:

```sh
phonectl setup claude-code        # or: codex, gemini (the desktop app), deepseek-harness
```

`setup` adds the server to the agent's MCP config, with the token, installs the `phonectl-scripts` skill (the rules for a script that shares the phone: wait in line, yield between units of work, survive being interrupted), and, for Claude Code, Codex and Gemini, a hook that frees the phone when the agent's turn ends (Codex asks you to approve it once, under Hooks need review). Before it first changes a file, it keeps the original as `<file>.phonectl.bak`, and it prints what it changed. `phonectl setup` alone lists the agents it knows; `phonectl setup --remove <agent>` takes all of it out again. After upgrading phonectl, `phonectl update` brings the skill up to date in every agent set up this way (`doctor` says when one is behind); a skill you edited by hand is left as it is.

**Other clients by hand** (`~/.cursor/mcp.json` and others with streamable HTTP). This gives the agent the phone, but not the skill: scripts it writes will not know to yield the phone to other agents.

```json
{
  "mcpServers": {
    "phone": {
      "url": "http://127.0.0.1:47321/mcp",
      "headers": { "Authorization": "Bearer <contents of ~/.config/phonectl/token>" }
    }
  }
}
```

Restart the client so it loads the server, then ask your agent for a screenshot of the phone.

After one setup over the cable, it also works over Wi-Fi while the phone and the Mac share a network.

## Tools

Coordinates are iOS points, the same as the pixels of the returned screenshot.

| Tool | What it does |
| --- | --- |
| `screenshot` | Captures the screen |
| `read_text` | Text on screen with positions, as JSON. Much cheaper than an image |
| `tap_text`, `wait_text` | Tap text found on screen; wait until text appears or goes away |
| `tap`, `long_press`, `swipe` | Touch. To scroll down, swipe upward |
| `type_text` | Types into the focused field by pasting, so the phone's input method cannot change it; submit with `press_key('enter')`. `method="keys"` types key by key, for fields that refuse pasting |
| `press_key` | A key or chord, such as `enter` or `cmd+a` |
| `press_button` | `home`, `lock`, `volume-up`, `volume-down`, `mute`, `siri` |
| `launch_app`, `list_apps` | Opens apps (with `url`, hands the app a link to open), finds bundle ids |
| `get_clipboard`, `set_clipboard` | The phone's clipboard |
| `status` | The server, the phone link, and who is using the phone |

Tools that act on the phone return a screenshot taken afterwards (`screenshot=False` skips it). Taps are not confirmed, so check that screenshot.

## Several agents, one phone

All clients of the server share the phone, and they take turns: a client that starts using it keeps it for its whole task, until it says it is done: its turn ends (an end-of-turn hook, below), a script yields between units of work, or its process exits. The server does not guess the end of a task from the pauses between calls; only a client that made no call for 90 s while someone waits is taken to be done, and it gets back in line on its next call. A call from another client meanwhile waits in line instead of landing on the other agent's screen. A wait lasts at most 50 s, shorter than any agent's own tool timeout; then the call ends with `WAITING`, having done nothing, and the client keeps its place in line for 2 minutes: calling again carries on from there. Agents read `WAITING` as a reason to call again, not as a failure. `status` says who has the phone and who waits.

- Clients are told apart by their process: a Claude Code session and its subagents are one client. A script that an agent runs counts as that agent, so it neither waits for the agent nor takes the phone from it; a script started from a terminal is a client of its own. A process that runs several independent tasks sends a header `X-Phonectl-Client: <name>` per task. When a client's process exits, the phone is free at once, named or not.
- A tap, swipe, typing or key press is sent only if the process making it has looked at the screen since anyone else changed it (a script an agent runs is its own process here: its look does not show the agent the screen, and its taps make the agent look again). Otherwise the call fails with `NOT DONE` and nothing is sent; look at the screen and repeat it. This also holds for a process's first such input after the server starts, since the server cannot know who used the phone before. `tap_text` is held to the same rule, since the text it finds may be in someone else's app, unless the caller has opened its own app with `launch_app` since. `launch_app` and `press_button` need no old coordinates and are always sent. A process an agent starts for the first time counts as having seen what the agent last saw (a tool run once per call looks in one run and taps in the next); the server cannot tell which of an agent's processes it read the screen from.
- A long-running script gives the phone up between two units of work with `POST /phonectl/yield` (same token), which hands it over only if someone is waiting. Without that, others wait until it exits, makes no call for 90 s, or has held the phone for 30 minutes.
- When an agent's turn ends, its hook can say so with `POST /phonectl/done`, and the phone is free at once instead of after 90 s; `phonectl setup` adds that hook to Claude Code, Codex and Gemini. The server tells clients apart by process, so all conversations of one desktop app (Codex's, Gemini's) are one client: any of them ending its turn frees the phone, and another that was using it gets back in line on its next call.
- The server cannot see you using the phone by hand: `phonectl hold 30m` keeps agents off it, `phonectl hold off` ends that.

## Scripts

A fixed sequence of steps does not need a model to think between them. As a script, it is one command for the agent instead of one model round trip per step. A script is just another MCP client of the same server, on any MCP library; with the official Python SDK:

```python
# /// script
# dependencies = ["mcp>=2.3,<3"]
# ///
import asyncio, json
from pathlib import Path
from mcp.client.session import ClientSession
from mcp.client.streamable_http import streamable_http_client
from mcp.shared._httpx_utils import create_mcp_http_client

async def main():
    token = (Path.home() / ".config/phonectl/token").read_text().strip()
    http = create_mcp_http_client(headers={"Authorization": f"Bearer {token}"})
    async with streamable_http_client("http://127.0.0.1:47321/mcp", http_client=http) as (read, write, *_):
        async with ClientSession(read, write) as phone:
            await phone.initialize()
            for tool, args in [("launch_app", {"bundle_id": "com.apple.Preferences", "restart": True}),
                               ("tap_text", {"text": "Wi-Fi", "timeout_s": 5, "settle_ms": 1000}),
                               ("read_text", {})]:
                args = {**args, "screenshot": False} if tool != "read_text" else args
                result = await phone.call_tool(tool, args)
                while result.is_error and result.content[0].text.startswith("WAITING"):
                    result = await phone.call_tool(tool, args)  # another client has the phone: same place in line
                if result.is_error:  # NOT DONE, the phone gone: stop instead of carrying on
                    return f"{tool}: {result.content[0].text}"
            return [line["t"] for line in json.loads(result.content[0].text)]

print(asyncio.run(main()))
```

Run it with `uv run script.py`. Its calls share the phone like an agent's: they wait while another client has it, a refused call is an error result, and the phone is free as soon as the script exits.

## Troubleshooting

Run `phonectl doctor` first. It tells you which link is broken.

| Symptom | Fix |
| --- | --- |
| No iPhone found | Use a data cable, unlock the phone, replug |
| "Mac is not trusted" | Unlock the phone, replug, tap **Trust** |
| No Developer Mode switch | Run `phonectl doctor --fix`; the switch appears under Settings › Privacy & Security |
| Disk image install fails | The server installs the developer disk image on first connect and downloads it from GitHub; check the network or proxy, then `phonectl restart` |
| Taps do nothing | Needs iOS 27+; keep the screen on and unlocked |
| Wi-Fi link drops | A locked phone leaves the network for up to minutes at a time. Unlock it and wait a few seconds |
| Clients cannot connect | `phonectl restart`, then check `~/Library/Logs/phonectl.error.log`. A 401 means the client's token differs from `~/.config/phonectl/token` |

## Security

- The server listens only on `127.0.0.1` and rejects requests without the token.
- An agent can do anything your finger can: send messages, pay, delete. Keep its instructions narrow and watch the screen. Use at your own risk; automating third-party apps may break their terms.

## Settings

<details>
<summary>Environment variables (set them, then run <code>phonectl install-service</code> again; <code>restart</code> keeps the old values)</summary>

| Variable | Default | Meaning |
| --- | --- | --- |
| `PHONECTL_UDID` | first connected iPhone | Which phone to use when several are connected |
| `PHONECTL_PORT` | `47321` | HTTP port (127.0.0.1 only) |
| `PHONECTL_TOKEN_FILE` | `~/.config/phonectl/token` | Where the token is kept |
| `PHONECTL_SCALE` | `3` | Pixels per point; 2 on iPhone SE, XR, 11. Only affects screenshot size |
| `PHONECTL_OCR_LANGS` | `zh-Hans,en-US` | `read_text` languages, in priority order |
| `PHONECTL_SETTLE` | `0.6` | Seconds to wait before the screenshot after an action; `settle_ms` overrides it per call |
| `PHONECTL_TOUCH_IDLE` | `30` | Idle seconds before the input stream closes (reopening takes ~0.6 s) |
| `PHONECTL_KEY_IDLE` | `5` | Seconds without a key before the virtual keyboard detaches, so the on-screen keyboard comes back |
| `PHONECTL_CALL_TIMEOUT` | `15` | Seconds to wait for the phone, on top of the gesture time |
| `PHONECTL_IDLE` | `90` | Seconds without a call after which a client that has not said it is done counts as done, if someone waits |
| `PHONECTL_WAIT` | `50` | Seconds a call waits in line before it ends with `WAITING`; keep it below the clients' own tool timeouts |
| `PHONECTL_MAX_HOLD` | `1800` | After holding the phone this long, a client lets a waiting one go first |
| `PHONECTL_LOG` | `WARNING` | Log level (`INFO` for the service, which logs each call with its client); logs in `~/Library/Logs/phonectl*.log`; a log over 10 MB moves to `<file>.1`, replacing the older one |

</details>

Other commands: `phonectl restart` (e.g. after `uv tool upgrade phonectl-mcp`). To remove: `phonectl uninstall-service`, `uv tool uninstall phonectl-mcp`, and delete `~/.config/phonectl`.

## License

MIT
