# Deploy instruction for AI agents

Add this context to your project's `CLAUDE.md`, Cursor rules, or paste it when starting a project, so your AI assistant builds the app to deploy correctly on Percher.

Requirements: the app must expose an HTTP server on a configurable port (default 3000) and a health endpoint that returns 200 (usually `GET /health`); a `percher.toml` must exist in the project root. Node/Bun build through Percher's multi-stage Dockerfile; Python builds use Percher's own multi-stage Dockerfile too: set `[web].command`, and ship `requirements.txt` or a supported lockfile with its project file (a bare `pyproject.toml` is rejected); `runtime = "docker"` uses your own Dockerfile. runtime is one of node, bun, python, static, docker (use docker for Go, Rust, PHP, Ruby, Java, .NET, Elixir).

How to deploy: `bunx percher publish` or the `percher_publish` MCP tool handles auth, config, packaging, and deploy in one call and returns structured errors. The agentic happy path (MCP) is:

```
publish (waitForLive: false) -> wait_for_deploy -> if recovery says so: doctor -> exact action
```

`percher_publish` returns in seconds with `status: "queued"` and a `deployId`; `percher_wait_for_deploy` (args pre-filled in `recovery.args`) reports live/failed/replaced; ambiguous failures route to `percher_doctor`, the recovery hub.

A `live` result can also carry `runtimeCapture: { status, errors? }` — console errors and uncaught exceptions captured from the deployed page. A GREEN deploy (the container serves HTTP) can still be broken on load: an unresolved module import, a CSP violation, a throw. `status: "pending"` means the capture is still running; call `percher_doctor` mode='runtime' a few seconds later to read them.

Agent recovery contract: every MCP tool that can fail returns `recovery.nextAction`, one of: none, open_login, wait_auth, wait_deploy, run_doctor, set_env_vars, fix_problems, retry, reproduce_locally, fix_config, ask_user, inspect_build_log. Read `recovery.nextAction` (don't regex the suggestion text), call exactly the suggested tool with exactly `recovery.args` (keep `mode`/`deployId`), and repeat until it's `none` (success) or `ask_user`.

Database: add `[data] mode = "pocketbase"` for a managed PocketBase (connect via `POCKETBASE_URL`). Env: set with `bunx percher env set KEY=VALUE` or `percher_env_set`; declare a `[env]` contract (required/optional/ignore) so undeclared keys block the deploy with `fix_config` instead of failing mid-build. Apps deploy to https://<app-name>.percher.run with automatic SSL.

Full guide: https://percher.app/docs/ai-agents
