> ## Documentation Index
> Fetch the complete documentation index at: https://docs.leverine.com/llms.txt
> Use this file to discover all available pages before exploring further.

# For agents

> If you are an AI whose user runs BunnyBridge, this page is yours: the two tunnels, the connect block, the diagnosis, failure meanings, and the working rules.

If you are an AI — an API agent or a chatbot app — whose user runs BunnyBridge on their phone, this page is yours. It is the short form of the skill file that ships with the product.

## What you are being handed

BunnyBridge exposes a small authenticated command API on the user's phone. Through it you can run commands on the phone (within the Android app sandbox) — and, once the jump-host phase ships, on the user's other machines via hosts they configured. It is the user's phone and the user's bridge: you are a guest operator, and access is lent, not owned.

## Know which tunnel you are using

### Tunnel 1 — tailnet (API agents)

The bridge listens on the phone's Tailscale address (for example `http://<phone-tailnet-ip>:8765`). It is reachable only from inside the user's tailnet. If you can make HTTP requests and have a route to the tailnet, this is your tunnel.

### Tunnel 2 — public address (chatbot apps)

If you are a cloud chatbot, you **cannot** reach a tailnet address — do not try, and do not tell the user it should work. Your tunnel is the user's **public address**: an https address (their hosted-relay address, or their own front-door machine's address) where the `/door2/` surface lives. You reach it through:

* **Actions / OpenAPI:** the app generates an actions schema pre-filled with the public address; the user adds it to your configuration along with the token. The schema is also served at `<public-address>/door2/openapi.json`.
* **MCP:** a remote MCP endpoint at `<public-address>/door2/mcp`, with one tool, `run_command` (arguments: `cmd`, optional `timeout` in seconds).
* **Relay mode:** if you have no tool ability at all, use the copy-paste protocol in the last section of this page.

On Tunnel 2 your endpoints live under `/door2/`: `POST /door2/run`, `GET /door2/health`, `GET /door2/status` (a reduced status: version and your token's name only). Send your token as the `X-Token` header, or as a Bearer token if your connector works that way. A Tunnel 2 token works **only** on the `/door2/` surface — never on Tunnel 1 paths — and Tunnel 1 tokens never work here. Tunnel 2 is rate-limited: 30 calls per minute and at most 2 commands at once. A 429 means slow down, not retry harder.

**Do not** advise the user to "enable Tailscale Funnel on the phone." Android has no Tailscale CLI and its Tailscale app has no Funnel feature; that instruction sends the user to a switch that does not exist. If the user's Tunnel 2 address is unreachable, the front door (relay or their machine) is the problem — say that instead.

## The connect block

The user hands you a **connect block** from the app: the URL for your tunnel, a token made for you, and a link to this page. Rules for the token: treat it as a password. Never print it in full, never save it in code, logs, or files. Send it only as the `X-Token` header (Tunnel 1 / direct API) or as configured in your actions/MCP setup (Tunnel 2). If you have no connect block, ask the user to open BunnyBridge → Tokens → create one for your tunnel and paste you the block. Tokens are shown once, so if a block is lost, the fix is a fresh token — never ask the user to "look up" the old value; it cannot be displayed again.

## Read the diagnosis first

`GET /health` without a token is basic liveness. **With** your token it returns the full self-diagnosis — the same three lists the user sees on the Status screen. Check it before your first real command, and whenever something fails:

* `permissions_missing` — Android permissions not yet granted (battery exemption, notifications…).
* `software_missing` — for example Tailscale not installed. Verdicts are layered: a live tailnet address counts as Tailscale being up even when the app check cannot see the app, and each item's detail names which signal decided it. Termux, when found, is information, never a blocker.
* `state_missing` — for example Tailscale signed out or its VPN down, Tunnel 2 not set up, no hosts configured.

Each item carries a `fix` field: `"agent"` (resolvable through the API, or the app self-heals) or `"user"` with a short instruction. For a `"user"` fix, relay that one instruction exactly and wait. Never improvise around a system permission dialog or a Tailscale sign-in — those are the user's taps.

One more endpoint worth knowing: `GET /log` (Tunnel 1 only) returns the app's event log as plain text. When the user says something misbehaved, fetch `/log?session=current` first — it covers everything since their last "Start test session" marker, with diagnosis facts and stack traces. There is no log on Tunnel 2, by design.

## Helping a new user set up

One step at a time, waiting for confirmation after each:

1. The user installs **BunnyBridge** and **Tailscale**.
2. The user opens Tailscale and signs in with **their own** account, VPN on.
3. The user opens BunnyBridge — it self-diagnoses, starts the bridge, and generates a first token automatically.
4. The user creates a token for you under Tokens and pastes you the connect block. For Tunnel 2, the user also selects Your own front door in Chatbot Access (Status screen) and gives you the public address plus the generated actions schema or MCP endpoint.
5. You call `GET /health`, confirm the diagnosis is clear (or relay the one remaining user fix), run one harmless verification (`echo ok`), and show the user the result.

Never ask the user to install a terminal, type a shell command by hand, or fetch a token from anywhere except the app's Tokens screen.

## Failure meanings — do not guess

| Symptom | Meaning |
| - | - |
| Empty reply / connection refused | Nothing is listening — bridge stopped or Tailscale down. Ask the user to open the app; its Status screen says which. Don't retry in a loop. |
| `403` | Token wrong, revoked, on the wrong tunnel, or rotated past grace. Ask for a fresh connect block. |
| `403` "door 2 is off" | The app is in Mode 1 (relay) — the Tunnel 2 surface is off by the user's choice. Only the user can change it (Status → Chatbot Access → Your own front door). Don't ask for a Tunnel 1 token instead — it would not work on this surface anyway. |
| Public address unreachable | The relay connection or the user's front-door machine is down — not a phone problem and not an auth problem. Name it as such. |
| `429` | You hit Tunnel 2's rate limit (30 calls/minute) or its 2-command concurrency cap. Wait — the reply may carry `retry_after_s` — then continue. Repeated 429s mean you are looping; stop and summarise instead. |
| Command times out | The command outlived its timeout. Say so; never resend a destructive command whose outcome is unknown. |

## Working rules

* Start read-only. Look before changing anything.
* One command per call, and prefer one command that shows its work over a chain you can't verify.
* Confirm with the user before anything destructive, irreversible, or visible to other people (deleting files, restarting services, sending messages). Their bridge, their call.
* Report outputs faithfully: quote exit codes and errors as returned; never summarise a failure as a success.
* If the user revokes your token or stops the bridge, stop. Access is lent, not owned.

### What you cannot do

* Reach Tunnel 1 from the public internet — it doesn't listen there. No route to the tailnet means Tunnel 2 or relay, or no connection.
* Grant yourself permissions, install software on the phone, or sign the user into Tailscale. Your job is to name the exact next tap.
* See the user's other tokens, SSH keys, or stored secrets. `/status` shows names only, by design.
* Manage tokens over HTTP. Creation, rotation, and revocation happen only in the app, by the owner.

## Relay mode protocol

If you have no tool ability at all, emit exactly one command per reply in this fenced format and ask the user to paste it into the app's Agent Inbox:

````
```bunnybridge
{"cmd": "...", "host": "optional-host-name"}
```
````

The user pastes your block into the Agent Inbox and taps Run on the queued command — pasting alone runs nothing, and the user can dismiss your command instead. After it runs, the app shows the result as a fenced block for the user to paste back to you:

````
```bunnybridge-result
{"cmd": "...", "exit_code": 0, "stdout": "...",
 "stderr": "...", "duration_ms": 0}
```
````

Continue from what they paste; never claim a relay command ran until you have seen its result block. The full endpoint reference — shapes, errors, limits — is the [API Reference](https://docs.leverine.com/bunnybridge/api-reference.md).

***

*Source: Leverine/Leverine-BunnyBridge\@902c77c — `docs/site/BunnyBridge/for-agents.html`.*


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.