# AGENTS.md — working with the Lupeno API

<!-- Generated by `pnpm --filter @lupeno/mcp generate` (packages/mcp-server/src/agents-md.ts). Do not edit a copy by hand. -->

Lupeno is a ticketing and event-registration platform. Its public REST API (`/v1`, base `https://api.lupeno.com`) gives an organization's own software its events, ticket tiers, orders, tickets, attendees, discount codes, check-ins and documents; signed webhooks say when they change. You can reach it three ways:

- **HTTP** — the reference is `https://api.lupeno.com/openapi.json` (OpenAPI 3.1) and `https://lupeno.com/developers`; `https://lupeno.com/llms.txt` and `/llms-full.txt` are the guides for a model.
- **`@lupeno/sdk`** — the typed TypeScript client: `createLupeno({ apiKey })`, `unwrap`, `paginate`, `idempotencyKey`, `verifyWebhook`.
- **`@lupeno/mcp`** — an MCP server over the same API, its tools listed at the end of this file.

## The rules

1. **Test-mode keys first.** A `lup_test_…` key sees only events in test mode and their test orders; nothing it does is billed or shows in analytics, though the e-mails it causes are real. Build and try everything with one. Use a `lup_live_…` key only when the person you work for asks for real data — and through the MCP server, live writes stay refused unless they start it with `LUPENO_MCP_ALLOW_LIVE_WRITES=true`.
2. **Keys are secrets.** Read the key from the environment (`LUPENO_API_KEY`); never write it into code, a commit, a log, an issue or a chat. Ask for the narrowest key that does the job: one event rather than the organization, `read` unless writes are needed, and no `pii` scope unless you truly need e-mails (without it they come masked).
3. **An idempotency key on every create.** Creating an order or a discount code requires an `Idempotency-Key` header (16–128 characters of `A–Z a–z 0–9 _ -`). Choose it once per thing you mean to create and send the same key on every retry: the API answers a retry with the first result, so nothing is created twice. The other writes (cancel, revoke, assign, check in or out) take no key — repeating one ends in the state the first left.
4. **Cursor pagination.** Lists answer `{ items, nextCursor }`, newest first; pass `nextCursor` back as `cursor` for the next page, up to `limit=100` per page. A cursor is opaque — never build one. Read only the pages the task needs.
5. **Verify every webhook.** `Lupeno-Signature: t=<unix>,v1=<hex>` is HMAC-SHA256 over `${t}.${rawBody}` with the endpoint's `whsec_…` secret. Verify against the raw body before parsing, refuse a `t` more than five minutes off, answer `2xx` within 10 seconds and work afterwards, deduplicate on the event `id`, and act on `data`'s state, never on the type alone. The SDK's `verifyWebhook` / `constructWebhookEvent` do the checking.
6. **Rate limits.** 300 requests a minute per key, in bursts of up to 60. A `429` carries `Retry-After` in seconds: wait that long, then continue. Writes that mail people (orders entered by hand, naming a ticket's holder) also count against the organization's daily reach — past it `409 bulk.over_daily_cap` with `context.resetsAt`; wait until then.
7. **Errors are RFC 9457 problems.** Branch on `code` (`order.sold_out`, `api.scope_missing` …), never on `title`. Retry `429`, `5xx` and network failures with backoff — creates only with the same idempotency key; never retry a `4xx` unchanged. Quote `requestId` when asking Lupeno for help.
8. **Money is integer minor units with a currency.** `{ "amountMinor": 25000, "currency": "CZK" }` is 250 Kč. Never use floats for money.
9. **Some writes mail real people.** Entering an order mails its buyer, naming a holder mails the holder — in test mode too. Confirm names, addresses and quantities with the person before such a call.
10. **Buyers never pay through the API.** Orders a buyer pays go through Lupeno's checkout or the widget; the API enters only the organizer's own orders (free, paid outside Lupeno, or a proforma).

## The MCP server (`@lupeno/mcp`)

Runs over stdio with your key in the environment:

```json
{
  "mcpServers": {
    "lupeno": {
      "command": "npx",
      "args": ["-y", "@lupeno/mcp"],
      "env": { "LUPENO_API_KEY": "lup_test_…" }
    }
  }
}
```

| Variable | Meaning |
|---|---|
| `LUPENO_API_KEY` | The key the server acts with (stdio). A test key first. |
| `LUPENO_API_URL` | The API's base; `https://api.lupeno.com` when unset. |
| `LUPENO_MCP_READ_ONLY` | `true`: write tools are not offered at all. |
| `LUPENO_MCP_ALLOW_LIVE_WRITES` | `true`: writes with a live key are carried out. Unset, they are refused before anything is sent. |

`lupeno-mcp --http --port 3333` serves Streamable HTTP on `127.0.0.1` for your own hosting: each request carries its own key as `Authorization: Bearer lup_…`. Lupeno hosts no MCP server.

What the server does for you: a create without an `idempotencyKey` gets a generated one, named in the answer — retry with that one; list tools return `nextCursor` and never read every page by themselves; a `429` is reported with its `Retry-After` and not retried; errors come back as the problem's code, title, fields and request id, with the key always redacted. Resources: `lupeno://agents` (this file), `lupeno://guides/<slug>` (every developer guide) and `lupeno://events/{eventId}`.

## Tools and the endpoints they call

| Tool | Endpoint(s) | Key scope | Kind | Hints |
|---|---|---|---|---|
| `get_organization` | `GET /v1/organization` | `read` | read | read-only, idempotent |
| `list_events` | `GET /v1/events` | `read` | read | read-only, idempotent |
| `get_event` | `GET /v1/events/{eventId}`<br>`GET /v1/events/{eventId}/tiers` | `read` | read | read-only, idempotent |
| `list_event_gallery` | `GET /v1/events/{eventId}/gallery` | `read` | read | read-only, idempotent |
| `list_orders` | `GET /v1/events/{eventId}/orders` | `read` | read | read-only, idempotent |
| `get_order` | `GET /v1/orders/{orderId}` | `read` | read | read-only, idempotent |
| `list_order_documents` | `GET /v1/orders/{orderId}/documents` | `read` | read | read-only, idempotent |
| `list_tickets` | `GET /v1/events/{eventId}/tickets` | `read` | read | read-only, idempotent |
| `get_ticket` | `GET /v1/tickets/{ticketId}` | `read` | read | read-only, idempotent |
| `list_attendees` | `GET /v1/events/{eventId}/attendees` | `read` | read | read-only, idempotent |
| `list_check_ins` | `GET /v1/events/{eventId}/check-ins` | `read` | read | read-only, idempotent |
| `list_discount_codes` | `GET /v1/events/{eventId}/discount-codes` | `read` | read | read-only, idempotent |
| `get_discount_code` | `GET /v1/discount-codes/{codeId}` | `read` | read | read-only, idempotent |
| `create_order` | `POST /v1/events/{eventId}/orders` | `write` | create | idempotency key, mails people |
| `cancel_order` | `POST /v1/orders/{orderId}/cancel` | `write` | write | destructive, idempotent |
| `assign_ticket` | `POST /v1/tickets/{ticketId}/assign` | `write` | write | destructive, idempotent, mails people |
| `create_discount_code` | `POST /v1/events/{eventId}/discount-codes` | `write` | create | idempotency key |
| `revoke_discount_code` | `POST /v1/discount-codes/{codeId}/revoke` | `write` | write | destructive, idempotent |
| `check_in_ticket` | `POST /v1/events/{eventId}/check-ins` | `checkin` | write | idempotent |
| `revert_check_in` | `DELETE /v1/events/{eventId}/check-ins/{ticketId}` | `checkin` | write | destructive, idempotent |

Scopes: `write` and `checkin` include `read`; `pii` unmasks e-mails. "Mails people" marks a write that sends e-mail to the addresses it is given.
