Let Claude Code control an Android emulator
Register Karagöz's MCP server with Claude Code, then let it read an Android emulator's screen, tap and type.
karagoz mcp serves the 18 Karagöz commands to Claude Code as tools. Claude Code reads the emulator’s screen as text, taps, types and takes screenshots, and each tool returns the JSON line the CLI prints. The server opens no port: Claude Code starts the process and talks to it over stdio.
1. Before you start
Section titled “1. Before you start”- Node 22 or newer.
adbfrom Android platform-tools.- A running emulator:
emulator -avd <name>.
The registration below runs the published package with npx, without installing it. To run the commands in your own terminal as well, see Install.
2. Register the server
Section titled “2. Register the server”claude mcp add karagoz -- npx -y karagoz-mcp mcpThe server starts in the directory claude started in, with the shell’s environment. A call still running after 2 minutes becomes a background task.
For more information, see MCP server.
3. Check that the emulator is listed
Section titled “3. Check that the emulator is listed”karagoz devicesFound 1 device: Medium_Phone_API_37.0 • emulator-5554 • emulator • Android 17 (API 37) • device
Missing a device? Run karagoz doctor.exit 0Without a global install, npx -y karagoz-mcp devices runs the same command. Only a device in state device can be used.
When more than one device is listed, a tool call’s device argument picks one. Without it the server uses KARAGOZ_DEVICE, then ANDROID_SERIAL from its own environment, then the only device: Device selection.
For more information, see devices.
4. Add the agent instructions
Section titled “4. Add the agent instructions”This step is optional. Add the block below to your CLAUDE.md, AGENTS.md or your agent’s rules, or ask your agent to add it. The agent then uses Karagöz for a request about a device without being told to.
## Mobile devices
For anything on an Android emulator or phone, an iOS simulator or an iPhone (reading the screen, tapping, typing, screenshots, installing or launching an app, logs), use karagoz instead of calling adb, xcrun simctl, devicectl or xcodebuild yourself. Use the karagoz MCP tools when they are available; otherwise run `npx -y karagoz-mcp <command>`. Read the screen with ui-tree before taking a screenshot, tap by text or id, and branch on error.code.5. Ask for a task
Section titled “5. Ask for a task”Describe the task to Claude Code. It reads the screen with ui_tree and calls one tool per step.
- “Open Settings on the emulator and turn on dark mode.”
- “The app closes right after launch on the emulator. Show me its last 50 log lines.”
Esc cancels the running call. What already reached the emulator still finishes: a gesture plays to the end, and a cancelled install may leave the app installed.
6. How it reads the screen
Section titled “6. How it reads the screen”ui_treereturns the screen’s accessibility tree. It is text a program can search, costs a few hundred to a few thousand tokens, and gives the bounds needed to tap.tapwithtextoridfinds one node in the tree and taps its center.screenshotwrites a full-resolution PNG to disk and returns its path, with its pixel size, logical size, scale and safe area. Withinline: trueit also returns the image, which the client scales before the model sees it. So coordinates come from the tree’sbounds, never from the image.
A tool’s name has _ where its command has -, because Codex turns - into _: the ui-tree command is the ui_tree tool.
For more information, see ui-tree and tap.
With Codex
Section titled “With Codex”Codex was run against this server too. Register it:
codex mcp add karagoz -- npx -y karagoz-mcp mcpThen add these two lines under [mcp_servers.karagoz] in ~/.codex/config.toml. The command cannot write them, and without them Codex hides ANDROID_HOME from Karagöz and cuts long calls short.
env_vars = ["ANDROID_HOME", "ANDROID_SDK_ROOT", "KARAGOZ_DEVICE", "ANDROID_SERIAL", "DEVELOPER_DIR"]tool_timeout_sec = 600- Codex passes a server only a short list of environment variables.
env_varsforwards the ones Karagöz reads. tool_timeout_seccovers longtapwaits and big installs.installanduninstallask for approval.codex execnever asks, so it refuses them withMCP tool call requires approval, but approval policy is never. Run them in an interactive Codex session or from the CLI.
For more information, see MCP server.
When it fails
Section titled “When it fails”ADB_NOT_FOUND: noadbfound.doctorshows where Karagöz looked and whichadbit uses. Install platform-tools, or setANDROID_HOMEto your Android SDK. With Codex,env_varsforwardsANDROID_HOME.NO_DEVICE: no device connected and none named. Karagöz needs a running emulator:emulator -avd <name>.DEVICE_AMBIGUOUS: more than one device and none named. The tool call needsdevice, orKARAGOZ_DEVICEset in the shell you startclaudefrom.AUTOMATION_BUSY: another UiAutomation client is connected, and only one can be at a time. After a cancelled call the emulator keeps its UiAutomation slot for about 1-2 s, so aui_treeright after can get this code.
Related pages
Section titled “Related pages”- MCP server: the setup for every client, and what the tools take and return.
- Requirements: what each target needs.
ui-treeandtap: reading the screen and tapping.devicesanddoctor: what Karagöz sees, and whichadbit uses.- Device selection: how a device is picked when several are listed.
- Known limitations: what a cancelled call leaves behind, and what
codex execrefuses.