> ## Documentation Index
> Fetch the complete documentation index at: https://docs.widgetic.com/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP events

> Be called when a visitor sends an entry (a vote, an RSVP, a form answer) into one of your published widgets

When a visitor sends an entry into one of your published widgets (a vote, an RSVP, a form answer), Widgetic can call your server. You ask once, over [MCP](https://docs.widgetic.com/docs/agents/overview.md), with `events/subscribe`. From then on each entry is announced to the address you gave, with a signed `POST`. The call says which widget and table the entry went to, never what the visitor wrote: your code, or your assistant, reads the entry with the `get_widget_data` tool.

> [!NOTE]
>
> **What is offered.** MCP events follow the [Events extension](https://modelcontextprotocol.io/extensions/events/overview) of the Model Context Protocol. Widgetic offers one event, `submission.created`, and one way to receive it, a webhook. The push mode of the extension (`events/stream`) is not offered, and `events/poll` does not return the `nextPollMs` of the extension.

Any workspace on a plan with API access can use MCP events: you do not have to be a partner. A partner account is also told about the entries of its customers' widgets by the [`entry.created`](https://docs.widgetic.com/api-reference/events/entry-created) webhook.

## What you need

* A workspace on a plan that includes API access.
* A credential that may read. Sign in with Widgetic and approve `widgetic.read`, or use an API key made with full access: see [Authentication](https://docs.widgetic.com/docs/agents/authentication.md).
* The `composition_id` of a published widget that keeps entries. `list_widgets` and `get_widget` return it, and in the REST API it is the `id` of the composition. A widget made to gather what visitors send (a poll, a rating, a sign-up) keeps entries.
* An address that takes a `POST`, on the same terms as a [partner webhook](https://docs.widgetic.com/docs/webhooks/partner-webhooks.md#set-up-a-webhook): `https`, on the standard port, with no user name or password in it, the name of a public website, and no redirect.

## How it works

**1. Subscribe**

Call `events/subscribe` on `https://mcp.widgetic.com` with the widget, your address and a signing secret that you make.

**2. Answer the check**

Before it delivers anything, Widgetic sends your address a signed call with a `challenge`. Your address gives the same `challenge` back.

**3. Receive the entries**

Each entry sent to the widget is announced to your address, once. Check the signature, drop an event you already handled, and answer with a `2xx`.

**4. Read the entry**

The call names the widget and the table, and the entry's id when it has one. Read what was sent with `get_widget_data`, or with the entries routes of the REST API, such as `GET /compositions/{id}/entries/{table}/items`.

**5. Refresh before it ends**

A subscription lasts 7 days unless you ask for another time. Call `events/subscribe` again with the same details before `refreshBefore` to keep it.

## Subscribe

Make a secret first: `whsec_` and the base64 of 24 to 64 random bytes. Keep it where your receiver can read it.

```bash theme={"theme":"css-variables"}
echo "whsec_$(openssl rand -base64 32)"
```

Then subscribe. The MCP endpoint takes JSON-RPC over `POST`, and a request has to send both `Content-Type: application/json` and `Accept: application/json, text/event-stream`. The answer is a single JSON document.

```bash theme={"theme":"css-variables"}
curl -sS https://mcp.widgetic.com \
  -H "Authorization: Bearer $WIDGETIC_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  --data @- <<EOF
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "events/subscribe",
  "params": {
    "name": "submission.created",
    "arguments": {
      "composition_id": "11111111-1111-4111-8111-111111111111",
      "table": "votes"
    },
    "delivery": {
      "mode": "webhook",
      "url": "https://yourcompany.com/widgetic/mcp-events",
      "secret": "$WIDGETIC_MCP_EVENTS_SECRET"
    }
  }
}
EOF
```

```json theme={"theme":"css-variables"}
{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "resultType": "complete",
    "id": "sub_3f9a1c7e5b2d4a6c8e0f1b3d5a7c9e2b",
    "refreshBefore": "2026-11-17T09:30:00.000Z",
    "cursor": "128",
    "truncated": false
  }
}
```

| Parameter | What it does |
| - | - |
| `name` | The event: `submission.created`. `events/list` returns the events you may subscribe to, with the schema of their arguments and of what they carry |
| `arguments.composition_id` | The widget to watch. Required |
| `arguments.table` | Only the entries sent to this table. Leave it out to be told about every table of the widget |
| `delivery.mode` | `webhook`, the only mode Widgetic offers |
| `delivery.url` | Where the calls go |
| `delivery.secret` | The secret that signs the calls. Required. A new secret on an existing subscription is used at once, and the old one signs beside it for 10 minutes |
| `ttlMs` | How long you want the subscription to last, in milliseconds: at least 1 hour, at most 30 days. Leave it out for 7 days. `null` asks for the longest. Widgetic grants the closest lifetime it allows, and `refreshBefore` says which |
| `cursor` | Where to start from: see [Catch up on what you missed](#catch-up-on-what-you-missed) |

| Field of the answer | What it holds |
| - | - |
| `id` | The id of the subscription: `sub_` and 32 hexadecimal characters. It is worked out from your account, the address, the event and its arguments, so subscribing again with the same details refreshes the same subscription instead of adding another |
| `refreshBefore` | When the subscription ends if you do not refresh it, in ISO 8601 and UTC |
| `cursor` | Where you are in the log of events. A first subscription starts now |
| `truncated` | `true` when the cursor you sent could not be honoured completely |

## Check the address

The first time you subscribe with an address and a secret, Widgetic sends the address a call before it delivers anything:

```http theme={"theme":"css-variables"}
POST /widgetic/mcp-events HTTP/1.1
Host: yourcompany.com
Content-Type: application/json
User-Agent: WidgeticMcpEvents/1.0 (+https://widgetic.com)
webhook-id: msg_verification_9d2c4e6f8a0b4c1d9e3f5a7b1c2d4e6f
webhook-timestamp: 1794302990
webhook-signature: v1,fkBLRbYGFMFKaV1QSECu+Cqtufu6T/NR6L6A5q2I5ic=
x-mcp-subscription-id: sub_3f9a1c7e5b2d4a6c8e0f1b3d5a7c9e2b

{"type":"verification","challenge":"r7Qm1h8n0Wc5Yt3bZk2Xv9LdPe4JaUoS"}
```

Check its signature like any other call, then answer with a `2xx` and the same challenge, as JSON, within 5 seconds:

```json theme={"theme":"css-variables"}
{ "challenge": "r7Qm1h8n0Wc5Yt3bZk2Xv9LdPe4JaUoS" }
```

A success for the same address and secret is remembered for 10 minutes, so refreshing a subscription does not send the check again at once. When the check fails, `events/subscribe` answers with the error `-32015` and says why in `data.reason`: see [Errors](#errors).

## Deliveries

Each entry is announced with a signed `POST` to your address. This is one as it arrives:

```http theme={"theme":"css-variables"}
POST /widgetic/mcp-events HTTP/1.1
Host: yourcompany.com
Content-Type: application/json
User-Agent: WidgeticMcpEvents/1.0 (+https://widgetic.com)
webhook-id: evt_7b1d4f0a9c2e4d6f8a3b5c7d9e1f2a4b
webhook-timestamp: 1794303000
webhook-signature: v1,MCd1i1SGRUSzYC6YHjaJ+wOiGLPOhuuv/fMPrbBg10k=
x-mcp-subscription-id: sub_3f9a1c7e5b2d4a6c8e0f1b3d5a7c9e2b
```

```json theme={"theme":"css-variables"}
{
  "eventId": "evt_7b1d4f0a9c2e4d6f8a3b5c7d9e1f2a4b",
  "name": "submission.created",
  "timestamp": "2026-11-10T09:30:00.000Z",
  "data": {
    "composition_id": "11111111-1111-4111-8111-111111111111",
    "table": "votes",
    "read_with": "get_widget_data",
    "entry_id": "42"
  },
  "cursor": "128"
}
```

Widgetic sends the body as one line, without spaces, and the signature covers exactly those bytes. The signatures above are made with the example secret of [Verify signatures](https://docs.widgetic.com/docs/webhooks/verify-signatures.md#check-your-code-against-a-known-call).

| Header | What it holds |
| - | - |
| `webhook-id` | The event's `eventId`. It is the same for every retry and every replay, so use it to drop an event you already handled |
| `webhook-timestamp` | When the call was signed, in seconds since 1970 |
| `webhook-signature` | `v1,` and the base64 HMAC-SHA256 of `<webhook-id>.<webhook-timestamp>.<the raw body>`, under your secret. Two signatures, separated by a space, while a changed secret overlaps with the old one |
| `x-mcp-subscription-id` | The `id` that `events/subscribe` returned. A receiver that serves several subscriptions can pick the right secret with it before it reads the body |
| `user-agent` | `WidgeticMcpEvents/1.0 (+https://widgetic.com)` |
| `content-type` | `application/json` |

| Field of the body | What it holds |
| - | - |
| `eventId` | The id of the event: the same as the `webhook-id` header |
| `name` | The event: `submission.created` |
| `timestamp` | When the entry was announced, in ISO 8601 and UTC |
| `data.composition_id` | The widget the entry was sent to |
| `data.table` | The table that holds the entry |
| `data.read_with` | The tool that reads the entries: `get_widget_data` |
| `data.entry_id` | The id of the entry, when it has one that is safe to pass on: letters, digits, `-` and `_` |
| `cursor` | Where this event is in the log. Save it: see [Catch up on what you missed](#catch-up-on-what-you-missed) |

A call never holds anything a visitor wrote. What a visitor types is untrusted text, and an event can be handed to a model without a person reading it first, so the call carries only ids and names.

### Answer and retries

| Your address answers | What Widgetic does |
| - | - |
| A `2xx` status | The delivery is done |
| `410 Gone` | The subscription is removed |
| `413 Payload Too Large` | The delivery ends, with no more tries |
| Anything else: another status, a redirect, no answer within 10 seconds, or no connection | The call is tried again: 3 more times, after 2 seconds, 15 seconds and 1 minute 30 seconds |

Delivery is **at least once**: keep the `eventId`s you handled and drop a repeat. After 20 failed deliveries in a row, Widgetic removes the subscription. A delivery fails when the first try and every retry failed. For one subscription, at most 60 events a minute are sent: the rest are not sent, and stay in the log, where you can catch up with them.

Before every delivery Widgetic checks again that the permission, the plan and the ownership of the widget still hold. If they do not, the subscription is removed and nothing is sent.

### Which entries are announced

An event is raised for each entry that is stored in a widget somebody watches:

* an entry that a visitor sends from the published widget, with `POST /embed/compositions/{compositionId}/entries/{table}`;
* a record that you add with the API, with `POST /compositions/{id}/database/{table}`.

It is raised once for each entry, however it was stored. A row that another system writes straight into a database raises no event, except for a partner: the rows its own system writes into its customers' widgets are announced within about five minutes, when its `entry.created` webhook is on.

Several assistants or services can watch the same widget. Each subscription has its own address, secret and lifetime.

## Receive the calls

This Express receiver keeps the body as it arrived, checks it, answers the check of the address, drops an event it has already handled, and answers quickly. It uses the `verifyWidgeticWebhook` function of [Verify signatures](https://docs.widgetic.com/docs/webhooks/verify-signatures.md#check-a-call), which checks both kinds of call.

```typescript theme={"theme":"css-variables"}
import express from 'express';
import { verifyWidgeticWebhook } from './verifyWidgeticWebhook';

const app = express();
const handledEventIds = new Set<string>(); // Use your database in production

// Keep the body as bytes: the signature covers exactly what was sent.
app.post('/widgetic/mcp-events', express.raw({ type: 'application/json' }), (request, response) => {
  const rawBody: Buffer = request.body;

  try {
    verifyWidgeticWebhook(
      rawBody,
      request.header('webhook-id'),
      request.header('webhook-timestamp'),
      request.header('webhook-signature'),
      process.env.WIDGETIC_MCP_EVENTS_SECRET ?? '',
    );
  } catch (error) {
    console.warn('Rejected a call to /widgetic/mcp-events:', error instanceof Error ? error.message : error);
    return response.status(400).send('Invalid signature');
  }

  const message = JSON.parse(rawBody.toString('utf8'));

  // The check Widgetic makes before it delivers anything: give the challenge back.
  if (message.type === 'verification') {
    return response.status(200).json({ challenge: message.challenge });
  }

  // Delivery is at least once, so the same event can arrive again with the same id.
  if (handledEventIds.has(message.eventId)) {
    return response.status(200).send('Already handled');
  }
  handledEventIds.add(message.eventId);

  if (message.name === 'submission.created') {
    const { composition_id: compositionId, table, entry_id: entryId } = message.data;
    console.log(`A visitor sent entry ${entryId ?? '(no id)'} to ${table} of widget ${compositionId}`);
    // Read what was sent with get_widget_data, and save message.cursor next to your data.
  }

  return response.status(200).send('ok');
});
```

## Catch up on what you missed

Before it announces an entry, Widgetic writes the ids and names of the event, never what a visitor wrote, to a log that it keeps for 14 days. Every delivery carries a `cursor`, the place of the event in that log. Save the last one you handled, and use it to get what came after it.

* **`events/subscribe` with a `cursor`.** The events after it are sent to your address again, oldest first, with the `eventId` and the `timestamp` they had, right after the answer: at most 100 at a time. The `cursor` of the answer is the place just before the first of them, so if the replay is lost on its way, saving it gets you the same events again. Subscribe again with the cursor you saved after each restart, and each time you refresh.
* **`events/poll`.** It returns the events after a cursor in the answer, for a client that cannot be called, or that wants to check. It needs the `name`, the `arguments` and the `delivery` of a subscription you hold, `cursor`, and `maxEvents` (at most 100). It answers `events`, each with its own `cursor`, the `cursor` to use next, `hasMore` and `truncated`.

```bash theme={"theme":"css-variables"}
curl -sS https://mcp.widgetic.com \
  -H "Authorization: Bearer $WIDGETIC_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Accept: application/json, text/event-stream" \
  --data @- <<EOF
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "events/poll",
  "params": {
    "name": "submission.created",
    "arguments": {
      "composition_id": "11111111-1111-4111-8111-111111111111",
      "table": "votes"
    },
    "delivery": {
      "mode": "webhook",
      "url": "https://yourcompany.com/widgetic/mcp-events"
    },
    "cursor": "128",
    "maxEvents": 50
  }
}
EOF
```

```json theme={"theme":"css-variables"}
{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "resultType": "complete",
    "events": [
      {
        "eventId": "evt_c3a9e1f07d2b4a58b6e4f0a1d2c3b4e5",
        "name": "submission.created",
        "timestamp": "2026-11-10T09:41:12.000Z",
        "data": {
          "composition_id": "11111111-1111-4111-8111-111111111111",
          "table": "votes",
          "read_with": "get_widget_data",
          "entry_id": "43"
        },
        "cursor": "129"
      }
    ],
    "cursor": "129",
    "hasMore": false,
    "truncated": false
  }
}
```

A few things to know:

* With no `cursor`, a first subscription starts now: it is not handed what happened before it.
* `truncated: true` says that the cursor you sent is not one of Widgetic's, is newer than the log, or is older than the oldest event it still holds: some events may be missing. Read the entries with `get_widget_data` to see where things stand.
* The log holds the events of a widget while an unexpired subscription watches it. If yours lapses because you did not refresh it in time, nothing is kept for that time, and your next `events/subscribe` starts from now.
* An event that is waiting for a retry when Widgetic restarts is not lost: it is in the log, and the cursor you saved gets it again.
* `events/poll` does not recommend how often to poll (the `nextPollMs` of the extension), so choose an interval of your own.

## Stop

Call `events/unsubscribe` with the `name`, the `arguments` and the `delivery` of the subscription (`mode` and `url`, without the secret). It answers with success whether or not the subscription existed, so a second call does no harm. A subscription you stop refreshing ends by itself at `refreshBefore`.

## Limits

| What | Limit |
| - | - |
| Subscriptions | 50 for one account, and 25 for one widget |
| How long a subscription lasts | 7 days unless you ask for another with `ttlMs`: at least 1 hour, at most 30 days. `refreshBefore` in the answer says when it ends |
| Time your address has to answer | 10 seconds for an event, 5 seconds for the verification call |
| Tries for an event | The first, and 3 retries after 2 seconds, 15 seconds and 1 minute 30 seconds |
| Failed deliveries that end a subscription | 20 in a row (a delivery fails when the first try and every retry failed) |
| Events for one subscription | At most 60 a minute; more are dropped, not queued |
| Size of a call | At most 256 KiB; a call is much smaller |
| Size of your answer | Widgetic reads at most 16 KiB of it |
| Your secret | `whsec_` and a base64 key of 24 to 64 bytes. A new secret on an existing subscription is used at once, and the old one signs beside it for 10 minutes |
| The log of events | Kept 14 days. One `events/subscribe` sends at most 100 missed events again, and `events/poll` returns at most 100 |

## Errors

An event method answers a refusal with HTTP `200` and a JSON-RPC `error`, whose `code` is one of these.

| Code | When | What to do |
| - | - | - |
| `-32602` | The request is not valid: an unknown event, a `composition_id` that is not a widget of this account (a widget that does not exist and one that belongs to someone else look the same), an address or a secret that does not meet the rules above, a `ttlMs` that is not a positive number or `null`, an account that already holds the most subscriptions, or an `events/poll` without a matching subscription. `data.reason` is `invalid_url` for an address that is refused | Correct the request |
| `-32010` | The connection was not approved to read widgets | Connect again and approve `widgetic.read`, or use an API key made with full access |
| `-32015` | Widgetic could not check your address. `data.reason` says why: `timeout`, `redirect`, `bad_status` (not a `2xx`), `challenge_failed` (the answer did not give the challenge back), `invalid_url`, or `unreachable` | Mend the receiver, and subscribe again |
| `-32016` | Events are not available just now | Try again shortly |
| `-32601` | The server does not offer events just now: they are switched off | Read the entries with the REST API until they are back |

The endpoint answers the other problems with an HTTP status: `401` for no credential or one that is not valid, `403` when the plan has no API access or the key is limited, `406` when `Accept` does not list both `application/json` and `text/event-stream`, `413` for a body over 1 MiB, and `429` for too many requests. See [Errors at the door](https://docs.widgetic.com/docs/agents/build-a-client.md#at-the-door).

> [card] [Verify signatures](https://docs.widgetic.com/docs/webhooks/verify-signatures.md)
>
> Check a call in TypeScript, Python, Go, Java, C#, Ruby or PHP.

> [card] [AI agents (MCP)](https://docs.widgetic.com/docs/agents/overview.md)
>
> Connect an assistant and build widgets from a conversation.

> [card] [Event reference](https://docs.widgetic.com/api-reference/events/submission-created.md)
>
> The call of `submission.created` and the check of your address.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.