# Connect Android Backstage

Goal: register Android Backstage as a remote MCP server in this assistant, guide the user through approving on their phone, and verify the connection.

- **MCP server (Streamable HTTP, OAuth):** `https://relay.android-backstage.com/work/mcp`
- **Account & device management:** `https://relay.android-backstage.com/work/account`
- **Android app:** `https://android-backstage.com/downloads/android-backstage-2.0.7.apk`
- **Plugin package:** `https://android-backstage.com/downloads/android-backstage-plugin.zip` (verify SHA-256 in `https://android-backstage.com/downloads/SHA256SUMS.txt`)
- **CLI connector fallback (Node 22+):** `https://relay.android-backstage.com/work/connect/agent.mjs`

## 1. Check for an existing connection
If an `android-backstage` MCP server is already registered and responds to `android_devices`, reuse it and go straight to step 4. Preserve other MCP servers and settings. Never delete an older local Backstage link until the new connection works.

## 2. Register the server for this client
Use user/personal scope so the connection works across all projects:

| Client | How to configure | Start sign-in |
| --- | --- | --- |
| **Claude Code** | `claude mcp add --transport http --scope user android-backstage https://relay.android-backstage.com/work/mcp` | Run `/mcp` → choose `android-backstage` |
| **Codex** | `codex mcp add android-backstage --url https://relay.android-backstage.com/work/mcp` (or add `[mcp_servers.android-backstage]` in `~/.codex/config.toml`) | Run `codex mcp login android-backstage` |
| **Antigravity** | Add HTTP MCP server `android-backstage` with URL `https://relay.android-backstage.com/work/mcp` (or use `agent.mjs --host antigravity` below) | Approve on phone |
| **Grok Build** | Add HTTP MCP server `android-backstage` with URL `https://relay.android-backstage.com/work/mcp` (or use `agent.mjs --host grok` below) | Approve on phone |
| **Cursor** | Merge `mcpServers["android-backstage"] = { "url": "https://relay.android-backstage.com/work/mcp" }` in `~/.cursor/mcp.json` | Enable & click **Connect** |
| **Cursor Cloud** | Add personal HTTP MCP server at `https://cursor.com/agents` | Click **Connect** |
| **VS Code / Copilot** | Merge `servers["android-backstage"] = { "type": "http", "url": "https://relay.android-backstage.com/work/mcp" }` in user MCP config | Run `MCP: List Servers` → Start |
| **Gemini CLI** | `gemini mcp add --transport http android-backstage https://relay.android-backstage.com/work/mcp` | Run `/mcp auth android-backstage` |
| **OpenCode** | Merge `mcp["android-backstage"] = { "type": "remote", "url": "https://relay.android-backstage.com/work/mcp", "enabled": true }` in `~/.config/opencode/opencode.json` | Run `opencode mcp auth android-backstage` |
| **Claude (Web/Desktop)** | **Settings → Connectors → Add custom connector** with the MCP URL above | Click **Connect** |
| **ChatGPT** | **Plugins → + → Custom MCP server** with the MCP URL above (enable Developer mode if prompted) | Click **Connect** |
| **Any other MCP client** | Register `https://relay.android-backstage.com/work/mcp` as a Streamable HTTP MCP server with OAuth | Run host's OAuth sign-in |

## 3. Approve on the phone
When sign-in opens a Backstage page, tell the user:
> Enter your Backstage email, tap **Send to my phone**, verify the 6 check digits match, and tap **Allow**.

If this host cannot edit its own settings (e.g., ChatGPT or Claude web), give the user the exact steps and MCP URL for this app and stop.

### Fallback when browser OAuth is unavailable (SSH / WSL / headless CLI, Node 22+)
1. Download `https://relay.android-backstage.com/work/connect/agent.mjs` to a private local folder.
2. Run `node agent.mjs connect --name "AGENT NAME" --host HOST` where `HOST` is one of `claude-code`, `codex`, `cursor`, `grok`, `opencode`, `gemini`, `antigravity` (or `--all` to wire every detected local client).
3. Show the user the 6 check digits so they can tap **Allow** on their phone. If installation fails after approval, keep the saved account file and run `node agent.mjs install --host HOST --account FILE`.

## 4. Verify without disturbing the screen
Reload tools if needed, then call `android_devices` with `detail: "debug"`. Report the returned phone model and stop. Do not open apps, read personal content, or touch the physical screen during setup.

## Rules
- Never approve on the phone for the user.
- Never print, copy, or ask for passwords, tokens, or link keys.
- If the phone is offline or paused, ask the user to open Android Backstage and tap **Start** or **Resume**; do not reset pairing.
- Detailed tool usage rules (private displays, `android_confirm`, multi-device selection, and file artifacts) are supplied directly by the MCP server instructions once connected.
