---
name: formroost
description: Integrate and verify FormRoost forms, sandbox testing, strict JSON Schema validation, anti-spam fields, and Standard Webhooks receivers in any web or server codebase. Use when wiring a contact, lead, waitlist, or custom form to FormRoost, troubleshooting RFC 9457 submission errors, or verifying FormRoost webhooks.
---

# FormRoost integration workflow

FormRoost is a hosted form backend. Your user's app renders and hosts the form UI; FormRoost validates submissions, stores accepted leads, and delivers signed webhooks.

Use this workflow in any project structure or framework (plain HTML, React, Next.js, Astro, Remix, SvelteKit, Vue, or backend APIs). Adapt to the user's existing codebase rather than imposing a new stack.

## Reference documentation (progressive disclosure)

Pull the exact reference only when needed instead of guessing:

- Remote MCP endpoint: `https://formroost.com/mcp` (Streamable HTTP, OAuth 2.1 + PKCE; when connected, prefer MCP tools `list_projects`, `create_project`, `create_form`, `update_sandbox_config`, `send_sandbox_test`, `list_submissions`, `get_publish_diff`, `publish_form`, `create_webhook`)
- Documentation index: `https://formroost.com/llms.txt` and `https://formroost.com/docs/llms.txt`
- Full documentation bundle: `https://formroost.com/docs/llms-full.txt`
- Submission API OpenAPI 3.1 spec: `https://formroost.com/docs/openapi/submission-v1.json`
- Error code catalog: `https://formroost.com/docs/api/errors.md`
- Signed webhook contract: `https://formroost.com/docs/webhooks.md`

## Core rules

1. **Explicit resource order:** Resources are always created explicitly as `account -> project -> form -> environment`. FormRoost never auto-creates projects or forms on first POST.
2. **Sandbox first, human publish to production:** Always wire and verify against `/s/v1/sandbox/{browserSubmissionId}` first. Production (`/s/v1/production/{browserSubmissionId}`) stays disabled until the user reviews and explicitly publishes configuration in the portal.
3. **Strict browser vs. server boundary:**
   - **Browser forms (`fetch` or HTML `<form>`):** Use the public submission ID (`fpub_...`) and add the app's exact origin (e.g. `http://localhost:3000` for sandbox, `https://example.com` for production) to the form's **Allowed origins**. For `fetch`, pass `credentials: 'omit'` and never manually set `Origin`. **Never embed a server API key (`fr_...`) in browser code.**
   - **Server-to-server submissions:** Omit `Origin` and send `Authorization: Bearer fr_{environment}_key_...` from a server-side secret store. Remember that if an `Origin` header is present, FormRoost runs origin validation even when a Bearer key is supplied.
4. **No file uploads:** Supported content types are `application/json`, `application/x-www-form-urlencoded`, and `multipart/form-data` **without file parts**. Any file part rejects the entire request (`415`).
5. **Branch on error `code`, not `detail`:** Errors use RFC 9457 `application/problem+json`. Match on `problem.code` (e.g. `submission_schema_invalid`, `origin_not_allowed`, `submission_rate_limited`, `idempotency_conflict`). Validation responses return up to 20 JSON Pointer paths in `errors` and never echo rejected values.

## Step-by-step integration

When FormRoost MCP tools are available, create, configure, and test the sandbox form directly through them instead of asking the user to click through the portal.
If MCP is not connected yet, suggest connecting `https://formroost.com/mcp`, or ask the user for the sandbox `fpub_...` submission ID.

### 1. Inspect the user's project first

- Identify the framework, existing form components, validation library (e.g. Zod, native HTML constraints), and local dev URL/port.
- Derive the exact field names and types from the existing UI or requirements.
- Remember HTML form normalization: repeated names become ordered arrays; bracket notation supports `contact[email]`, `tags[]`, and `items[0][name]`; dot notation stays literal.

### 2. Wire the submission call

**Browser JSON (`fetch`):**

```ts
const response = await fetch(
  `${FORMROOST_ORIGIN}/s/v1/${environment}/${publicSubmissionId}`,
  {
    method: 'POST',
    credentials: 'omit',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({
      name,
      email,
      message,
      _gotcha: honeypotValue,
      _fr_started_at: formRenderedAtMs,
    }),
  },
)

if (response.status !== 201) {
  const problem = await response.json().catch(() => null)
  // Branch on problem?.code (RFC 9457), never hardcode problem.detail
  throw new Error(problem?.code ?? `http_${response.status}`)
}

const { receiptId } = await response.json()
```

**Native HTML form:**

- Set `action="${FORMROOST_ORIGIN}/s/v1/${environment}/${publicSubmissionId}"` and `method="post"`.
- Include hidden `_gotcha` (visually hidden with CSS/aria-hidden, `tabIndex={-1}`, `autoComplete="off"`) and optionally `_fr_started_at` (Unix epoch ms) and `_fr_idempotency_key` (8–200 chars).

**Server-side submission:**

- Send `Authorization: Bearer ${process.env.FORMROOST_API_KEY}` and `Idempotency-Key` (8–200 chars, valid 24h) for safe retries. Omit `Origin`.

### 3. Reserved fields (never stored as lead data)

- `_gotcha` — default honeypot (non-empty value quarantines the submission silently without consuming quota or firing webhooks).
- `_fr_started_at` — Unix timestamp in milliseconds for minimum-completion timing checks.
- `_fr_turnstile_token` — Cloudflare Turnstile token when Turnstile is enabled on the form.
- `_fr_idempotency_key` — HTML form equivalent of the `Idempotency-Key` header.

### 4. Verify in sandbox before going live

1. Confirm the local dev origin (`http://localhost:<port>`) is added to the form's sandbox **Allowed origins**.
2. Send a valid test submission to `/s/v1/sandbox/{browserSubmissionId}` and confirm HTTP `201` with a `receiptId` (`sub_...`).
3. If strict JSON Schema mode is enabled, also send one deliberately invalid payload and confirm HTTP `422` with `code: "submission_schema_invalid"`.
4. Confirm the accepted lead appears in the FormRoost **Inbox → Sandbox** view.
5. Hand off to the user to add the live HTTPS origin (`https://...`), review the diff, and publish to production in the FormRoost portal.

### 5. Webhook receivers (when requested)

- FormRoost delivers CloudEvents 1.0.2 JSON envelopes signed with **Standard Webhooks** headers: `webhook-id`, `webhook-timestamp`, and `webhook-signature`.
- Verify signatures against the **exact raw request body** using the `standardwebhooks` package (`new Webhook(secret).verify(rawBody, headers)`) before parsing JSON.
- Deduplicate deliveries using `webhook-id` (at-least-once delivery, not strictly ordered).
- Return `2xx` quickly and run slow downstream work asynchronously; production endpoints must use HTTPS and must not rely on redirects.
