Skip to content
karagöz docs
Star4npm0.5.1

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.

  • Node 22 or newer.
  • adb from 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.

~/app
claude mcp add karagoz -- npx -y karagoz-mcp mcp

The 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.

~/app
karagoz devices
Found 1 device:
Medium_Phone_API_37.0 • emulator-5554 • emulator • Android 17 (API 37) • device
Missing a device? Run karagoz doctor.exit 0

Without 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.

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.

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.

  • ui_tree returns 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.
  • tap with text or id finds one node in the tree and taps its center.
  • screenshot writes a full-resolution PNG to disk and returns its path, with its pixel size, logical size, scale and safe area. With inline: true it also returns the image, which the client scales before the model sees it. So coordinates come from the tree’s bounds, 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.

Codex was run against this server too. Register it:

~/app
codex mcp add karagoz -- npx -y karagoz-mcp mcp

Then 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.

~/.codex/config.toml
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_vars forwards the ones Karagöz reads.
  • tool_timeout_sec covers long tap waits and big installs.
  • install and uninstall ask for approval. codex exec never asks, so it refuses them with MCP 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.

  • ADB_NOT_FOUND: no adb found. doctor shows where Karagöz looked and which adb it uses. Install platform-tools, or set ANDROID_HOME to your Android SDK. With Codex, env_vars forwards ANDROID_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 needs device, or KARAGOZ_DEVICE set in the shell you start claude from.
  • 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 a ui_tree right after can get this code.