Quickstart
Start Charter and Postgres from one Compose file, connect an operator agent, and commit the charter.toml it writes.
To get a local Charter project running, you will start Postgres and Charter from one Compose file, connect an operator agent, and commit the charter.toml the agent writes. By the end of this page you will have a live API on http://localhost:3000.
What you need#
- Docker Engine
- Docker Compose (the
docker composeplugin)
Confirm both:
docker --version
docker compose version
Run the commands in bash or zsh. Of course, you are free to install a charter binary on the host instead; see Run Charter on the host.
Create the project#
mkdir acme-api && cd acme-api
Create compose.yaml in that directory. You should pin the image to a release from Install. Prerelease tags use the exact version. latest only moves for stable releases.
services:
postgres:
image: postgres:17-alpine
environment:
POSTGRES_USER: charter
POSTGRES_PASSWORD: charter
POSTGRES_DB: charter
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U charter -d charter"]
interval: 5s
timeout: 5s
retries: 10
charter:
image: ghcr.io/snaapi/charter:1.0.0-alpha.5
# Writes charter.toml as your user, so you can commit it.
user: "${UID}:${GID}"
working_dir: /work
command: ["dev"]
volumes:
- .:/work
ports:
- "127.0.0.1:3000:3000"
depends_on:
postgres:
condition: service_healthy
volumes:
postgres_data:
Postgres stays on the Compose network. The Charter container reaches it at the hostname postgres. Inside that container, localhost is the container itself.
Warning
The Postgres password in this file is for a local project. Do not reuse it, and do not publish port 5432. Keep .env out of git. COOKIE_SIGNING_KEY signs session cookies. Changing it signs every existing session out. Leave the published port as 127.0.0.1:3000. 3000:3000 opens the seeded password and API key to other machines on the network.
Info
This file runs charter dev for local work. Production uses charter serve. See Deploy with Docker.
Write .env and a .gitignore from the project directory. The shell fills in your user id, group id, and a new signing key:
cat > .env <<EOF
UID=$(id -u)
GID=$(id -g)
APP_ENV=development
DATABASE_URL=postgres://charter:charter@postgres:5432/charter
COOKIE_SIGNING_KEY=$(openssl rand -base64 64 | tr -d '\n')
CHARTER_HOST=0.0.0.0
CHARTER_API_NAME=Acme API
CHARTER_MCP_ROLE=user
EOF
echo .env > .gitignore
openssl wraps the key onto more than one line. tr removes that break so .env keeps a single KEY=VALUE line. The key has to be at least 64 bytes.
CHARTER_HOST=0.0.0.0 makes charter dev listen on every interface inside the container. Docker forwards the published port to that address, not to the container's own localhost. The host side stays 127.0.0.1, so only this machine can open http://localhost:3000. Charter refuses 0.0.0.0 until COOKIE_SIGNING_KEY is set.
APP_ENV=development marks the project as local. charter dev refuses to start when APP_ENV is production.
CHARTER_MCP_ROLE is the role Admin Model Context Protocol (MCP) uses for record reads. Without it, those reads refuse to run.
CHARTER_API_NAME is the name on the docs header. CHARTER_BASE_URL defaults to http://localhost:3000, which matches this file.
Start Charter#
From the project directory:
docker compose up -d
docker compose logs -f charter
The first start pulls the images, waits until Postgres is healthy, then runs charter dev. Ctrl-C stops following the logs and leaves Charter running. docker compose down stops the stack.
The Charter logs should include a banner like this:
Charter v1.0.0-alpha.5 (dev)
✓ REST http://localhost:3000/v1
✓ OpenAPI http://localhost:3000/openapi.json
✓ Docs http://localhost:3000/docs
✓ LLMs http://localhost:3000/llms.txt
✓ MCP http://localhost:3000/mcp
✓ MCP API http://localhost:3000/v1/mcp
✓ Worker queues: default, imports, webhooks, mail
Info
On the first start Charter seeds a control-plane admin, [email protected], and prints its password and API key once, under that banner. To rotate them, stop the service and run docker compose run --rm --service-ports charter dev --reseed, then start the stack again with docker compose up -d.
Connect an agent#
Register the Admin MCP server with your operator client. charter mcp speaks MCP over standard input and output (stdio). Run the client from the project directory so docker compose finds compose.yaml.
claude mcp add acme-api -- docker compose run --rm -i -T charter mcp
codex mcp add acme-api -- docker compose run --rm -i -T charter mcp
gemini mcp add -s project acme-api -- docker compose run --rm -i -T charter mcp
-i keeps standard input open. -T skips a terminal. A stdio session needs both.
For Claude Desktop, add this to claude_desktop_config.json. The app has to start with the project directory as its working directory:
{
"mcpServers": {
"acme-api": {
"command": "docker",
"args": ["compose", "run", "--rm", "-i", "-T", "charter", "mcp"]
}
}
}
Warning
Claude Desktop often starts in your home directory. This config only works when that working directory is the project, because docker compose reads compose.yaml from there.
Paste a prompt like this into the client and let the agent build the API with Admin MCP tools. The MCP page lists every tool.
Build a small library API with Charter Admin MCP.
Resources:
- books: title (required, searchable), author (required), isbn (unique string), published_year (number), available (boolean, default true)
- loans: book_id (relation to books), borrower_name (required), borrowed_at (datetime), returned_at (optional datetime)
Permissions:
- role librarian: full create, read, update, and delete on books and loans
- role member: read books; create and read loans
Create the resources, fields, and permissions with the MCP tools. Do not write application code. When you finish, summarize what you created.
View the API#
Open the live docs and OpenAPI document while charter dev is running:
- http://localhost:3000/docs for try-it forms for your resources
- http://localhost:3000/openapi.json for the OpenAPI specification (YAML too)
See OpenAPI for import into other tools.
Review and commit#
While charter dev is running, it keeps charter.toml and the database in step. The file is created in the project directory when it is missing. Changes from MCP, the CLI, or the HTTP API are written back into it.
Open charter.toml, check the resources, fields, and permissions the agent added, then commit it. Leave .env untracked. That file is the API definition your repository needs.
More on the format: Config file.
Run Charter on the host#
Use this section when you want the charter binary on your PATH. Start in a new empty directory so charter setup can write its own files. Install the binary from Install first.
mkdir acme-api && cd acme-api
charter setup --yes
charter dev
charter setup writes a .env, a .gitignore, and a compose.yaml for Postgres. Pass --force to overwrite a file that already exists. charter dev listens on 127.0.0.1:3000, and runs docker compose up -d postgres when that database is down.
From that directory, register the agent with the binary:
claude mcp add acme-api -- charter --env-file .env mcp
codex mcp add acme-api -- charter --env-file .env mcp
gemini mcp add -s project acme-api -- charter --env-file .env mcp
The example prompt and the docs URLs above are the same. For Claude Desktop, the command is charter and the args are --env-file, .env, and mcp.