# AI Agents & MCP Server

BlokForms ships with a stateless **Streamable HTTP Model Context Protocol (MCP)** server at `https://api.blokforms.com/mcp`. Every tool executes directly against the same EU domain services as the Management REST API with scoped RBAC permissions.

## Machine-Readable Discovery Files

Point any AI coding agent or autonomous workflow at these URLs:

- `https://blokforms.com/llms.txt` (concise directory of docs, API, SDK, and MCP endpoints)
- `https://blokforms.com/llms-full.txt` (complete self-contained Markdown reference in one fetch)
- `https://blokforms.com/skill/SKILL.md` (drop-in Agent Skill file for coding agents)
- `https://blokforms.com/docs/<slug>.md` or send `Accept: text/markdown` to any `/docs/*` route
- `https://api.blokforms.com/api/v1/openapi.json` (live OpenAPI 3.1 JSON schema)

## Authentication (Personal Access Token)

1. Open `https://app.blokforms.com/organization` and select **Developers & API**.
2. Create a **Personal Access Token** (`bf_pat_...`) with the scopes your agent needs:
   - `forms:read`, `forms:manage`
   - `submissions:read`, `submissions:manage`
   - `webhooks:manage`, `tokens:manage`
3. Pass `Authorization: Bearer bf_pat_...` to `https://api.blokforms.com/mcp`.

> **Security note:** Interactive `org.manage` operations (rotating Mollie/Stripe API keys and mutating custom domains) require an authenticated browser session and intentionally reject PATs with HTTP `403`.

## Client Configuration Examples

### Claude Code CLI

```bash
claude mcp add --transport http blokforms https://api.blokforms.com/mcp \
  --header "Authorization: Bearer bf_pat_YOUR_TOKEN"
```

### Cursor / Windsurf / Antigravity (`mcp.json`)

```json
{
  "mcpServers": {
    "blokforms": {
      "url": "https://api.blokforms.com/mcp",
      "headers": {
        "Authorization": "Bearer bf_pat_YOUR_TOKEN"
      }
    }
  }
}
```

### Raw JSON-RPC Call (curl)

```bash
curl -X POST https://api.blokforms.com/mcp \
  -H "Authorization: Bearer bf_pat_YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  -d '{
    "jsonrpc": "2.0",
    "id": 1,
    "method": "tools/call",
    "params": {
      "name": "generate_form_with_ai",
      "arguments": {
        "prompt": "Dutch consultation booking form with 30-min slots and GDPR consent",
        "locale": "nl"
      }
    }
  }'
```

## Complete Catalog of 32 MCP Tools

### Discovery (5 tools)

| Tool | Required Args | Description |
| --- | --- | --- |
| `list_projects` | none | List all active projects in the organization |
| `get_project` | `projectId` | Get project settings, allowed origins, and defaults |
| `list_forms` | `projectId?` | List forms in the org or a single project |
| `get_form` | `formId` | Get full form schema, fields, settings, theme, and translations |
| `list_form_templates` | none | List all 16 built-in starter templates |

### Authoring & AI Generation (6 tools)

| Tool | Required Args | Description |
| --- | --- | --- |
| `create_project` | `name`, `siteUrl?`, `allowedOrigins?` | Create a new project workspace |
| `generate_form_with_ai` | `prompt`, `locale?` | Generate a validated form blueprint in `en`, `nl`, `de`, or `fr` |
| `create_form` | `projectId`, `name`, `templateId?`, `fields?`, `settings?` | Create a live form from a template or custom field array |
| `update_form` | `formId`, `fields?`, `settings?`, `theme?`, `i18n?`, `active?` | Update form fields, logic, workflow, security, or theme |
| `duplicate_form` | `formId`, `name?` | Clone an existing form inside the same project |
| `delete_form` | `formId` | Permanently delete a form, submissions, and R2 uploads |

### Embedding & Distribution (1 tool)

| Tool | Required Args | Description |
| --- | --- | --- |
| `get_embed_snippets` | `formId` | Generate tailored `<script>`, popup, drawer, `<iframe>`, React `<BlokForm>`, and HTML snippets |

### Inbox, Triage, Analytics & AI Assistant (8 tools)

| Tool | Required Args | Description |
| --- | --- | --- |
| `list_submissions` | `formId?`, `projectId?`, `status?`, `q?`, `limit?` | Search (FTS5) or filter submissions |
| `get_submission` | `submissionId` | Inspect a single submission, notes, and uploaded file metadata |
| `triage_submissions` | `ids[]`, `action`, `assigneeId?` | Bulk mark_read, mark_new, archive, spam, assign, or delete (up to 200) |
| `add_submission_note` | `submissionId`, `body` | Append an internal team note |
| `get_form_stats` | `formId` | Aggregate counts by status and 30-day trend (zero PII) |
| `get_form_analytics` | `formId`, `days?` | Views, starts, conversion rate, step drop-off funnel, UTM, and devices (zero PII) |
| `get_form_visual_report` | `formId` | Anonymized choice distributions, NPS/rating averages, and numeric sums (zero PII) |
| `ask_submissions_ai` | `formId`, `question`, `includePii?` | Ask natural-language questions over responses (PII scrubbed by default) |

### EU Payments & BlokForms Sign (3 tools)

| Tool | Required Args | Description |
| --- | --- | --- |
| `list_form_payments` | `formId` | List Mollie/Stripe transactions and EU revenue totals |
| `list_signature_envelopes` | `formId` | List e-signature envelopes and signer completion states |
| `create_signature_envelope` | `submissionId`, `title`, `documentBody`, `signers[]` | Launch a multi-signer BlokForms Sign ceremony from a submission |

### Approvals, Bookings, Integrations, Webhooks, Audit & GDPR (9 tools)

| Tool | Required Args | Description |
| --- | --- | --- |
| `list_form_approvals` | `formId` | List approval workflow runs and step statuses |
| `decide_approval_step` | `stepId`, `decision` (`approved`/`denied`), `comment?` | Approve or deny a pending workflow step |
| `list_form_bookings` | `formId` | List appointment bookings with `.ics` calendar links |
| `list_form_integrations` | `projectId?`, `formId?` | List Slack/Teams/Notion/Airtable/HubSpot/Sheets/Make connectors (masked) |
| `create_form_integration` | `projectId`, `provider`, `name`, `config`, `events[]` | Create an AES-256-GCM encrypted native integration |
| `list_webhooks` | `projectId?`, `formId?` | List HMAC-SHA256 webhooks |
| `create_webhook` | `projectId`, `name`, `url`, `events[]` | Register a signed webhook endpoint |
| `list_audit_logs` | `action?`, `limit?` | Inspect organization security and management audit logs |
| `erase_submissions_by_email` | `email`, `dryRun?` | GDPR Art. 17 erasure across D1, FTS5, and EU R2 (always call with `dryRun: true` first) |

## Agent Best Practices

1. **Always preview GDPR erasure first:** Call `erase_submissions_by_email` with `{ email, dryRun: true }` and confirm the matched count with the user before passing `dryRun: false`.
2. **Minimize PII exposure:** Prefer `get_form_stats`, `get_form_analytics`, `get_form_visual_report`, or `ask_submissions_ai` (with default `includePii: false`) when answering summary questions.
3. **Validate field ordering:** Any `showIf` condition must reference an input field that appears earlier in the `fields` array.
4. **Use `generate_form_with_ai` as a blueprint:** Generate a valid draft schema, adjust field names or settings if needed, then persist with `create_form`.
