# Build with AI

These docs are written to be read by coding agents as much as by people. Every page is also Markdown, the whole set is one file, and a hosted MCP server lets Claude Code, Cursor and Copilot search and read the docs from inside your editor.

## The MCP server

`http://docs.staging.regoria.com/mcp/docs` is a public, read-only MCP server over these docs (Streamable HTTP, no sign-in). It serves documentation only: no account data, no credentials, no calls to the API.

Claude Code:

```bash
claude mcp add --transport http merchant-docs http://docs.staging.regoria.com/mcp/docs
```

Cursor (`.cursor/mcp.json`):

```json
{ "mcpServers": { "merchant-docs": { "url": "http://docs.staging.regoria.com/mcp/docs" } } }
```

VS Code with Copilot (`.vscode/mcp.json`):

```json
{ "servers": { "merchant-docs": { "type": "http", "url": "http://docs.staging.regoria.com/mcp/docs" } } }
```

| Tool | What it returns |
|---|---|
| `search_docs(query, limit)` | the best matches across guides, reference and events, with excerpts and URLs |
| `get_guide(slug)` | a guide as Markdown (no slug: the list) |
| `get_operation(method, path)` | one operation: scope, idempotency, parameters, examples, code samples |
| `get_event(type)` | one webhook event with its payload and example |
| `list_operations(tag)` | the inventory of operations |

## The boards' MCP servers (signed in, as you)

Every board of Regoria also exposes an MCP server over the same operations the board's pages call, run **as the signed-in person with their permissions**: `https://api.staging.regoria.com/mcp/v1` for the merchant API (your API key as the bearer, the key's scopes decide the tools), the dashboard host's `/mcp/merchant`, the back office's `/mcp/admin`, and `/mcp/buyer` on the pay host (the buyer's portal token). The tool list is generated from this reference: a tool's name, description and parameters are the operation's, so a read here is a read there.

Claude Code against the merchant API:

```bash
claude mcp add --transport http merchant-api https://api.staging.regoria.com/mcp/v1 --header "Authorization: Bearer $API_KEY"
```

The dashboard and back-office servers take an OAuth sign-in instead of a key: point the client at the board host's `/mcp/<board>`, it discovers `/.well-known/oauth-protected-resource/mcp/<board>`, registers itself, sends you to the board's authorize page, and gets a token that lives as long as your session. Writes are limited to the idempotent operations and carry an `Idempotency-Key` the server mints. The in-app assistant on the boards ("Explain" on a page) reads through the same tools, so an answer there and a call here cannot disagree; every call is kept in the tenant's audit with a redacted transcript.

## llms.txt and Markdown pages

- [`http://docs.staging.regoria.com/llms.txt`](http://docs.staging.regoria.com/llms.txt): the index, one line per page.
- [`http://docs.staging.regoria.com/llms-full.txt`](http://docs.staging.regoria.com/llms-full.txt): every guide, event and operation in one Markdown file (under 1 MB). Point an agent at this when it has no MCP.
- Any guide or event page as Markdown: add `.md` to its URL, or send `Accept: text/markdown`. The **Copy for AI** button on each page copies the Markdown.
- [`http://docs.staging.regoria.com/openapi.json`](http://docs.staging.regoria.com/openapi.json): the OpenAPI 3.1 document with examples, scopes and code samples, for type generation.

## A CLAUDE.md or AGENTS.md snippet

Paste this into your repository's agent instructions and fill in the two paths:

```markdown
## Payments: Regoria merchant API

- Docs: http://docs.staging.regoria.com (MCP server http://docs.staging.regoria.com/mcp/docs; full text http://docs.staging.regoria.com/llms-full.txt).
- Base URLs: sandbox https://api.sandbox.staging.regoria.com with the mor_test_ key in API_KEY; live https://api.staging.regoria.com with a mor_live_ key, never from a developer machine.
- Amounts are integer cents in USD. Never floats, never strings.
- Send Idempotency-Key (a UUID, or derived from our own record) on POST /v1/checkout-sessions, /v1/orders, /v1/refunds, /v1/subscriptions/{subscription}/charge and /v1/subscriptions/{subscription}/resume.
- Webhooks: verify X-Webhook-Signature (HMAC-SHA256 of "<t>.<raw body>" with the endpoint secret, 300 s tolerance) before trusting a body; deduplicate on X-Webhook-Delivery; acknowledge 2xx after recording, do the work after.
- Treat order.paid as the source of truth for a sale, never the success_url redirect.
- Never log a full API key or webhook secret; log the key prefix and the delivery id.
- Our webhook handler lives at <path>; our API client wrapper at <path>.
```

## Three prompts that work

Each names the pages the agent should read; with the MCP server it will fetch them itself.

**Hosted checkout**

> Add a "Buy now" flow for product `prd_…` using the Regoria API. Read get_guide("hosted-checkout") and get_operation("POST", "/v1/checkout-sessions"). On click, our server opens a checkout session with the user's id as customer_ref and an Idempotency-Key derived from our cart id, then redirects to the session url. Add a webhook handler for order.paid (get_guide("webhooks"), get_event("order.paid")) that verifies the signature, stores the event id for deduplication, marks our order paid and enqueues fulfilment. Mark the order fulfilled with POST /v1/orders/{order}/fulfil when our job completes. Use the sandbox and API_KEY from the environment.

**A subscription with a portal link**

> Read get_guide("subscriptions") and get_guide("customers-and-portal"). Create a plan on our "Pro" product (monthly, 14-day trial) if none exists, open a checkout session for its price with the signed-in user's id as customer_ref, and handle subscription.started, subscription.renewed, subscription.past_due and subscription.cancelled to keep our `subscriptions` table current. Add a "Manage billing" button that mints a portal session (POST /v1/portal-sessions) for the user and redirects to its url.

**A webhook handler with tests**

> Read get_guide("webhooks") and list the events with get_event(). Write a single webhook endpoint for our framework that verifies X-Webhook-Signature with constant-time comparison and a 300-second tolerance, rejects replays by X-Webhook-Delivery using our database, acknowledges with 200 before processing, and dispatches to one handler per event type. Write tests with a fixture per event taken from the examples in get_event(type), including a tampered body and a stale timestamp.

## What the agent should not do

- Call the live base URL from a development machine, or put a live key in a `.env` that is committed.
- Build a card form; the hosted page and the portal take cards.
- Trust the `success_url` redirect as proof of payment.
- Retry a non-idempotent write without reading the record first.
