# xhostd — Agent cheat-sheet API: `https://api.xhostd.com` (override via `XHOSTD_API_URL`) OpenAPI: https://docs.xhostd.com/openapi.json Auth: `Authorization: Bearer $XHOSTD_TOKEN` on every authed call. Tokens start with `xh_`. Send the header on curl's stdin, `printf 'Authorization: Bearer %s\n' "$XHOSTD_TOKEN" | curl --header @- ...`, and to git from its environment, `GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.https://git.xhostd.com/.extraHeader GIT_CONFIG_VALUE_0="Authorization: Bearer $XHOSTD_TOKEN" git ...` (git 2.31 or later): any local user reads a process's argv with `ps`, and neither form puts the token there. With the header on stdin, a request body comes from an argument or a file, never from stdin. Errors: `{"error":{"code":"...","message":"..."}}` — surface `message` to the user. ## Mental model - **App** owns a git repo (`https://git.xhostd.com//.git`) and one or more channels. - **Channel** binds to a git ref and exposes a hostname. - **Deploy** is two-step: `git push` stores code; `POST .../deploy` builds and ships it. Pushing alone does nothing. - Hostnames: `-.xhostd.app` for prod; `--.xhostd.app` otherwise. - DNS labels everywhere: `^[a-z0-9]([a-z0-9-]*[a-z0-9])?$`, ≤40 chars. Reserved app prefixes: `git api www admin preview staging`. Reserved channel name: `prod` (auto-created). ## Worked recipes Each recipe deploys one shape of app. It gives every file in full and the exact call sequence with the real responses. It also gives the log excerpt that proves the result, and the failure modes of that shape. Read the recipe for your shape **before** you write the code. - https://docs.xhostd.com/guides — index - https://docs.xhostd.com/guides/projects-and-channels — Projects & channels: Project scope, channel isolation, and shared account capacity. - https://docs.xhostd.com/guides/deployments — Deployments: Push a revision, review a deployment, and distinguish results from serving state. - https://docs.xhostd.com/guides/data-and-recovery — Data & recovery: Postgres, files, recovery points, exports, and restore safeguards. - https://docs.xhostd.com/guides/access-and-security — Access & security: Membership, credentials, protected agent actions, and app sign-in. - https://docs.xhostd.com/guides/troubleshooting — Troubleshooting: Find build, runtime, traffic, and resource evidence. - https://docs.xhostd.com/guides/git — push code with git: the credential, the remote URL, the `HEAD:master` refspec - https://docs.xhostd.com/guides/register-as-agent — register as an agent: the SSH key, the signed message, `POST /registrations`, the 30-day token, `POST /auth/ssh-key` to renew, and an email that opens the console to a person - https://docs.xhostd.com/guides/recipes-static — static site, no build step - https://docs.xhostd.com/guides/recipes-app-node — `app` template, Node 22 + Express - https://docs.xhostd.com/guides/recipes-app-python — `app` template, FastAPI + uvicorn - https://docs.xhostd.com/guides/recipes-docker — your own Dockerfile - https://docs.xhostd.com/guides/recipes-postgres — `DATABASE_URL`, migrations, snapshots - https://docs.xhostd.com/guides/recipes-blob — object storage via the injected `S3_*` env - https://docs.xhostd.com/guides/recipes-oauth — how to verify the `__Host-xhost_id` cookie - https://docs.xhostd.com/guides/recipes-port-forwarding — a public `host:port` for raw TCP - https://docs.xhostd.com/guides/recipes-worker — a background worker that serves no HTTP, readiness by `$XHOSTD_READY_FILE` - https://docs.xhostd.com/guides/recipes-commit-files — `commit_files`, for a runtime with no shell - https://docs.xhostd.com/guides/bkm — working methods: how to debug, stacks, budgets, the undo path - https://docs.xhostd.com/guides/diagnose-slowness — diagnose a slow app: `get_app_health`, read `findings` first, obey `action` - https://docs.xhostd.com/guides/client-blocked-deploy — when the client itself refuses `deploy` before it reaches xhostd: how to recognize it, and what the user changes ## Templates **Two ways to signal readiness.** Every non-`static` deploy is marked ready on whichever of these arrives first inside the time window: (1) the app answers `GET /` with a 2xx or 3xx on `$XHOSTD_HTTP_PORT` (the request carries the channel's hostname as its `Host` header, and a redirect is never followed; `$PORT` holds the same value for apps that read it, and new code reads `$XHOSTD_HTTP_PORT`), or (2) the app creates the file whose path is in the injected `$XHOSTD_READY_FILE`. Signal (2) exists so a channel with no HTTP surface — a queue consumer, a cron-style daemon, a stream processor — needs no dummy HTTP listener; the file can be empty, only its existence is checked, it sits directly under `/tmp` so neither `mkdir` nor a shell is required (a distroless image can just `open()` it), and its path is minted fresh per deploy so it can never be baked into an image. Create it once the app is genuinely doing its work (the consumer loop is subscribed and running), never as the first line of the start command. A channel that passes on the file keeps its hostname and route; that URL simply returns 502, which is expected. `XHOSTD_READY_FILE` is a **reserved env key** (`set_env` rejects it). - `static` — serves the committed files from the repo root (put `index.html` at the root; it answers `/`). Default. - `app` — a per-deploy image is built from your repo on a Node 22 / Python 3.13 runtime: `install.sh` (optional) runs at **build** time and its output (`node_modules`, virtualenvs, …) is baked into the image, then `launch.sh` (required) starts your process. A server must bind `0.0.0.0:$XHOSTD_HTTP_PORT` (read it from the environment; don't hardcode) and return a 2xx or 3xx at `GET /` within 120s — a 4xx or 5xx (incl. an API with no `/` route) or nothing listening fails the deploy unless the app used the `$XHOSTD_READY_FILE` signal instead (above). Because `install.sh` now runs during the build (with build headroom, not under the app's current runtime memory allowance), heavy installs no longer OOM; that runtime budget applies to the running server. `install.sh` runs as **root**, so system-wide installs (`uv pip install --system`, `npm install -g`, `apt-get`) belong there — for Python, use `uv` to install packages (it is preinstalled in the base). `launch.sh` runs at boot as the **non-root `app` user** (uid 10001, all Linux capabilities dropped); its writable paths are `/app`, `$HOME` and `/tmp`, so never install or write outside them at launch — an install in `launch.sh` fails with `Permission denied`. Charged image size follows the current account entitlement exactly like `docker` (below); the Node/Python runtime base is a warm base, exempt from the charge, so only your code + dependencies count. - `docker` — the repo has a `Dockerfile` at its root; xhostd builds it on every deploy and runs the image with pure Docker semantics (your image's own `ENTRYPOINT`/`CMD` runs — no `install.sh`/`launch.sh`). Contract: bind `0.0.0.0:$XHOSTD_HTTP_PORT` (injected) and return a 2xx or 3xx at `GET /`, or create `$XHOSTD_READY_FILE` if the image has no HTTP surface (same health check as `app`); env vars are injected at run time only, NEVER as build args — secrets are unavailable during the build and must never be baked into an image; run migrations in the start command, e.g. `CMD ["sh","-c","alembic upgrade head && exec uvicorn app:app --host 0.0.0.0 --port $XHOSTD_HTTP_PORT"]`. Charged image size (total minus warm-base layers) follows the current account entitlement; call `get_stats(view="overview")` for the current cap. Match EVERY `FROM` to a warm base — including a build-only stage in a multi-stage build, since every stage that names one starts with no pull: `node:22-slim`, `node:24-slim`, `node:26-slim`, `python:3.11-slim`, `python:3.12-slim`, `python:3.13-slim`, `python:3.14-slim`, `debian:trixie-slim`. The final stage's warm-base layers are also exempt from the charged size. The deploy log streams `[build] ...` lines (queue position, build duration, size/cap result). ## Endpoints **Auth & accounts** - MCP clients with a person present (Claude Code, claude.ai): OAuth — no token. An agent with no person present registers itself: `POST /registrations` (no auth; `ssh-ed25519` public key + SSHSIG over `xhostd-register\n\n\n`, namespace `xhostd-register`) → `{user_id, username, plan, token, token_expires_at, ssh_key_id, fingerprint_sha256, git_ssh_host, limits, next}`; 409 key registered already (sign in instead), 429 budget, 503 closed. `POST /auth/ssh-key` (no auth; SSHSIG over `xhostd-login\n\n\n`, namespace `xhostd-login`) → `{token, token_expires_at, user_id, username}`, 404 for a key without `api_login`. `POST /ssh-keys` takes `api_login` (default false) and the key list shows it; `api_login: true` needs all nine default scopes plus either a verified address on the account or an `email:bind` token, and answers 409 otherwise, so an agent registers a replacement login key with the token these two routes answer. Guide: https://docs.xhostd.com/guides/register-as-agent - `POST /me/email-verifications` `{email}` → `{status:"sent", expires_at}` (403 without the `email:bind` scope, which only `POST /registrations` and `POST /auth/ssh-key` grant — sign in with the key again for a token that can bind, because no other request sequence reaches the scope; 409 verified already, 429 inside 60 s or past the address caps of 3 links an hour and 9 in all); the platform mails the address a link that works once for 60 minutes, and the person who reads the mail opens it and presses Confirm in the console, which binds the address, applies the post-verification entitlement, and opens console sign-in to the address. `GET /me/email-verifications` → `{status, expires_at, plan}` with `status` one of `verified`, `pending`, `expired`, `conflict` (the address belongs to another account), or `none`; call it once after the person says they confirmed, never in a loop. `POST /me/email-verifications/complete` is retired and answers 410. An account whose email nobody confirms may be deleted after 7 days. No MCP tool binds an email: only a token from `POST /registrations` or `POST /auth/ssh-key` can, and an agent that holds one calls these two routes itself. - Tokens (for git remotes, curl, CI): mint at `https://console.xhostd.com/tokens?label=` (shown once). Use as `Authorization: Bearer xh_…`. On 401, ask the user to re-mint at the same URL. - `POST /credentials` (bearer auth) → `{token, username, expires_at, scopes}` — a unified credential (git password + Postgres password + object-storage and download credential + platform API bearer) carrying the default scopes your calling token holds, all nine for a general credential, and living 30 days or until your calling token expires, whichever comes first; accepts an optional `scopes` subset and an optional `expires_in` in seconds (at most 2592000, and at most what your calling token has left), which compose. A mint never grants more scope, and never a longer life, than the caller holds, so a narrowed token renews itself here rather than widening, a short-lived one cannot outlive itself, and `POST /tokens` — whose grant is the fixed nine — answers 403 `scope_denied` to a token short of that set. `POST /ssh-keys` needs `repo:*`, and each download-token route needs the one scope it mints. In an MCP session, the `get_credential_request` tool describes this request and never runs it: run it yourself with your own token from `$XHOSTD_TOKEN`, and keep the minted token in a variable of its own (see MCP section). **Apps & channels** - `GET /apps` → `{apps: [...]}` - `POST /apps` `{name, template?, branch?}` → app w/ auto-created `prod` channel. `prod` has no branch (`git_ref_binding: null`) unless `branch` names one; the first deploy with `ref` binds it. Total channels follow the current account entitlement; each app consumes one slot for its `prod` channel, and every extra channel consumes another. Call `get_stats(view="overview")` for this account's limit and headroom. - `GET|DELETE /apps/{id}` - `GET /apps/{id}/channels` - `POST /apps/{id}/channels` `{name, git_ref_binding}` where binding is `branch:` (one channel per branch; the legacy `branch:*` wildcard is deprecated and rejected at create time) - `GET|DELETE /apps/{id}/channels/{cid}` (cannot delete `prod`) - `PATCH /apps/{id}/channels/{cid}` `{git_ref_binding?: "branch:", follows_branch?: bool}` — rebind a channel without deploying, make it follow its branch, or both; a body with both applies the binding first (needs `channel:*`; MCP `update_channel`). The branch does not have to exist yet. `null` answers 400 for either field: a channel cannot be unbound. Refused bindings: `branch:*`, names under `xhost/`, and `HEAD`. `follows_branch: true` makes each push to the channel's branch on the connected source repository deploy the new head; it needs `deploy:*` as well (403 without), a connected source repository (409 "connect a source repository first"), and a bound branch (409 "bind a branch first"). `false` is always accepted. Channel payloads carry `follows_branch`. **Deploy** - `POST /apps/{id}/channels/{cid}/deploy` `{sha?, ref?}` — `ref` is a branch name (bare `main` or `refs/heads/main`): xhostd deploys that branch's current HEAD and binds the channel to it. `sha` (40-char hex, or a branch name) deploys once and never changes the binding; both means `sha` wins and `ref` is ignored. Neither deploys the HEAD of the channel's bound branch; an unbound channel answers 400 `channel_unbound`, and a bound branch missing from the repo answers 404, each naming the fix and the source repository's default branch when known. On an app with a connected source repository, a 503 means another write (a push, a changeset, or another sync) holds the repo, or the app is under maintenance; retry. Returns `{deploy_id, channel_id, status, joined}`. `joined` is true when a deploy of the same commit, queued by a deploy request or by a push to the connected source repository, is already waiting for this channel. `deploy_id` names that deploy, and no second deploy was queued. It reads the current env when it starts, so poll it as usual. - `GET /apps/{id}/channels/{cid}/logs?deploy={did}` → `text/plain` — the build/boot log of one deploy. - `POST /apps/{id}/channels/{cid}/runtime/log` → the RUNNING app's stdout/stderr, i.e. everything after the deploy window. The log is materialized as `/log/app.log` (one line per output line, RFC3339 timestamp prefix, stdout+stderr merged) inside a throwaway, network-less container with cwd `/log`, and the `command` you send runs there — any shell pipeline, e.g. `"tail -n 200 app.log"` or `"grep -i error app.log | tail -20"`. Debian userland: `sh`, `bash`, `grep`, `sed`, `awk`, `tail`, `head`, `cut`, `tr`, `sort`, `uniq`, `wc`, `find`, `xargs`, `python3`, `node`, `perl` — no `jq`, `rg` or `less`. Body: `command` (optional, ≤4096 chars — **omit it** and no container is started, you get the status header alone), `container_index`. Returns `output` (the command's combined stdout+stderr, ~256 KiB cap → `truncated`), `command_exit_code`, `timed_out` (30 s limit; partial output still returned), `log_bytes` (size of the whole log your command saw) plus the crash facts: `status`, `exit_code` (**your app's**, not the command's), `oom_killed` (true = your app exceeded its plan's memory limit), `restart_count`, `started_at`/`finished_at`, and `available_indices`. **The log survives a redeploy**: when a new version replaces a container the old container's log is archived, so pass an older `container_index` to read why the previous version crashed. Only stdout/stderr is captured — an app that writes its logs to a file inside the container has nothing here. `source` is `live` (the container on its host), `archive` (the log the host kept when a redeploy replaced the container), or `central`: the platform also keeps each container's output in a central log store, for the retention period that the account's plan sets, and the reply comes from it when the container's host doesn't answer or no longer holds the container (for example after a move). A central reply never shows a running container; its `status` is `unknown` when the platform has no record of how the container ended, and `exit_code`, `oom_killed`, `restart_count`, `finished_at` are then null. A `command` on a central reply runs on the newest 200,000 lines or 64 MiB of the container's log: `truncated_head` is true when the read left out older lines, false when the command saw the whole log, and null on every other reply. 404 = nothing readable for that channel yet; 503 = the host can't answer right now. The central path adds 503s: "runtime log and central store unavailable" or "this host no longer holds that container, and the central log store is unavailable" (the store can't answer either), "central log reader busy, retry shortly" (too many central command reads at once), and "no host can read this log right now; retry shortly" (no host can run the command) — retry all of them later. - `GET /apps/{id}/channels/{cid}/images` → `{images, image_cap_bytes}` — built-image inventory for docker channels, newest first: per image `{tag, sha, size_bytes, charged_size_bytes, matched_base, created, current}`; `images` is `null` (not an error) when the host agent is unreachable. **Env** - `POST /apps/{id}/env` `{key, value, kind?, channel_id?}` — key must match `^[A-Z_][A-Z0-9_]*$`. `value` is capped at 16 KiB of UTF-8, per value (not per app). `kind` is `env` (plain var) or `secret`; omitted, an existing key keeps its kind and a new key defaults to `env`; `kind=secret` turns a plain var into a secret, and `kind=env` over a secret answers 409 (a secret never turns plain in place: delete it first); `channel_id` makes it a per-channel override (channel wins over the app-level default at deploy time). Reserved: `XHOSTD_USER`, `XHOSTD_SHA`, `XHOSTD_HTTP_PORT`, `XHOSTD_FORWARD_PORT`, `XHOSTD_READY_FILE`, `XHOSTD_HOSTNAME`, `XHOSTD_URL`, `XHOSTD_DOMAINS`, `XHOST_USER`, `XHOST_SHA`, `XHOST_HTTP_PORT`, `PORT`, `XHOST_FORWARD_PORT`, `XHOST_READY_FILE`, `DATABASE_URL`, `DATABASE_URL_READONLY`, `DATABASE_URL_DIRECT`, `DATABASE_HOST`, `DATABASE_PASSWORD`, `S3_ENDPOINT`, `S3_BUCKET`, `S3_ACCESS_KEY_ID`, `S3_SECRET_ACCESS_KEY`, `S3_REGION`. Every other key that starts with `XHOSTD_` is reserved too. - `PUT /apps/{id}/env/{key}?kind=secret&channel_id=` — stores the raw request body as the value, byte for byte (a trailing newline included), so a secret goes from a file straight to xhostd: `printf 'Authorization: Bearer %s\n' "$XHOSTD_TOKEN" | curl -sS --fail-with-body -X PUT --header @- -H "Content-Type: application/octet-stream" --data-binary @ ""`. `kind` defaults to `secret`. The body is at most 16 KiB of UTF-8 and never empty; a form or JSON `Content-Type` answers 400. Answers 204 with no body. - `POST /apps/{id}/env/{key}/generate?channel_id=` — stores a new random secret (43 URL-safe characters, 256 bits) under a NEW key and answers 204 with no body; a key that already has a value there answers 409 (delete it first to rotate). Read the value with the console's audited reveal. - `DELETE /apps/{id}/env/{key}?channel_id=` — with `channel_id`, deletes only that channel's override. A secret is a kind of env var, so this deletes a secret too. - Every container, `static` included, gets the channel's hostnames: `XHOSTD_HOSTNAME` (the platform hostname, which the deploy probe sends as `Host`), `XHOSTD_URL` (`https://` plus that hostname, no trailing slash, never a custom domain), and `XHOSTD_DOMAINS` (that hostname and the verified custom domains, comma-separated with no spaces). Build a host allowlist from `XHOSTD_DOMAINS`, for example Django's `ALLOWED_HOSTS = os.environ.get("XHOSTD_DOMAINS", "localhost").split(",")`. Treat `XHOSTD_DOMAINS` as a set: don't infer a primary domain from its position, and read the platform hostname from `XHOSTD_HOSTNAME` or `XHOSTD_URL`. The values are fixed at container create, so deploy again after you verify or remove a custom domain. - `GET /apps/{id}/env?channel_id=` — lists entries; with `channel_id`, the resolved view for that channel (`scope` = `app` or `channel`). The web console reads this view too, and edits env from it. Plain values are returned in cleartext; secret entries carry metadata only (`value: null`) in list responses. - `GET /apps/{id}/env/{key}/value?channel_id=` → `{key, kind, scope, value}` — reveals one value, the only read path for secrets (requires the `deploy:*` scope; every reveal is audit-logged as `env.reveal`). With `channel_id`, resolved semantics (channel override wins, app-level fallback); without, the app-level row. The web console's click-to-reveal uses this same endpoint. MCP has NO reveal tool — secrets stay write-only in MCP sessions. This route is a **protected action** — it answers `protected_action` to an agent credential, and the account or project **agent access** switch opens it. - `GET /apps/{id}/channels/{cid}/deploys/{did}/env` — the env snapshot a past deploy ran with: plain values, secrets masked, system-injected keys listed by name only. - MCP: `set_env(app_name, key, value, channel=None)`, `set_secret(app_name, key, channel=None, generate=False)`, `delete_env(app_name, key, channel=None)`, `list_env(app_name, channel=None, deploy_id=None)` — with `channel` and `deploy_id`, `list_env` returns the env snapshot that deploy ran with. `app_name` is the app *name* (a UUID also works) and `channel` is the channel *name* (e.g. `prod`). - **A secret's value never passes through a tool call.** `set_env` stores plain values only, and warns when the key reads like a credential (`*_KEY`, `*_SECRET`, `*_TOKEN`, `PASSWORD`, `PASSWD`). `set_secret` takes no value: it returns the `PUT` request above with its `url`, which you run from your shell with the value in a file, and a `console_url` that opens the console's add form with the key filled in and "Store as a secret" checked, for a client with no shell. `set_secret(generate=True)` makes xhostd store a random value and returns no value. A secret is a kind of env var: `list_env` lists it with a null value, `delete_env` deletes it, channel overrides apply the same way, and the app reads it at its next deploy. To upload a one-line value without its trailing newline, hand curl the value as a file with a bash or zsh process substitution, since stdin carries the header: `--data-binary @<(printf '%s' "$VALUE")`, or from a `.env` file `--data-binary @<(grep -m1 '^KEY=' .env | cut -d= -f2- | tr -d '\n')` (it keeps the quotes of a quoted value and misses an `export KEY=` line, so strip both first). **SQL database** - Every non-static channel automatically gets its own Postgres database, with `DATABASE_URL` injected at deploy time, and `DATABASE_URL_READONLY` beside it — a second role that can `SELECT` from every table in `public` by default and run no write, for a query surface exposed to visitors; writes use `DATABASE_URL`, and data the read-only role must not see goes in a schema the app creates (`CREATE SCHEMA private`) or stays in `public` behind the app's own `REVOKE SELECT ON public. FROM `, which stays revoked. Tables live in that database's stock `public` schema, so user code writes unqualified table names and a plain `pg_dump`/`pg_restore` round-trip lands where the app reads — read the connection string from `DATABASE_URL` rather than constructing it. A static-template channel gets no database, no role, and no `DATABASE_URL`, because a static site serves files and never queries Postgres. - `DATABASE_URL` and `DATABASE_URL_READONLY` can go through a transaction pooler (PgBouncer, port 6432), which lends a server session for one transaction at a time; `DATABASE_URL_DIRECT` always reaches the database server itself (port 5432). Session state breaks through the pooler: a session `SET` of a setting the pooler does not track, such as `statement_timeout`, a session advisory lock, `LISTEN` (`NOTIFY` works), a temporary table that outlives its transaction, a `WITH HOLD` cursor, Django server-side cursors, and SQL `PREPARE`. The pooler refuses at connect a startup parameter it does not track, such as `-c statement_timeout=...` in `options` or asyncpg `server_settings`; full list: https://docs.xhostd.com/guides/recipes-postgres#what-a-transaction-pooler-changes. Run migrations and listeners over `DATABASE_URL_DIRECT`, falling back to `DATABASE_URL`; Prisma sets `directUrl = env("DATABASE_URL_DIRECT")`. Where a database has no pooler the two URLs are equal. Use `DATABASE_URL` for the app's traffic on every plan: through the pooler, many client connections share a few server sessions, each in use only while a transaction runs, while each `DATABASE_URL_DIRECT` connection holds a server session even when idle and counts against the role's cap and the server's total; keep `DATABASE_URL_DIRECT` for the few connections that need a session feature. Limits with a pooler, by plan: write role 15 server sessions (5 of them through the pooler) and read-only role 5 on other plans, 20 (10) and 10 on Studio, 40 (20) and 20 on Pro; 100 client connections per role to the pooler. On Studio and Pro, all of the account's apps and channels share about 180 server sessions on their own server: its `max_connections` of 200, less the sessions Postgres and the platform keep for themselves. - Schema migrations are 100% user-managed and must run at deploy time, where `DATABASE_URL` and `DATABASE_URL_DIRECT` are set: put `alembic upgrade head` / `prisma migrate deploy` / `drizzle-kit migrate` in `launch.sh` (`app` template) or the start command / `CMD` (`docker`). Do NOT put them in `install.sh` — it runs at build time with no env or DB access. - Per-channel inspection: `GET /apps/{id}/channels/{cid}/postgres` → `{db_name, role_name, status, connection_count, storage_bytes, password_set}`. - Wipe a channel's data: `POST /apps/{id}/channels/{cid}/postgres/reset {confirm_db_name}` — destructive: empties the channel's database, all data lost; role and password preserved so `DATABASE_URL` keeps working. Meant for deliberate, human-approved action. - Download a SQL dump: `GET /apps/{id}/channels/{cid}/postgres/dump` → `application/sql` stream (the channel's database, nothing else). - Per-user rollup: `GET /me/postgres/storage` → `{database_size_bytes, database_count}`. - Isolation: cross-user and cross-channel are both the DB boundary (Postgres rejects the connect). Channels share no namespace. Backups: one `nightly` snapshot per channel per day, retained according to the current account entitlement (the newest is always kept, at any age), plus the `pre_deploy` snapshot taken before each deploy. Call `get_stats(view="overview")` for the current retention values. A static-template channel gets neither kind — a static channel has no database. List both with `list_channel_snapshots`. `get_snapshot_download_link(app_name, channel, snapshot_id, part="database")` returns the download link for one snapshot (fetch it with your own token). `restore_channel_snapshot(..., part="database")` / `POST .../postgres/restore` starts a background restore and answers at once with its `restore_id`; poll `get_restore_status(restore_id)` / `GET /postgres/restores/{restore_id}` and relay its `activity` sentence. A restore can take up to an hour; for databases under 10 GB it typically takes minutes. `during_restore` picks what the app does meanwhile: `read_only` (the default: the app is served and its database writes fail), `maintenance` (a maintenance page replaces the app, and its writes fail; xhostd's page answers 503, so uptime monitors report the app as down), or `live` (the app keeps writing, and the restore discards those writes). In every mode, a write made while the restore still waits to start is discarded. For the user's own page, deploy a static app of the same owner, then pass `maintenance_app` and `maintenance_channel` (MCP) or `maintenance_channel_id` (API) with `during_restore="maintenance"`; that site answers with its own status codes. The start cancels the channel's queued deploys (`cancelled_deploys`), and a deploy answers `restore_in_flight` (409) until the restore ends. Each `list_channel_snapshots` row carries `restores`, the restores from it in the last 30 days. - External access (opt-in, default-closed): enable **per project (per app)** via the console Project settings toggle — the toggle is a **protected action** and has no MCP tool: it answers `protected_action` to an agent credential, and the account or project **agent access** switch opens it (the flag is app-wide). Once on, **every channel** of the app is reachable; connect external tools directly: `PGPASSWORD="$XHOSTD_TOKEN" psql "postgresql://@db.{domain}:5432/-?sslmode=require"` (for the `prod` channel, the database name elides to just ``). The password is your existing xhostd token, read from the environment so its value never appears in the command — no separate secret. Revoking the token or disabling the toggle cuts access immediately for all channels. **Object storage (S3-compatible)** - Auto-provisioned per channel (like SQL on a non-static channel) — no enable step. Use the MCP `get_credential_request(purpose="object_storage", app_name, channel)` for the request that returns the endpoint/bucket/key pair (run it with your own token from `$XHOSTD_TOKEN`; the tool result never holds the key pair) and `get_stats(view="object_storage", app_name, channel)` for bytes used. HTTP: `POST .../blob/credentials`, `GET .../blob`. - Deploys inject `S3_ENDPOINT`, `S3_BUCKET` (per-channel virtual bucket), `S3_ACCESS_KEY_ID`, `S3_SECRET_ACCESS_KEY`, `S3_REGION` (`us-east-1`, neutral). Point any S3 SDK at these and **always read them from env — never construct them**: in-container `S3_ENDPOINT` is a platform-internal address, not a public URL, and it is not the endpoint the credentials call returns. The upstream provider is proxied and hidden. - From **outside** the container, use the channel's public blob endpoint — the `endpoint` field `POST .../blob/credentials` returns (the request `get_credential_request(purpose="object_storage")` describes), `https://{channel-hostname-label}.s3.{domain}`, one per channel. - Bucket-wide object versioning is always on. Isolation is enforced at the gateway: a channel's key can only address its own key prefix; the gateway routes by key and compares the client bucket segment with the channel's own name (any other name → `404` `NoSuchBucket`), so cross-channel/cross-user access is denied. Per-user byte quota is metered at the gateway (over quota → `507`). - Snapshots: every deploy of a non-static app writes a timestamp marker + snapshot row (`pre_deploy`), and the nightly pass writes one per channel per day (`nightly`, same plan window as the DB kind); a static-template channel gets neither kind; restore walks each object back to the version current at that timestamp (copy-forward, never rewind). - Snapshot **restore** rolls the store back with `restore_channel_snapshot(app_name, channel, snapshot_id, part="files")` (MCP) or `POST .../blob/restore {confirm_channel_name, snapshot_id}`, where `snapshot_id` is the checkpoint id from `list_channel_snapshots` whose `aligned_blob` flag is true (prod is a protected action: 403 `protected_action` to an agent credential until the app owner turns agent access on; refused mid-deploy with `channel_busy`, for a checkpoint with no aligned blob leg with `no_aligned_blob_snapshot`, or past the retention window). The **external-access** toggle is a **protected action** — it answers `protected_action` to an agent credential, and the account or project **agent access** switch opens it (app-wide; once on, connect `aws --endpoint-url s3 ...` with the channel's S3 key pair from `POST .../blob/credentials`). `get_snapshot_download_link(..., part="files")` returns the download link for a checkpoint's files as a `.tar.gz`. **Custom domains** - Attach up to 5 custom domains per channel. Domains are globally unique across xhostd. - `POST /apps/{id}/channels/{cid}/domains` `{domain}` → 201 `{domain, status:"pending", reason:null, dns_records:{txt_host, txt_value, cname_target, a_values}, created_at, verified_at:null}`. Idempotent for the same channel (re-POST returns the existing row); 409 `domain_taken` if another channel owns it; 400 `domain_limit_reached` at 5; 400 `invalid domain: ` for malformed input (reasons: `is_ip_address`, `invalid_idna`, `too_long`, `invalid_label`, `platform_domain_forbidden`, `needs_dot`). - User then creates two DNS records: `TXT _xhost.` with the returned `txt_value`, plus a routing record — `CNAME ` → `cname_target` for subdomains, or `A ` → one of `a_values` for an apex. - `POST /apps/{id}/channels/{cid}/domains/{domain}/verify` → re-checks DNS, idempotent + retryable. Status flips `pending → verified` on a passing check. Closed reason set: `txt_nxdomain`, `txt_token_mismatch`, `txt_lookup_failed`, `dns_not_pointing`, `domain_nxdomain`, `dns_lookup_failed`, `platform_ip_unknown`. A verified domain only downgrades on the four definitive failures (`txt_nxdomain`, `txt_token_mismatch`, `dns_not_pointing`, `domain_nxdomain`) — transient lookup failures never downgrade. The response carries `notice`, a string when the call moved the domain into or out of `verified` and `null` otherwise. Relay it. - `GET /apps/{id}/channels/{cid}/domains` → `{domains: [...]}` same shape. - `DELETE /apps/{id}/channels/{cid}/domains/{domain}` → `{ok:true, notice}`. Detaches and stops cert renewals; the existing cert expires on its own. `notice` is a string when the removed domain was verified and `null` otherwise. - A verify or a delete does not restart the app. The container's `XHOSTD_DOMAINS` changes at the channel's next deploy, so deploy after you verify or remove a domain when the app checks the `Host` header. - HTTPS: certs mint automatically on the first TLS handshake after verification (Caddy on-demand TLS), so the first request may add a few seconds for issuance. Subsequent requests are normal HTTPS. - OAuth on custom domains: end-user sign-in works on every verified custom domain with no extra config — the identity cookie is scoped to the inbound Host (`aud` = that hostname), so login on `myapp.com` does not log in on the canonical `.xhostd.app` or other attached domains. - Full docs: . **Port forwarding (public raw-TCP endpoints)** - For a channel that speaks a **non-HTTP** protocol over TCP — a database, a message broker, a game server, a gRPC service, a custom binary protocol. Ordinary web traffic never needs this: the channel's `https://` URL already serves it. - Container-side port is **fixed at 7000**, injected as `XHOSTD_FORWARD_PORT` into every `app` and `docker` container beside `$XHOSTD_HTTP_PORT` — the process must listen on `0.0.0.0:$XHOSTD_FORWARD_PORT` (read it from the environment). `XHOSTD_FORWARD_PORT` is a **reserved env key** (`set_env` rejects it). `static` channels have no process that can receive a connection and are refused. - Two preconditions: the current account entitlement includes port forwarding, and public TCP endpoints are on for the project (Project settings → Port forwarding). Call `get_stats(view="overview")` for current feature availability. The toggle is app-wide and is a **protected action** — it answers `protected_action` to an agent credential, and the account or project **agent access** switch opens it. The external database and object-storage toggles follow the same rule. Which *channel* is actually exposed is then the agent's call. - MCP: `expose_port(app_name, channel, allow_cidrs?)`, `list_exposed_ports(app_name)`, `unexpose_port(app_name, channel)`. - HTTP: `POST /apps/{id}/channels/{cid}/forward` `{allow_cidrs?}` → 201 `{channel_id, channel, host, port, allow_cidrs, active, created_at}`; re-POSTing an exposed channel returns 200 with the **same** `host`/`port` and the allowlist replaced (the address is stable for the life of the exposure, so it is safe to hand out). `GET /apps/{id}/forwards` → `{forwards:[...]}` (app-scoped — one round trip for every channel). `DELETE /apps/{id}/channels/{cid}/forward` → 204 — blocks reconnection only; sessions already established survive it, so deploy the channel afterwards to replace the container and end them. - `allow_cidrs` is a source-address allowlist — IPv4/IPv6 addresses or ranges (`203.0.113.7`, `203.0.113.0/24`, `2001:db8::/32`), at most 16 entries. Empty or omitted means reachable from anywhere. - Connect with the returned `host:port`. xhostd forwards bytes blind and adds no TLS and no protocol handling, so if the traffic needs encryption or auth, that belongs in your own protocol. - `active:false` on a returned endpoint means the allocation exists but is not serving — the project toggle is off or the current account entitlement does not include the feature. **End-user auth (Sign in with Google)** - xhostd is an identity provider, not a gatekeeper. It runs the Google sign-in dance and sets a signed identity cookie; nothing is blocked at the edge. Your app verifies the cookie and decides access itself (layer your own password/SMS login, allowlists, roles — or ignore `/xhost-auth/*` and run your own auth). - **Zero config.** `/xhost-auth/*` (login, logout, whoami) works on every deployed channel with no activation step. There is no protected-paths list — gating lives entirely in app code. - Identity cookie: after Google sign-in xhostd sets `__Host-xhost_id` — an `HttpOnly`, `Secure`, host-only cookie (the `__Host-` prefix forces `Path=/` and no `Domain`). Its value is an RS256-signed JWT with claims `{iss: "https://auth.xhostd.com", aud: "" (exact channel hostname), sub (stable Google id), email, name, picture (optional — absent when Google sends none or the URL fails the gateway's check), iat, exp}`. `__Host-xhost_id` is a **reserved cookie name** — apps must not set or read it as a raw value. - Verify it: fetch+cache the JWKS at `https://auth.xhostd.com/xhost-auth/jwks`; **pin `RS256`** and select the key by the token's `kid` (never let the token's own `alg` choose — prevents alg-confusion); require `iss == "https://auth.xhostd.com"`, `aud == ""`, `exp` not past. On success use `sub` as primary key (emails change). Use a real verifying JWT lib (`PyJWT` `PyJWKClient`, `jsonwebtoken`+`jwks-rsa`, `go-oidc`); **never** decode-only helpers (`jwt-decode`, `jwt.decode(..., verify=False)`) — they accept forged tokens. - Verify pseudocode: `jwks = fetch_and_cache(".../xhost-auth/jwks"); claims = jwt_verify(cookie["__Host-xhost_id"], jwks, algorithms=["RS256"], issuer="https://auth.xhostd.com", audience="")`. - Gate routes in app code: if verification fails, redirect browsers to `/xhost-auth/login?return_to=` or return 401/403. Restricting which signed-in users may proceed (allowlists or application-defined entitlements) is the app's job — check `claims.email` / `claims.sub`. - Reserved on every channel: `/xhost-auth/login`, `/xhost-auth/logout`, `/xhost-auth/whoami`. `whoami` returns JSON `{logged_in, email, name, sub}` when signed in, else `{logged_in:false, login_url}` — SPA/JS-only apps call it since the cookie is `HttpOnly`. - Where to send users: `/xhost-auth/login?return_to=`; logout: `/xhost-auth/logout?return_to=/`. - JWKS + OIDC discovery: `https://auth.xhostd.com/xhost-auth/jwks` (RS256 public keys) and `https://auth.xhostd.com/.well-known/openid-configuration`. - Anti-spoof: xhostd unconditionally strips inbound `X-Xhost-*` request headers at the edge; read identity from the verified cookie, not headers. - Persistence: xhostd does not store end-user identities, so on first sight do `INSERT … ON CONFLICT (sub)` into your own DB if you need a user record. - Full docs (per-stack verify snippets for Python/Node/Go): . **Self** - `GET /api/user/stats` — counts and `sites` rows over every project the caller can see, shared projects included (`repo` reads `owner/project`); the `resources` block is the caller's own memory and CPU alone. - `GET /me/usage` (bearer) → `{plan, storage_bytes, storage_limit_mb, bandwidth_month_bytes}` — database storage against its SOFT cap, plus the month's measured egress. Over-limit storage warns on the console account page; it blocks no write and no deploy. The payload carries NO egress limit field, because no plan states an egress figure: nothing counts the month's bytes against anything, and no egress carries a charge. 503 `postgres_unavailable` when the account's database server is unreachable. - `GET /plans` (no auth, no DB read) returns the subscription catalog. This route exists for HTTP API clients but is outside plugin workflows. Do not call it to display or compare subscription options. Use `get_stats(view="overview")` for the authenticated account's current limits, headroom, and feature availability. - `get_stats(view="overview", window)` (MCP) composes six sources in order — `/me/stats`, `/me/usage/resources`, `/apps`, `/me/usage`, `/me/blob/storage`, `/plans` — and returns `{window, traffic, resources, plan_headroom}`. `plan_headroom` carries `plan`, `cpu`, `memory`, `swap`, `channels`, `database_storage` (soft), `object_storage` (enforced, `unlimited: true` where the plan has no cap), `egress` (`month_to_date_bytes`, `enforcement: "none"`, `charged: false`), `image_size_bytes`, `snapshot_retention_days`, `deploy_snapshot_keep` and `port_forwarding`. Every `enforcement` field reads `soft`, `enforced`, or `none`: soft warns, enforced refuses the write, none means the dimension has no limit at all — `egress` states its measured bytes and no allowance, so it carries no limit and no remaining value. Nothing is clamped, so a negative remaining value is a real overage. A 503 from `/me/usage` degrades `database_storage` and `egress` to `available: false` with a reason and leaves every other block intact; any other failed source fails the whole call. ## Standard flows **First app** 1. `POST /apps {name, template}` → grab `id`, `channels[0].id`, `repo_url` 2. `git remote add xhostd "https://git.xhostd.com//.git"` 3. `GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.https://git.xhostd.com/.extraHeader GIT_CONFIG_VALUE_0="Authorization: Bearer $XHOSTD_TOKEN" git push xhostd HEAD:master` (git reads the header from its environment, so the token is never in the remote URL, the command, or argv) 4. `POST /apps/{id}/channels/{cid}/deploy {ref: "master"}` — deploys the branch you pushed and binds `prod` to it. **Redeploy**: commit → the push in step 3 → `POST .../deploy`. Same three lines, every time; once `prod` is bound, the deploy body can be `{}`. **Branch preview**: create an explicit channel per branch (`POST /apps/{id}/channels {name, git_ref_binding: "branch:"}`), push the branch, then deploy via `{ref: ""}` (xhostd resolves to HEAD) or `{sha}`. The channel's hostname is `--.xhostd.app`. ## Git-less flow (no local git required) For agents without shell or git (web LLMs, Custom GPTs, MCP connectors): commits via HTTP+JSON, two-step like `git push` + deploy. - `GET /apps/{id}/tree?ref=` → `{ref, sha, files: [{path, kind, size}]}` — list current files. Requires `repo:*`, like every repo-content read. - `GET /apps/{id}/blob?ref=&path=index.html` → raw bytes — fetch one file before editing. Requires `repo:*`. - `POST /apps/{id}/changeset` `{ref?, message, changes: {path: content_or_null}}` → `{sha}` — string upserts, null deletes, absent paths unchanged. Creates one real commit on top of ref's HEAD (or initial commit if empty). Requires `repo:*`. A 503 commits nothing: the repo is busy or the app is under maintenance. - An omitted `ref` on these three routes means the branch `prod` deploys; if `prod` has no branch yet, the repo's own default branch (`master` for a repo xhostd created, the source repository's default for an app with a connected source repository). A connected app that never synced answers 400 `ref_required`. Then ship it: `POST /apps/{id}/channels/{cid}/deploy {sha}` with the SHA returned above. Same two-step model as `git push` + deploy. Plays nicely alongside `git push` — both produce normal commits on the same bare repo. **First app, git-less**: 1. `POST /apps {name, template}` → grab `id`, `channels[0].id`. 2. `POST /apps/{id}/changeset {message, changes: {"index.html": "

hi

"}}` → `{sha}`. 3. `POST /apps/{id}/channels/{cid}/deploy {ref: "master"}` — deploys the branch the changeset wrote and binds `prod` to it. A `{sha}` deploy ships that commit and leaves `prod` unbound. ## Apps with a connected source repository An app can use a source repository as its source of truth: a GitHub repo connected with a deploy key, or a Cursor Origin repository. Both connect in the console. Mirror model: the source repository is authoritative; xhostd mirrors the repo into the app's internal repo on each sync. The pipeline and read tools (`list_source_files`, `read_source_file`, `deploy`, etc.) operate on the internal mirror unchanged. - While connected, `commit_files` and `git push` to xhostd are rejected (409/403) — push to the source repository. Cursor Origin sends each push to xhostd; a GitHub repo syncs each push once it pings xhostd (see "Deploy on push" below). - Each `deploy` first fetches the latest commits from the source repository into the mirror, then resolves/builds — so a deploy always reflects what was last pushed. If the fetch fails (e.g. the deploy key isn't set up yet), the deploy is rejected with a 409 carrying the sync error. If another write (a push, a changeset, or another sync) holds the repo, it answers 503: retry in a minute. - Sync without deploying via the console "Sync now" button or the `sync_git_from_remote` MCP tool (both refresh the mirror and surface any sync error). The sync route requires a credential holding `repo:*`. - Each sync records the source repository's default branch as `default_branch` on `GET /apps/{id}/source` and in `sync_git_from_remote`. It is a hint: nothing binds a channel to it. Deploy it with `deploy(app_name, channel="prod", ref="")`, which binds `prod`. An older app's `prod` can already be bound to `master`; a deploy with `ref` rebinds it. - **Deploy on push.** After each push, a channel with `follows_branch` deploys its branch's new head, so for that channel deploy is not its own call. A Cursor Origin repository needs no setup: Cursor Origin sends each push to xhostd. For a GitHub repo, `GET /apps/{id}/github` and `sync_git_from_remote` return `notify_url` (`https://api.xhostd.com/webhooks/github/`) and `last_ping_at`. A `POST` to `notify_url` (no auth, no body read, always 202) makes xhostd fetch the repo from GitHub. Set the ping up in one of two ways. **A GitHub Action:** commit `.github/workflows/notify-xhostd.yml` to every branch that should ping (it holds no secret; over HTTPS the push needs a token with GitHub's `workflow` scope): ```yaml name: Notify xhostd on: push jobs: notify: runs-on: ubuntu-latest steps: - run: curl -fsS --retry 5 --retry-all-errors -X POST https://api.xhostd.com/webhooks/github/ ``` **A repo webhook:** GitHub → Settings → Webhooks, the same URL, no secret, push events only (needs repo admin, uses no Actions minutes). A branch whose files lack the workflow does not ping. A repo that feeds two apps needs two `curl` lines or two webhooks. A failed push deploy, or a push xhostd cannot fetch, notifies the app owner. Full guide: https://docs.xhostd.com/guides/git. - Connect and disconnect have no MCP tool — use the console, or for a GitHub repo the HTTP API (`POST /apps/{id}/github/connect`, `DELETE /apps/{id}/github`). Connecting and disconnecting a repository are **protected actions** — each answers `protected_action` to an agent credential, and the account or project **agent access** switch opens it. A Cursor Origin repository needs a Cursor Origin account connected to the xhostd account first. That account connects in the console only, because the connection needs a person's approval on Cursor Origin, and no switch opens it. Disconnecting keeps the last mirrored state and re-enables commits. ## MCP server (claude.ai + Claude Code) Remote MCP server at `https://mcp.xhostd.com/mcp`. OAuth handles auth for a person — the browser step takes an xhostd password or Google; a registered agent sends its own token as the header instead: - **claude.ai and the Claude desktop app**: open Settings → Connectors, search for xhostd, select the **xhostd** connector, and choose **Connect to Claude**; the OAuth flow runs in the browser window that opens. In Claude Code signed in with the same claude.ai account, the connector appears in `/mcp` as **claude.ai xhostd**: choose it, and then choose **Authenticate**. - **Claude Code**: if `/mcp` already lists **claude.ai xhostd**, authenticate that instead of installing; use one way only. Otherwise install the plugin — `/plugin marketplace add xhostd/xhostd-sdk` then `/plugin install xhostd@xhostd-sdk` inside Claude Code (registers the MCP server + the xhostd skill) — or from a shell, which an agent can run itself: `claude plugin marketplace add xhostd/xhostd-sdk` then `claude plugin install xhostd@xhostd-sdk`. After a shell install, the person runs `/reload-plugins` (or restarts Claude Code) to load the plugin. Or register just the server with `claude mcp add --transport http xhostd https://mcp.xhostd.com/mcp`. Either way, the person then runs `/mcp` → xhostd → **Authenticate** (browser opens; on WSL/SSH, paste the callback URL back when prompted). An agent can't run slash commands or finish the browser sign-in, so it gives the person these steps and waits. For a headless setup with a token, register the server with `claude mcp add-json --scope user` and a `headersHelper` that reads the token from its file at each connection, so neither the configuration nor any argv holds the token: https://docs.xhostd.com/guides/register-as-agent shows the command. Exposes 44 tools: `list_apps`, `create_app`, `get_app`, `delete_app`, `create_channel`, `update_channel`, `delete_channel`, `list_source_files`, `read_source_file`, `commit_files`, `deploy`, `rewind_channel`, `get_logs`, `set_env`, `set_secret`, `delete_env`, `list_env`, `get_stats`, `get_app_health`, `list_channel_snapshots`, `restore_channel_snapshot`, `get_restore_status`, `get_snapshot_download_link`, `add_custom_domain`, `list_custom_domains`, `remove_custom_domain`, `expose_port`, `list_exposed_ports`, `unexpose_port`, `get_credential_request`, `sync_git_from_remote`, `register_ssh_key`, `list_ssh_keys`, `delete_ssh_key`, `list_activity`, `add_note`, `list_notes`, `vote_note`, `add_app_feedback`, `list_app_feedback`, `submit_platform_feedback`, `list_platform_feedback`, `export_data`, `get_export_status`. This page is the authoritative tool list; MCP clients cache the tool set at connect time, so if a tool here is missing from your session, reconnect the connector to pick up newly added or removed tools. A client with an older tool list can still call a retired tool name or use an old call shape: the server runs the call on the tool that replaced it, and the result starts with a note that names the change and asks for a reconnect. An argument a tool does not take, with no old shape to explain it, fails the call: the error names the argument and lists the ones the tool accepts. Every tool also accepts the optional `mcp_version` argument; the server reads it to explain such a change and counts calls per version, and never refuses a call over it. Four tools pick a mode with a required argument: `get_logs(source="deploy" | "runtime")` reads one deploy's build log or the running app's output, `get_stats(view="overview" | "traffic" | "object_storage")` reads account, app, or object-storage figures, `list_notes(view="threads" | "thread" | "search")` lists threads, reads one, or searches notes, and `add_note` replies on a thread when it gets `thread_number` and opens a thread otherwise. `get_app` lists an app's channels, `list_env` with `deploy_id` returns a past deploy's env snapshot, and `add_custom_domain` with `verify=true` re-checks an attached domain's DNS records. Same semantics as the HTTP API. No tool result carries a token or a key: a tool that leads to a secret returns links only — the request or the download link, plus a `console_url` that a person opens in a browser signed in to the console. Send the request with the header `Authorization: Bearer $XHOSTD_TOKEN`; any HTTP client works, for example `printf 'Authorization: Bearer %s\n' "$XHOSTD_TOKEN" | curl -sS --fail-with-body --header @- -o `, which keeps the token off argv. On a failure, the response body holds the `{"error": {"code", "message"}}` envelope. Never write a token value into a command, and never ask the person to paste one. `$XHOSTD_TOKEN` is your own token: mint one on the console /tokens page (or use the one registration gave you) and export it. Tools address an app by `app_name` — the name `list_apps` shows; qualify a shared app as `owner/name`; a UUID also works — and a channel by `channel`, its name (e.g. `prod`); a UUID works there too. The one exception is `add_app_feedback`, which names another owner's app by `owner_username` and name. Neither SQL reset/dump nor the external-access toggles have MCP tools. Reset and dump exist as HTTP API endpoints — the destructive ones are meant for deliberate, human-approved action, not something an agent triggers mid-session. The external-access toggles are protected actions, and so is the project's public-TCP-endpoint toggle. Each answers `protected_action` (403) to an agent credential, until the app owner turns agent access on. Day to day, write app code that reads `DATABASE_URL` / the `S3_*` env instead. **Git push from an MCP session** (the SSH path needs no token): pick the path from what the machine can do, before you push — never after a failure. **No shell** (a client with no shell access cannot run git): use `commit_files` — `files` for whole content, `edits` for an anchored replacement inside an existing file, `patches` for anchored hunks. On a file that already exists, `edits` and `patches` send the changed region, not the file. **A shell**: push over SSH with a key of the connected account. Compare the fingerprint (`ssh-keygen -lf `) of every existing `~/.ssh/xhost_ed25519*.pub` — the default key and every `~/.ssh/xhost_ed25519_*` key — with `list_ssh_keys`, which lists the connected account's keys, and push with the key whose `.pub` file `list_ssh_keys` lists. A file name proves nothing about the account; only a match does. If none is listed, register the default key: make it in a subprocess if it is absent (`ssh-keygen -t ed25519 -N "" -f ~/.ssh/xhost_ed25519`) and send only the **public** half with `register_ssh_key`. A `409` means the default key belongs to a different xhostd account on this machine: make `~/.ssh/xhost_ed25519_` if absent and register it. If that registration also answers `409`, this machine holds no usable SSH key for this account: push over HTTPS when `XHOSTD_TOKEN` is set, else use `commit_files`, and never make a key under any other name. Then `git remote add xhostd-ssh "git@git.xhostd.com:/.git"` and `GIT_SSH_COMMAND="ssh -i -o IdentitiesOnly=yes" git push xhostd-ssh HEAD:master`, where `` is the key you chose and `-o IdentitiesOnly=yes` stops ssh from offering another key it finds first. An SSH push needs no token; `get_app` returns the `repo_url` that holds `` and ``. With SSH, the private half never enters a tool call — some agent runtimes refuse a tool call whose content holds a secret, and such a refusal is not a clean error an agent can act on. A key belongs to the account, not to one app, so one `register_ssh_key` call per machine and account covers every app. Keep every key at `~/.ssh/xhost_ed25519` or `~/.ssh/xhost_ed25519_` — never the project directory, and never a per-project, per-app or per-tool suffix. They sit in `$HOME`, so every session, editor window and project on the machine reuses one key per account and registers no other. Never make a second key for the same account, and never make one to clear a `409` for a key that `list_ssh_keys` lists for this account. **Outbound port 22 blocked, or the SSH push fails**: push over HTTPS with a token sent as a header, either your own token from the `XHOSTD_TOKEN` environment variable or a scoped, short-lived token that you mint: `GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.https://git.xhostd.com/.extraHeader GIT_CONFIG_VALUE_0="Authorization: Bearer $XHOSTD_TOKEN" git push https://git.xhostd.com//.git HEAD:master` (git 2.31 or later). git reads the header from its environment, so the token is not on argv, and the URL-scoped key sends it to the git host alone; put the variables in front of every git command that reaches the repo. Never write the token value into a command or a remote URL. A registered agent exports the token registration gave it. **Neither transport can push** (no usable SSH key, and `XHOSTD_TOKEN` unset): use `commit_files`, and never ask the person to paste a token. Both transports reach the same repo. The **same token is your Postgres password**: `PGPASSWORD="$XHOSTD_TOKEN" psql "postgresql://@db.xhostd.com:5432/?sslmode=require"`, where `` is the app name for the `prod` channel else `-` (requires external database access enabled in the console). No tool result carries a token. To mint a scoped, short-lived token, which suits an unattended job or a token that you hand to another process, call `get_credential_request(scopes=["repo:*"], expires_in=3600)` (or `["db:*"]` for Postgres). It describes the `POST /credentials` request; run it into a variable of its own and use that variable the same way, so the token stays out of the command text and out of the output: `XHOSTD_GIT_TOKEN="$(printf 'Authorization: Bearer %s\n' "$XHOSTD_TOKEN" | curl -sS --fail-with-body -X POST --header @- --json '{"scopes":["repo:*"],"expires_in":3600}' https://api.xhostd.com/credentials | python3 -c 'import json,sys; d=json.load(sys.stdin); sys.exit(json.dumps(d)) if "token" not in d else print(d["token"])')" && GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=http.https://git.xhostd.com/.extraHeader GIT_CONFIG_VALUE_0="Authorization: Bearer $XHOSTD_GIT_TOKEN" git push https://git.xhostd.com//.git HEAD:master`. Run the mint and the command that uses the token as one shell command. A shell variable does not survive into a new shell, and an agent's tool often starts a new shell for each command. If the mint fails, `python3` prints the error envelope to stderr and exits, so `&&` stops before the push. For Postgres, mint with `"scopes":["db:*"]` into `XHOSTD_DB_TOKEN` and chain `&& PGPASSWORD="$XHOSTD_DB_TOKEN" psql ...` the same way. On 401 after expiry, ask for a fresh token on the /tokens page, or renew a registered account from its SSH key. ## App-name slugify (for `init`-style flows) Lowercase, non-alphanumerics → `-`, trim hyphens, ≤40 chars. Reject reserved prefixes. Confirm with the user before creating. ## Status values - Channel: `provisioning` | `running` | `failed` (the latter when SQL provisioning failed at create time; the hourly sweeper retries) - Deploy: `queued` | `running` | `success` | `failed` | `superseded` | `cancelled` (`superseded`: a newer deploy request for this channel replaced it; `superseded_by` names it, so poll that id. Its log is empty, or ends where a control-plane restart paused it. `cancelled`: a database restore of the channel started before it ran, so it never ran; deploy again once the restore ends) - Postgres (per-channel): `provisioning` | `ready` | `failed` ## Scopes Default-issued: `repo:* deploy:* channel:* db:* blob:* stats:read exports:read snapshots:read blobs:read`. Public bearer statistics routes require `stats:read`. ## Error codes (HTTP) `auth_required` 401 · `token_invalid` 401 · `token_revoked` 401 · `scope_denied` 403 · `permission_denied` 403 · `protected_action` 403 · `admin_not_configured` 403 · `not_found` 404 · `bad_request` 400 · `conflict` 409 · `gone` 410 · `too_many_requests` 429 · `bad_gateway` 502 · `service_unavailable` 503 · `internal_error` 500