MCP Events
The MCP event catalogue, emitting custom events, subscription lifecycle, delivery and limits.
MCP clients can subscribe to events from your API. This page covers the generated catalogue, emitting your own events, and subscription delivery. Start at The MCP Server for authentication.
MCP Events
ChatGPT's MCP Events lets a user say "watch this project for new tasks and open a draft for each one": ChatGPT subscribes through your MCP server, you POST a signed webhook to its callback when the event fires, and the chat acts on it. agents.mcp.events builds the catalogue and the subscription endpoints; the generated Worker does the rest.
Requires outbound webhooks — webhooksBinding on the database provider — because subscriptions and deliveries live in the webhooks store and ride the webhooks queue. The compile fails without it.
import { defineConfig } from '@quickback/compiler';
export default defineConfig({
name: 'my-api',
// …
agents: {
mcp: {
events: {
// Resource events: <table>.created / .updated / .deleted from every
// write through the audit-wrapped db. Table jsNames, as in feature().
resources: ['tasks', 'comments'],
// Custom events your own code emits with emitMcpEvent().
custom: {
'build.finished': {
description: 'A build finished and its artefacts can be downloaded.',
filters: { project_id: { description: 'Only builds of this project.' } },
payloadSchema: {
type: 'object',
properties: { project_id: { type: 'string' }, build_id: { type: 'string' }, status: { type: 'string' } },
required: ['project_id', 'build_id', 'status'],
},
},
},
// Subscription lifetime bounds (ms). Defaults: 15 min / 24 h / 7 days.
ttl: { minMs: 900_000, defaultMs: 86_400_000, maxMs: 604_800_000 },
},
},
},
});The catalogue
events/list returns one definition per event with inputSchema (the filters a subscription may set) and payloadSchema (the delivered data). It is access-filtered like tools/list.
Resource events. Each table in resources gets <table>.created, <table>.updated and <table>.deleted:
-
Gate. The table's
read.access, evaluated atevents/listand at everyevents/subscribe(including refreshes). A caller who cannot list the table does not see its events and cannot subscribe to them. Org roles are checked against the caller's membership roles; ascope:<kind>:<role>role passes only when the caller's verified scope claim (ctx.scope.<kind>.roles) carries it — exactly REST's check, never "any authenticated caller might hold one" (that guess istools/listvisibility only). -
Which tables qualify. A delivery is matched on the row's organization (or owner) column and nothing else, so the compile refuses a table whose collection read narrows rows below that key — the subscriber would otherwise receive ids, timing and foreign keys for rows its REST list hides:
read.accesswith ascope:role,recordpredicates, arelationshiporfga:arm, or a function;- a firewall arm other than the scope column bound to
ctx.activeOrgId(owner-scoped:ctx.userId), the soft-deleteisNullarm, or{ exception: true }— e.g.via:,permission, team,ctx.scope.*, literal filters, anotherisNullfilter, or an owner arm under an organization key. Anany:group that contains the key arm admits every keyed row and is allowed.
The error names the table and the arm, e.g.
agents.mcp.events.resources: table "tasks" cannot emit MCP events — its firewall has ownerId = ctx.userId, finer than the organizationId key deliveries match on.Remove the table fromresources, or emit a custom event to the right scope from your own code. -
Filters.
idplus every foreign-key column (projectId,documentId, …). The filter values are compared as strings against the written row. -
Scope. The table must be organization- or owner-scoped; a subscription created inside organization
org_1receives onlyorg_1rows, and an owner-scoped subscription receives only the subscriber's rows. A table with neither column fails the compile. -
Payload.
{ id, operation, <scope column>, <foreign keys…> }— a summary, never the row. The receiving agent reads the record with the table's get tool, so masking and access apply exactly as on REST. A soft delete arrives as<table>.deleted. -
Source. The audit-wrapped
dbchokepoint, after the write commits: CRUD routes, actions, cron, queue and email handlers all count. Insidedb.transaction()the occurrences wait for the commit and are dropped on rollback. The write must use.returning()— without rows there is no id to send, so the generated CRUD routes emit and a baredb.delete(...)does not.
Custom events. Keyed by name (<noun>.<verb>, lowercase). Every filters entry becomes an optional string argument matched against the same-named field of the emitted data. The gate is "any authenticated caller". A custom name that equals a resource event fails the compile.
Emitting a custom event
import { emitMcpEvent } from '../lib/mcp-events';
// Exactly one scope, like emitWebhookEvent: the organization the subscriber
// was in when they subscribed, or the owning user. An unscoped emit throws.
await emitMcpEvent(
'build.finished',
{ project_id: build.projectId, build_id: build.id, status: 'passed' },
{ organizationId: ctx.activeOrgId! },
env,
);The name must be declared under custom; the data must satisfy your payloadSchema (the compiler does not check it at runtime). The function returns the number of subscriptions the occurrence was queued for.
Subscription lifecycle
| Method | Behaviour |
|---|---|
events/subscribe | Validates the event, arguments, delivery.url (https, public — the same anti-SSRF policy as webhook endpoints) and delivery.secret (whsec_ + 24–64 base64 bytes). Verifies the callback with a signed challenge, then stores or refreshes the subscription. Returns { id, refreshBefore, cursor: null, truncated: false }. |
events/unsubscribe | Deletes the matching subscription. Idempotent. |
- Identity is
(principal, callback URL, event, arguments); theidis derived from it and arguments are canonicalised, so re-subscribing refreshes instead of duplicating. The principal is the authenticated user, or the delegated principal on aprincipals:lane. - Verification POSTs
{ "type": "verification", "challenge": "…" }signed with the new secret and expects a2xx{ "challenge": "…" }echo. A successful verification is cached per (principal, URL) for 7 days. A failure returns JSON-RPC error-32015withdata.reason(challenge_failed,timeout,connection_refused,http_4xx,http_5xx,http_3xx). - Lifetime.
ttlMsis clamped into[minMs, maxMs]; an omittedttlMsgetsdefaultMs;ttlMs: nullgetsmaxMs.refreshBeforeis nevernull— a subscription always expires, and delivery stops when it does. ChatGPT refreshes by callingevents/subscribeagain beforerefreshBefore; the refresh re-runs the access gate, which is where revoked access is caught. - Secret rotation. A refresh with a new secret signs the next 10 minutes of deliveries with both secrets, space-separated.
- No replay.
cursoris alwaysnull; events missed while a subscription was expired are not recoverable.
Other errors: -32602 invalid params, -32023 unknown event or subscription (data.kind), -32024 not authenticated or no active organization for an organization-scoped event, -32026 a delivery mode other than webhook (data.feature: "deliveryMode").
Delivery
One event per request, signed in the Standard Webhooks format with the subscription's secret:
| Header | Value |
|---|---|
webhook-id | The body's eventId (evt_…), stable across retries |
webhook-timestamp | Signing time, Unix seconds — fresh per attempt |
webhook-signature | v1,<base64 HMAC-SHA256>, two entries during a rotation window |
X-MCP-Subscription-Id | The id from events/subscribe |
{
"eventId": "evt_8f3c…",
"name": "tasks.created",
"timestamp": "2026-10-29T12:05:00.000Z",
"data": { "id": "tsk_42", "operation": "created", "organizationId": "org_1", "projectId": "prj_7" },
"cursor": null
}Deliveries are webhook_deliveries rows (endpoint_id is the subscription id) processed by the webhooks queue consumer, with the same backoff as outbound webhooks. Differences from endpoint deliveries:
- A body over 256 KiB is not sent; the delivery is marked
failed. 410revokes the subscription;413and any redirect fail the delivery without retry.- The destination is re-checked against the anti-SSRF policy before every attempt, and redirects are never followed.
Limits
Polling and streaming delivery, replay cursors, and the draft's gap / terminated control envelopes are not implemented. Access revoked mid-lifetime is enforced at the next refresh, so the subscription TTL bounds the window — shorten ttl.maxMs if that window matters.
Named MCP Servers
Additional MCP servers with their own path, tools and audience — MCP Apps, attendee servers, vanity hosts, login pages, transport.
Security Headers
Configure CSP, COOP, COEP, CORP, X-Frame-Options, HSTS, Referrer-Policy, and Permissions-Policy on every response from your generated Worker.