# Events

MCP Events extension (`io.modelcontextprotocol/events`), MCP 2026-07-28 clients only. Needs scope `tl:read`.

Every modern request to `POST https://trustline.app/api/mcp` sends these headers:

```
Authorization: Bearer <token>
Content-Type: application/json
Accept: application/json, text/event-stream
MCP-Protocol-Version: 2026-07-28
Mcp-Method: <method>
Mcp-Name: <params.name>
```

and `"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientCapabilities":{}}` in `params`.

## Types (`events/list`)

`envelope.sent`, `envelope.viewed` (a signer first opened it), `envelope.signed` (a signer signed), `envelope.completed`, `envelope.voided`, `envelope.declined`, and `envelope.lifecycle` (all of them). Arguments: `{envelopeId?}` on every type; `envelope.lifecycle` also takes `events?: [names]`. Delivery: poll, push, webhook.

## Poll (`events/poll`)

```json
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "events/poll",
  "params": {
    "name": "envelope.lifecycle",
    "arguments": { "envelopeId": "env_..." },
    "cursor": null,
    "_meta": { "io.modelcontextprotocol/protocolVersion": "2026-07-28", "io.modelcontextprotocol/clientCapabilities": {} }
  }
}
```

Header `Mcp-Name: envelope.lifecycle`. Optional params: `maxAgeMs`, `maxEvents` (up to 200). Result:

```json
{
  "events": [
    {
      "eventId": "env_....2",
      "name": "envelope.lifecycle",
      "timestamp": "...",
      "data": { "envelopeId": "env_...", "title": "...", "status": "sent", "at": "...", "event": "envelope.sent" }
    }
  ],
  "cursor": "c1...",
  "truncated": false,
  "hasMore": false,
  "nextPollMs": 5000
}
```

- `data`: `{envelopeId, title, status, at, signer?:{email,name}, event?}`. `event` (the type name) is only on `envelope.lifecycle`.
- `eventId` is `<envelope id>.<seq>`: stable, use it to deduplicate.
- Cursors: `null` starts from now. Pass back the returned `cursor` on the next call, after `nextPollMs`. `hasMore: true`: call again at once. `truncated: true`: older events fell outside the replay window and were skipped; check `tl_read status`.

## Push (`events/stream`)

Same params as poll; the answer is SSE: `notifications/events/active`, then `notifications/events/event` and heartbeats. The server closes after about 45 s; reconnect with the last cursor.

## Webhook (`events/subscribe`)

`params.delivery: {url, secret}`: `url` https, `secret` = `whsec_` + base64 of 24-64 random bytes.

- Verification: your endpoint gets a POST `{"type":"verification","challenge":"..."}` and must answer `{"challenge":"..."}` with the same value.
- Each delivery carries Standard Webhooks headers `webhook-id`, `webhook-timestamp`, `webhook-signature` (`v1,` + base64 HMAC-SHA256 of `"<webhook-id>.<webhook-timestamp>.<raw body>"`, keyed with the base64-decoded bytes after `whsec_`) and `X-MCP-Subscription-Id`.
- TTL up to 24 h. Call `events/subscribe` again to refresh. `events/unsubscribe` stops it.

## Legacy clients

Clients that use `initialize` (2025-11-25 and older) cannot use events. Poll `tl_read {op:"status", args:{id}}` (at most once a minute) or register an account webhook: [webhooks.md](webhooks.md).
