# Leash > Leash is your own account for the apps you build with AI: one sign-in and one place for your data, across every app and every AI tool. Claude, Codex, Cursor and other AI tools connect to it as an MCP server and give each app a private Postgres database and your sign-in, with nothing to set up or host. Leash is for people who build small apps by asking an AI coding tool (Claude Code, the Claude app, Codex, Cursor or any MCP client) instead of writing code. The AI connects to Leash once, then creates apps, tables, sign-in and keys there; the person signs in to see every app and what it stores. Key facts: - MCP server URL: https://leash.build/mcp (Streamable HTTP, OAuth sign-in). Claude Code: `claude mcp add --transport http leash https://leash.build/mcp` - Agent connector (one app, structured tools, no SQL): https://leash.build/mcp/agent - Each person gets their own Postgres server; each app gets its own schema. Other users can't see or reach it. - Web apps sign people in through https://leash.build/authorize and read/write through a REST data API (https://leash.build/api/v1/data/); no keys in browser code. - Scripts, extensions and phone apps use per-device keys. - Automatic backups; a 7-day snapshot before destructive changes. - Sign in with Google or GitHub. - Pricing: Free (1 app, 100 MB) and Pro, US$10/month (25 apps, 5 GB, direct Postgres connections). ## Docs - [Leash docs](https://leash.build/docs): connecting your AI, the data API, sign-in, device keys, SQL rules and limits - [Full guide for AI tools](https://leash.build/llms-full.txt): the same instructions the MCP server gives its clients ## Examples - [Watch your app with Claude and Leash](https://leash.build/examples/watch-your-app): Set up a Claude scheduled task that checks your site every hour, keeps the results in Leash and updates a live status page. No code to host. ## Optional - [Home](https://leash.build/): what Leash is, pricing and FAQ - [Privacy Policy](https://leash.build/privacy) - [Terms of Service](https://leash.build/terms) --- # Using Leash Leash gives each of the person's apps its own Postgres schema plus sign-in. These tools act only within the signed-in person's account; every app-scoped tool takes `app` = the app's slug or id. Whoever signs in on a site approves it and picks which of THEIR apps' data it uses; no per-user rows or shared data, not for multi-user apps. ## Set up an app 1. `create_app` with a slug and the web origins the app is served from (e.g. https://myapp.example.com, http://localhost:5173). Change them later with `set_app_origins`. 2. Create tables with `apply_schema_change` (one statement per call, with a description), e.g. `create table notes (id bigserial primary key, body text not null, created_at timestamptz default now())`. 3. Inspect with `list_tables`, `describe_table`, `query` (read-only); change data with `execute`. ## Web apps (browser): no keys in the code - To sign in, send the browser to https://leash.build/authorize?app=&return= (https, or http on localhost). A new site gets an approval screen first (which data, read & change or read only); the app's own origins skip it. Leash returns `#leash_token=`: read it, keep it in memory, clear the address bar. - The token lasts 1 hour; there is no refresh token. On 401, send the browser to /authorize again: while the person's Leash sign-in lasts (30 days) it comes straight back with a new token, otherwise via sign-in. - Data API: https://leash.build/api/v1/data/
, header `Authorization: Bearer `, JSON replies: - GET
?select=a,b&=eq.&order=.desc&limit=50&offset=0 → 200 {"rows":[…]} - GET
/ (matches the `id` column) → 200 the row object itself, not wrapped; 404 not_found - POST
, body: a row object or an array of up to 1000 rows → 201 {"rows":[…inserted rows]} - PATCH
?, body: the columns to change → 200 {"rows":[…updated rows]} - DELETE
? → 200 {"rows":[…deleted rows]} Filters: eq, neq, gt, gte, lt, lte, like, ilike, in.(a,b), is.null. limit: default 100, max 1000. PATCH/DELETE need a filter; over 1000 rows they still apply but reply {"count":n}. `select` also picks what writes return. - bigint and numeric values are returned as strings (a bigserial id is "1", not 1), here and in `query`. - Errors are {"error":""}. 409 constraint_violation adds "constraint" and "column" (null when Postgres doesn't say) and a "message" naming them. 400: invalid_query, unknown_column (+ "column"), invalid_value, filter_required, invalid_body. 404 table_not_found. 429 = slow down (Retry-After). 403 storage_limit = over the storage limit (reads and deletes still work). 403 app_read_only = Free account, not its oldest app: reads only until it upgrades. 423 paused = account idle 90 days: the owner signs in to Leash, then the same token/key works again. 403 origin_not_allowed = Origin isn't the approved site's; a server-side client (script, proxy) must send none. 403 read_only_access = the person allowed this site to read only. 401 after they disconnect it in Leash. ## Device apps (scripts, extensions, phone apps) - `mint_device_key` returns a key (lk_…) shown once. Put it in the device's local config or secret store, never in browser code or a public repo. Use it as `Authorization: Bearer lk_…` on the same data API. A device key doesn't expire: it works until `revoke_device_key` or the app is deleted (then 401). - A server of the app's own can check a device key: POST https://leash.build/api/v1/keys/verify {"key":"lk_…"}. ## SQL rules - One SQL statement per `execute` / `apply_schema_change` / `query` call; use $1, $2 … with `params` for values. Allowed: select, insert, update, delete, create/alter/drop table, index, view, sequence, truncate, comment. Not allowed: functions, triggers, DO blocks, roles, grants, SET, COPY, transactions, extensions. Names starting with pg_ and system functions (e.g. pg_sleep, lo_*, dblink, set_config, current_setting) are reserved, even as column names. Tables live in the app's own schema: don't schema-qualify them. ## Safety net - Before a destructive change (drop table or column, change a column's type, truncate, or an update/delete touching more than 100 rows, or any inside a WITH clause) Leash saves a snapshot of the table, kept 7 days. `list_snapshots` and `restore_snapshot` bring data back. If a snapshot can't be taken (cap reached), the change is refused; pass `allowWithoutSnapshot: true` only when the person agrees to lose that safety net. ## Agents - To give an AI agent (Claude, ChatGPT, Grok, or your own) an app's data, add https://leash.build/mcp/agent as its connector. The approval screen has the person pick ONE app (or create one) and Read & change or Read only. The agent gets structured tools for that app only (list_tables, describe_table, select_rows; with write access insert_rows, update_rows, delete_rows, create_table, add_column, create_index): no raw SQL, other apps, drop, truncate or keys. A device key (lk_…) works too (device keys: rows only; tables are created by the owner or a connected agent). Per connection: 60 calls a minute; 50 tables, 100 columns per table; writes stop (app_storage_limit) when the app uses over half the plan's storage or the account reaches 90% of it. A prompt injection can damage only that app's data: use Read only where you can. Bulk changes are snapshotted 7 days. ## Limits - Free: 1 app, 100 MB. Pro: 25 apps, 5 GB. `usage` shows where the account stands (`bytes: null` = not measured yet; sizes are measured a few minutes after writes). `reclaim_space` compacts after large deletes. - Time: each MCP statement gets the plan's limit (Free 5 s, Pro 30 s); each data API request at most 10 s (5 s on Free). Rate limits (429) are abuse backstops per user, OAuth client and app; per-IP ones are generous. - This connector's tokens last 1 hour and renew by themselves; reconnect after 30 days unused or 90 in all.