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

# MCP Events

> Subscribe an MCP client to connector and Data Sync events, receive them at your callback URL, and verify their signatures.

The StackOne MCP server implements the webhook delivery mode of the official [MCP Events extension](https://modelcontextprotocol.io/extensions/events/overview) ([SEP-3415](https://modelcontextprotocol.io/seps/3415-events-extension)): `events/list`, `events/subscribe` and `events/unsubscribe`. A client subscribes with a callback URL and a signing secret, and StackOne POSTs each event to that URL. ChatGPT supports this mode today. To build your own client and its callback receiver, follow this page. Turning MCP Events on, choosing which events a connection gets and revoking subscriptions are covered in [MCP Events](https://docs.stackone.com/connect/mcp-events.md) in the Gateway tab.

```mermaid theme={null}
sequenceDiagram
    participant C as Your MCP client
    participant S as StackOne MCP
    participant R as Your callback URL
    participant P as Provider or Data Sync

    C->>S: events/list
    S-->>C: Events per account, with payload schemas
    C->>S: events/subscribe (url, whsec_ secret, ttlMs)
    S->>R: Signed verification challenge
    R-->>S: Echoes the challenge
    S-->>C: Subscription id and refreshBefore
    P->>S: A record is added, updated or removed
    Note over S: Re-checks the connection's access
    S->>R: Signed POST with identifiers only
    C->>S: tools/call to read the record
```

The same mechanism carries two kinds of event:

* **Native events** come from the provider's own webhooks and arrive in real time.
* **Data Sync events** come from [Data Sync](https://docs.stackone.com/optimize/data-sync/overview) runs, which are scheduled, as often as every 15 minutes for actions that sync incrementally. They cover systems that send no webhooks.

Both are listed by `events/list` and subscribed to with `events/subscribe`, and both deliver the same identifiers-only payload.

Events are offered when all of these hold:

* **MCP Events** is on for the project.
* The client connects with a session token, such as a token URL, through OAuth, or with a user's personal API key. A request authenticated with a project API key gets no events.
* The client speaks MCP over HTTP to `https://api.stackone.com/mcp` or `https://mcp.stackone.com/mcp`.

> [!NOTE]
>
> A backend that can't act as an MCP Events client, or that calls StackOne with a project API key, receives the same native and Data Sync events through a [webhook](https://docs.stackone.com/connect/webhooks.md) in your project. See [Data Sync events](https://docs.stackone.com/optimize/data-sync/events.md) for the Data Sync side.

## Discover events

When events are on, the `initialize` result advertises them:

```json theme={null}
{
  "capabilities": {
    "tools": {},
    "events": {}
  }
}
```

`events/list` returns the events the connection can subscribe to, 50 per page. Pass the `nextCursor` from one page as `cursor` to get the next:

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "events/list",
  "params": {}
}
```

For example, a Data Sync event available on two Linked Accounts:

```json theme={null}
{
  "resultType": "complete",
  "events": [
    {
      "name": "humaans_list_people.added",
      "description": "A record was added since the last sync of humaans_list_people. Syncs run every 15 minutes, so events arrive up to that late. Pass account_id: one of acc_1a2b, acc_3c4d (stackone_list_accounts gives their names).",
      "delivery": ["webhook"],
      "inputSchema": {
        "type": "object",
        "properties": {
          "account_id": {
            "type": "string",
            "enum": ["acc_1a2b", "acc_3c4d"],
            "description": "The connected account to receive this event from."
          }
        },
        "required": ["account_id"],
        "additionalProperties": false
      },
      "payloadSchema": {
        "type": "object",
        "properties": {
          "account_id": { "type": "string" },
          "connector": { "type": "string" },
          "record_type": { "type": "string" },
          "record_id": { "type": "string" },
          "change": { "type": "string", "const": "added" }
        },
        "required": ["account_id", "connector", "record_type", "record_id", "change"]
      }
    }
  ]
}
```

Native events are named by the connector's event ID. Data Sync events are named `{action_id}.added`, `{action_id}.updated` or `{action_id}.removed`. See [What an agent can subscribe to](https://docs.stackone.com/connect/mcp-events.md#what-an-agent-can-subscribe-to) for when each is offered.

`account_id` is the only argument. It is optional, with a `default`, when the session token is bound to one Linked Account or the event is available on only one. Otherwise it is required, and the description lists the choices.

## Subscribe

`events/subscribe` takes the event, its arguments, the callback and a lifetime:

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "events/subscribe",
  "params": {
    "name": "humaans_list_people.added",
    "arguments": { "account_id": "acc_1a2b" },
    "delivery": {
      "mode": "webhook",
      "url": "https://agents.example.com/stackone/events",
      "secret": "whsec_<BASE64_SECRET>"
    },
    "ttlMs": 3600000
  }
}
```

| Field | Rules |
| - | - |
| `delivery.mode` | `webhook`, the only mode supported |
| `delivery.url` | `https`, with a hostname rather than an IP address and no credentials in it. A fragment is dropped |
| `delivery.secret` | `whsec_` followed by the base64 of 24 to 64 random bytes |
| `ttlMs` | Lifetime in milliseconds, clamped to between 5 minutes and 24 hours. Omitted means 1 hour, and `null` means 24 hours. Never runs past the session token's expiry, or the end of an OAuth grant |
| `cursor` | Not supported. Events missed before the subscription can't be replayed, so a non-null cursor is ignored and the result reports `truncated: true` |

Before saving the subscription, StackOne verifies the callback URL. See [Answer the verification request](#answer-the-verification-request).

The result names the subscription and when to renew it:

```json theme={null}
{
  "resultType": "complete",
  "id": "sub_0123456789abcdef01234567",
  "refreshBefore": "2026-11-19T15:00:00.000Z",
  "cursor": null,
  "truncated": false
}
```

### Renew a subscription

A subscription is identified by the connection, the callback URL, the event name and its arguments, so calling `events/subscribe` again with the same four renews it rather than creating a second one. Renew before `refreshBefore`, or the subscription expires.

A renewal's result adds `deliveryStatus`, the subscription's state before the call:

```json theme={null}
"deliveryStatus": {
  "active": false,
  "lastDeliveryAt": "2026-11-19T12:41:07.000Z",
  "lastError": "http_5xx",
  "failedSince": "2026-11-19T12:44:10.000Z"
}
```

* `active` is `false` when deliveries had failed for an hour and the subscription was switched off. The renewal switches it back on.
* `lastError` is one of `connection_refused`, `timeout`, `tls_error`, `http_4xx`, `http_5xx` or `challenge_failed`.
* A renewal with a different `secret` rotates it. Deliveries are signed with both the new and the old secret for 10 minutes.

### Unsubscribe

`events/unsubscribe` takes the same `name`, `arguments` and `delivery.url` as the subscription. It returns an empty result whether or not the subscription existed:

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 4,
  "method": "events/unsubscribe",
  "params": {
    "name": "humaans_list_people.added",
    "arguments": { "account_id": "acc_1a2b" },
    "delivery": { "url": "https://agents.example.com/stackone/events" }
  }
}
```

### Errors

| Code | Name | Returned when |
| - | - | - |
| `-32602` | InvalidParams | An argument, the URL, the secret, `ttlMs` or a cursor is invalid, or the event isn't available on the named account |
| `-32023` | NotFound | No event by that name is available to the connection |
| `-32024` | Forbidden | The named account isn't available to the connection |
| `-32025` | ResourceExhausted | The connection has 100 subscriptions or the project 1,000 (`data.limit` names which), or the callback host has had 10 verification requests in the last minute |
| `-32026` | Unsupported | `delivery.mode` isn't `webhook` |
| `-32027` | CallbackEndpointError | The callback URL failed verification. `data.reason` is `challenge_failed`, `timeout`, `connection_refused`, `http_4xx` or `http_5xx` |

## Build the callback receiver

Every request StackOne sends to the callback URL is a signed JSON `POST` with these headers:

| Header | Value |
| - | - |
| `webhook-id` | The message ID. The same on every retry of one delivery |
| `webhook-timestamp` | Unix seconds when this attempt was signed |
| `webhook-signature` | `v1,` and the base64 HMAC-SHA256 signature. Space-separated when two secrets are signing during a rotation |
| `x-mcp-subscription-id` | The subscription's `id` |

StackOne doesn't follow redirects, and waits 10 seconds for a response (5 seconds for a verification request).

### Verify the signature

The signature follows [Standard Webhooks](https://www.standardwebhooks.com/): an HMAC-SHA256 over `{webhook-id}.{webhook-timestamp}.{raw body}`, keyed with the bytes of the secret after `whsec_`, base64-decoded. Accept the request if any signature in the header matches.

Each attempt, retries included, is signed with the time it was sent. Reject a `webhook-timestamp` more than a few minutes from your clock, so a captured request can't be replayed later.

For example:

```typescript TypeScript theme={null}
import { createHmac, timingSafeEqual } from 'node:crypto';

const TOLERANCE_SECONDS = 5 * 60;

export function isSignatureValid(
  headers: Record<string, string | undefined>,
  rawBody: string,
  secret: string,
): boolean {
  const timestamp = Number(headers['webhook-timestamp']);
  if (!headers['webhook-id'] || !Number.isInteger(timestamp) || Math.abs(Date.now() / 1000 - timestamp) > TOLERANCE_SECONDS) {
    return false;
  }

  const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
  const signedContent = `${headers['webhook-id']}.${headers['webhook-timestamp']}.${rawBody}`;
  const expected = Buffer.from(createHmac('sha256', key).update(signedContent).digest('base64'));

  return (headers['webhook-signature'] ?? '').split(' ').some((entry) => {
    const [version, signature] = entry.split(',');
    const received = Buffer.from(signature ?? '');
    return version === 'v1' && received.length === expected.length && timingSafeEqual(received, expected);
  });
}
```

```python Python theme={null}
import base64
import hashlib
import hmac
import time

TOLERANCE_SECONDS = 5 * 60


def is_signature_valid(headers: dict, raw_body: bytes, secret: str) -> bool:
    message_id = headers.get("webhook-id")
    raw_timestamp = headers.get("webhook-timestamp", "")
    if not message_id:
        return False
    try:
        timestamp = int(raw_timestamp)
    except ValueError:
        return False
    if abs(time.time() - timestamp) > TOLERANCE_SECONDS:
        return False

    key = base64.b64decode(secret.removeprefix("whsec_"))
    signed_content = f"{message_id}.{raw_timestamp}.".encode() + raw_body
    expected = base64.b64encode(hmac.new(key, signed_content, hashlib.sha256).digest()).decode()

    for entry in headers.get("webhook-signature", "").split(" "):
        version, _, signature = entry.partition(",")
        if version == "v1" and hmac.compare_digest(signature.encode(), expected.encode()):
            return True
    return False
```

The Standard Webhooks libraries make both checks for you.

### Answer the verification request

When a client subscribes, StackOne sends the callback URL a verification request before saving the subscription:

```json theme={null}
{ "type": "verification", "challenge": "c2b4f1e0a9d8" }
```

Return a `2xx` response within 5 seconds whose JSON body echoes the challenge:

```json theme={null}
{ "challenge": "c2b4f1e0a9d8" }
```

A callback URL that passes isn't verified again for the same connection for 24 hours.

### Handle events

Each event is its own request:

```json theme={null}
{
  "eventId": "8f14e45f-ceea-467f-a0e6-1b5c7f1d9a20",
  "name": "humaans_list_people.added",
  "timestamp": "2026-11-19T14:02:11.000Z",
  "data": {
    "account_id": "acc_1a2b",
    "connector": "humaans",
    "record_type": "humaans_list_people",
    "record_id": "4127",
    "change": "added"
  },
  "cursor": null
}
```

* `data` carries identifiers only. Read the record with a tool call, such as the action named in `record_type` or its `_s1query` copy.
* For a native event, `change` is the event name and `record_type` is the connector's event type.
* Return `2xx` to acknowledge. A delivery that gets any other response is tried up to 5 times over about 15 minutes. A `4xx` other than `408`, `425` and `429` isn't retried, and a `Retry-After` on a `429` or `503` is honored within that window.
* A delivery can arrive more than once, so deduplicate on `webhook-id`. Events aren't guaranteed to arrive in order.

### Handle terminated

When the connection loses access to the event, StackOne sends one final message and deletes the subscription:

```json theme={null}
{
  "type": "terminated",
  "error": {
    "code": -32024,
    "message": "Forbidden",
    "data": { "reason": "event_not_granted" }
  }
}
```

| `reason` | Why |
| - | - |
| `setting_off` | MCP Events was turned off for the project |
| `access_revoked` | The OAuth grant or token was revoked, or the grant expired |
| `session_ended` | The session token expired |
| `account_removed` | The Linked Account was unlinked, disabled or removed from the connection |
| `event_not_granted` | The event, or a Data Sync event's action, was removed from the connection |
| `policy_denied` | A runtime policy stopped the connection running a Data Sync event's action |
| `event_unavailable` | The Data Sync event's sync schedule was deleted |

Stop renewing a terminated subscription. A renewal is checked like a new subscription, so it fails until access is restored.

## Scope events on a session token

A session token minted with `scopes` receives only the events its permissions allow. Events are granted by a rule whose `actions` holds `events` alone, with the accounts named by ID:

```json theme={null}
{
  "permissions": [
    {
      "id": "tools",
      "effect": "allow",
      "resources": { "accounts": ["acc_1a2b"] },
      "actions": { "tools": ["humaans_list_people", "humaans_get_person"] }
    },
    {
      "id": "events",
      "effect": "allow",
      "resources": { "accounts": ["acc_1a2b"] },
      "actions": { "events": ["humaans_list_people.*"] }
    }
  ]
}
```

* `events` takes glob patterns or `"*"`, matched against event names. A `deny` rule removes events an `allow` rule matched.
* When the scope has permissions, an account with no events rule gets no events. A token with no scopes gets every event on its accounts.
* An events rule grants no tools. A Data Sync event also needs its action, or the action's `_s1query` copy, allowed by a tools rule on the same account.

## Manage subscriptions from your backend

Your backend can list and revoke the project's subscriptions with your API key:

* [List agent event subscriptions](https://docs.stackone.com/platform/api-reference/v2/mcp/list-agent-event-subscriptions.md) returns them newest first, filtered by Linked Account, OAuth client, user or credential.
* [Revoke an agent event subscription](https://docs.stackone.com/platform/api-reference/v2/mcp/revoke-an-agent-event-subscription.md) deletes one by its `sub_` ID.

For example, to list the subscriptions on one Linked Account, with `STACKONE_API_KEY` set to your API key (`v1.eu1.xxxxx`):

```typescript TypeScript theme={null}
const response = await fetch(
  "https://api.stackone.com/v2/mcp_event_subscriptions?account_id=<ACCOUNT_ID>",
  { headers: { Authorization: `Basic ${btoa(`${process.env.STACKONE_API_KEY}:`)}` } },
);
const subscriptions = await response.json();
```

```python Python theme={null}
import os
import requests

response = requests.get(
    "https://api.stackone.com/v2/mcp_event_subscriptions",
    params={"account_id": "<ACCOUNT_ID>"},
    auth=(os.environ["STACKONE_API_KEY"], ""),
)
subscriptions = response.json()
```

A revoked subscription gets no `terminated` event, and the agent can subscribe again while it still has access. To stop an agent receiving events for good, remove its access to the account or the event.

## Next steps

> [card] [MCP](https://docs.stackone.com/embed/call-actions/mcp)
>
> Connect to the MCP server and call tools.

> [card] [Data Sync events](https://docs.stackone.com/optimize/data-sync/events.md)
>
> When Data Sync events are produced, and what `removed` means.

> [card] [Webhooks](https://docs.stackone.com/connect/webhooks.md)
>
> Receive the same events in your backend, without an MCP client.

> [card] [ChatGPT](https://docs.stackone.com/ai-platforms/openai/overview.md#chatgpt)
>
> Connect ChatGPT, which supports MCP Events, to StackOne.


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