# Start a product with create-omazy-app

Create a Cloudflare Worker on the Omazy SDK kits with one command. Capabilities, the guard and an MCP door with personal keys, and optionally the ai, actors, flows, copilot and oauth kits, with tests and a deploy.

Source: https://docs.omazy.ai/build-on-omazy/create-omazy-app/

:::caution[Preview]
`create-omazy-app` ships with `@omazyai/sdk` 0.5.3 as a preview, and the kits it wires may change
before 1.0. Until it is on npmjs.com, run it from the release:
`npx https://github.com/omazyai/omazy-sdk/releases/download/v0.5.3/create-omazy-app-0.5.3.tgz my-product`.
Before you turn the oauth kit on, follow the setup rules on its [page](/build-on-omazy/kits/oauth/).
:::

`create-omazy-app` writes a new AI product on the [kits](/build-on-omazy/kits/capabilities/): a
Cloudflare Worker whose MCP door Claude, ChatGPT, Cursor and Claude Code can call, with every call
through the guard. It is wired and tested before you change a line.

```sh
npm create omazy-app@latest my-product
```

`bun create omazy-app my-product` and `pnpm create omazy-app my-product` do the same. In a
terminal it asks for the kits and your Cloudflare account; or pass flags:

```sh
npm create omazy-app@latest my-product -- --preset full --account <account id>
```

| Flag | What it does |
|---|---|
| `--preset minimal` | Capabilities, guard and mcp. The default |
| `--preset full` | Every kit below |
| `--kits ai,flow` | Kits on top of the base: `ai`, `actor`, `flow`, `copilot`, `oauth`. `actor`, `flow` and `copilot` bring `ai` |
| `--account <id>` | Your Cloudflare account id (`wrangler whoami`), written into `wrangler.jsonc` |
| `--sdk <path or url>` | Install `@omazyai/sdk` from a local build or another tarball |
| `--yes` | Ask nothing; take the defaults |

## What it writes

Every product has:

- **Two capabilities** in `src/capabilities.ts`: `note_get`, an R0 read, and `note_add`, an R2
  write with a preview, on a `notes` table in D1. Replace them with your own.
- **The guard** in `src/guard.ts`, on D1: the confirm tokens, the request log and the kill
  switches. Your `can()` is in `src/access.ts`. The guard refuses an argument that names another
  tenant's record.
- **Approval codes.** The guard proves whoever decides an approval with its `codeStepUp`. `sendCode`
  in `src/index.ts` delivers the code: locally, `STEP_UP_LOG=1` in `.dev.vars` prints it to the
  `wrangler dev` console; deployed, it refuses until you wire your mail or SMS sender there. The
  tests catch codes in `h.codes`.
- **An MCP door** at `/mcp` for the `app` audience, with **personal keys**: one person's seat in
  one tenant, at most R2 and 90 days, stored only as a hash in KV.
- **A door switch that is off in production.** `DOOR_DEFAULT` is `off` in `wrangler.jsonc` and
  `on` in `.dev.vars`, so a fresh deploy answers 503 until you turn the door on.
- **Tests** on the [testing kit](/build-on-omazy/kits/testing/): parity, the tier snapshot, the
  approval invariant, tenant isolation, the door end to end and the injection suite, on memory
  stores and the fake Core API.

Each kit you add brings its part:

| Kit | Adds |
|---|---|
| `ai` | The `note_title` task unit, saved through `note_add`, with 30 cases in `evals/note-title.jsonl` and a threshold of 0.9, and its eval test |
| `actor` | The `note_intake` actor, served on the door as `actor_start`, `actor_reply`, `actor_status` and `actor_confirm` |
| `flow` | The `note_followup` workflow on Cloudflare Workflows, started through the R2 capability `note_followup_start` |
| `copilot` | The copilot on a Durable Object, and its page at `/` from the [ui kit](/build-on-omazy/kits/ui/): the panel, standing grants and approvals inbox (with `CodeStepUpForm`, so an owner approves in the page), signed in with a personal key |
| `oauth` | The [oauth kit](/build-on-omazy/kits/oauth/) for clients that sign in. Off (`OAUTH` is `off`) until you turn it on; read its page first |

`wrangler.jsonc` binds what the kits need: D1 and KV always, Durable Objects for the copilot and
the OAuth refresh lock, the Workflow, assets for the page and rate limits for OAuth. The kits' D1
migrations are collected, after your own, in `migrations/`.

## From install to a deployed door

```sh
cd my-product
npm install
npm run migrate                                   # local D1
npm run key -- --person you --tenant demo         # prints a personal key once
npm run dev
```

Call the door with the key as a bearer token:

```sh
curl -s localhost:8787/mcp -H "authorization: Bearer $KEY" -H 'content-type: application/json' \
  -H 'accept: application/json, text/event-stream' -H 'mcp-protocol-version: 2025-06-18' \
  -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
```

A first `note_add` answers with its preview and a `token`, under the guard's names (`outcome`,
`token`, `expiresAt`, `preview`). The same call with `"confirm_token": "<token>"` adds the note:
the guard's confirm for an R2 write.

To deploy:

```sh
npx wrangler login
npm run setup                                     # page, D1, KV, migrations, deploy, GUARD_SECRET
npm run key -- --person you --tenant demo --remote
npm run door -- on --remote
```

`setup` builds the page when the product has one, creates the D1 database and the KV namespace,
writes their ids into `wrangler.jsonc`, applies the migrations, deploys and sets the guard's
secret. The door then answers at
`https://my-product.<your subdomain>.workers.dev/mcp`. Connect Claude Code with:

```sh
claude mcp add --transport http my-product https://my-product.<your subdomain>.workers.dev/mcp --header "Authorization: Bearer $KEY"
```

`npm run door -- off --remote` stops every request within a few seconds. With the `ai` kit, set
the Core API token too: `npx wrangler secret put OMAZY_TOKEN`.

## Scripts

| Script | Does |
|---|---|
| `dev` | `wrangler dev`, after building the page when there is one |
| `test`, `check` | The tests; `check` typechecks first |
| `migrate`, `migrate:remote` | Applies `migrations/` to local or remote D1 |
| `key` | Mints a personal key: `--person`, `--tenant`, `--days`, `--name`, `--remote` |
| `door` | Turns the MCP door `on` or `off`, with `--reason` and `--remote` |
| `setup` | Puts the product on your Cloudflare account, once |
| `deploy` | `wrangler deploy` |

## The SDK version

The product pins `@omazyai/sdk` to the release tarball of the version `create-omazy-app` came
with, so the two always match. To try it against a build of your own:

```sh
(cd sdk/typescript && npm run build && npm pack --pack-destination /tmp/sdk)
node sdk/create-omazy-app/bin/create-omazy-app.mjs my-product --sdk /tmp/sdk/omazyai-sdk-<version>.tgz
```

## Next

[Build an AI product in a day](/build-on-omazy/tutorial-ai-product-in-a-day/) takes a full product from
here to a deployed booking desk: your own capabilities, an AI task with evals, an actor, the copilot
page and a workflow with an approval.
