How it works
- The client subscribes to an event by name, with arguments that narrow it
(here, one channel). Your
onSubscribehook can refuse. - Your code emits the event when something changes, usually from a tool callback or a backend job.
- mcp-use delivers it to every matching subscription, either as a signed
HTTP POST to the client’s callback URL (webhook) or on the client’s next
events/pollrequest (poll).
Define and emit an event
Declare the event once withserver.event(). It returns a handle you call
emit() on.
What emit() does
- Validates the data against
payloadSchemaand rejects bodies over 256 KiB. - Sends the event to every matching webhook subscription and adds it to the
log that
events/pollreads. - Resolves with
{ eventId, deliveries }after the first delivery attempt. Failed deliveries are retried in the background.
eventId that stays the same for the same change (a message id, a
deployment id). Clients use it to ignore duplicates. One is generated if you
leave it out.
emit() throws if it can’t read the subscriptions or queue the deliveries in
the store. A failed write to the poll log is logged instead. When the event
follows a write that already succeeded, catch the error so the tool call still succeeds:
Control who receives an event
By default, a subscription receives an event when each subscription argument that also appears indata has the same value there. A client subscribed with
{ channel_id: "c1" } gets every event whose data.channel_id is "c1".
The client chooses those arguments, so they narrow a stream but don’t prove the
client may read it. When events carry one user’s data, add two hooks:
onSubscribe(ctx, args)runs when a client subscribes, renews a webhook subscription or polls, so revoked access takes effect at the next renewal. Thrownew EventsError("forbidden", message)to refuse.match(ctx, event, args)runs for each subscription when you emit, and for each logged event when a client polls. Returntrueto deliver.
ctx.userId holds:
onSubscribe runs on every poll, so keep it fast. A match that throws skips
that subscription and is logged. Receiving an event never lets a client act:
its tool calls still go through normal authorization.
The ctx argument
Webhook subscriptions store the subscriber, so
match sees the same ctx on
every later emit, on any server instance.
Delivery: webhook or poll
The client picks how it receives events. Your server code is the same for both.Webhooks
- When a subscriber first subscribes with a callback URL, the server sends a
signed verification challenge during
events/subscribeand expects the client to echo it back. A passed check is remembered for that subscriber and URL for an hour. - Each event is one POST, signed with HMAC-SHA256 using the client’s
whsec_secret (webhook-id,webhook-timestampandwebhook-signatureheaders). - Failed deliveries are retried after 10 s, 1 min, 5 min, 30 min and 2 h with
the same
eventId. A410response removes the subscription. - Subscriptions last 24 hours by default (
events.defaultTtlMs). Clients renew by subscribing again. - By default, callbacks must be HTTPS and can’t point at private or loopback
addresses.
mcp-use devrelaxes this, as doesevents.allowInsecureCallbacks, which is for trusted local development only.
mcp-use dev,
node, a container). On serverless hosts, a due retry runs on the next emit().
Webhooks need an authenticated client
A webhook subscription outlives the request that created it: the server stores it and keeps POSTing events to its URL until it expires. So the server needs to know who owns it. mcp-use stores each subscription under the caller’s principal, the identity it reads from the access token (ctx.principal).
Only that principal can renew or cancel it, and onSubscribe and match
decide what it may receive.
A request without an access token has the principal anonymous. If anonymous
webhooks were allowed, anyone who can reach the server could register their
own URL and receive every event, including events that carry other users’
data. So by default the official dialect refuses them:
- Add OAuth to the server (Authentication). Clients sign in and each subscription belongs to that user.
- Poll instead.
events/pollstores nothing, so it works without sign-in.onSubscribeandmatchstill run on every poll. - Allow anonymous webhooks for testing.
MCP_USE_EVENTS_INSECURE=1orevents.allowInsecureCallbacks: trueallows them, along withhttp:and private callback URLs.mcp-use devsetsMCP_USE_EVENTS_INSECURE=1when it listens on localhost without--tunnel; with a tunnel or a non-loopback host, anonymous webhooks stay refused. Never enable it on a production server.
Polling
Every emitted event is kept in a per-event log for 1 hour (up to 1000 events). The client polls with the last cursor it got and receives what happened since:cursor: nullstarts from now.hasMore: truemeans poll again right away. Otherwise waitnextPollMs(5000 by default,events.pollIntervalMs).truncated: truemeans some events may have been missed, for example because the cursor is older than the log.
onSubscribe and match as webhooks.
Storage
Subscriptions and the poll log live in a store. mcp-use picks one for you:
To use your own Redis, pass an Upstash REST store:
mcp-use/events also exports memoryEventsStore() (for tests) and
fileEventsStore(dir). The server logs which store is active when it starts.
On Manufact Cloud, list the current subscriptions with:
Receive events in a client
Webhook
subscribeEvent again before refreshBefore to keep the
subscription, and unsubscribeEvent to stop it.
Poll
React
useMcpEvent runs the poll loop for a useMcp connection:
CLI
subscribe generates and prints a whsec_ secret unless you pass --secret.

Subscribe a local receiver, create a note, see the delivery, then unsubscribe.

Poll from a cursor: only the inbox note is returned.
Inspector
The Inspector’s Events tab lists your server’s events and subscribes with a built-in webhook inbox. Each delivery shows itswebhook-id, signature check
and body. Under mcp-use dev --tunnel, the inbox is reachable through the
tunnel.
When the server runs with insecure events, as under mcp-use dev on localhost,
the tab shows a banner saying anonymous webhook subscriptions are allowed. A
deployed server without that setting refuses them, and the tab explains why.

Subscribe from the Events tab, call create_note from Tools, inspect the delivery, then unsubscribe.
Use with ChatGPT
ChatGPT supports MCP Events with webhook delivery. Each event starts one automation run.- Subscriptions are created from ChatGPT Work chats with Cloud selected. A local Codex chat hands the subscription to a Work Cloud chat.
- The workspace needs Developer mode and Allow event-triggered scheduled tasks turned on.
- Servers without OAuth work.
Protocol details
mcp-use speaks two versions of the protocol from the sameserver.event()
definitions and picks one per client, so you don’t configure anything.
Push delivery (
events/stream) and webhook replay are not implemented.
Methods
Methods
Registering an event advertises
capabilities.events (ChatGPT) and
capabilities.extensions["io.modelcontextprotocol/events"] (official) on
initialize and server/discover.Error codes
Error codes
Webhook delivery format
Webhook delivery format
Each POST has the body
{ eventId, name, timestamp, data, cursor: null } and
the headers webhook-id, webhook-timestamp, webhook-signature
(v1,<base64 HMAC-SHA256>) and X-MCP-Subscription-Id.webhook-idis theeventIdfor ChatGPT, and a generatedmsg_...id (kept across retries) for the official extension.- The verification request body is
{"type":"verification","challenge":"..."}and expects a 2xx response with{"challenge":"..."}. Success is cached for an hour per subscriber and URL. 410and413responses are not retried.- When a client subscribes again with a new secret, deliveries are signed with both secrets for 24 hours.
- On Node, the sender resolves the callback host, rejects private, loopback and link-local addresses, and connects to the checked address. Redirects are not followed and each request times out after 10 s.
Subscription identity and lifetime
Subscription identity and lifetime
A subscription’s id comes from the subscriber, callback URL, event name and
arguments, so subscribing again with the same values renews it.
ttlMs
omitted grants 24 hours, a positive number is clamped between 1 minute and 30
days, 0 or a negative number is rejected, and null means no expiry (refreshBefore: null).Routing headers
Routing headers
On
events/subscribe, events/unsubscribe and events/poll, an Mcp-Name
header must equal params.name. An Mcp-Param-<Header> header must equal
the argument whose inputSchema property declares "x-mcp-header": "<Header>"
(Base64 values =?base64?...?= are decoded). A mismatch is HTTP 400 with -32020
(HeaderMismatch). Missing headers are accepted with a warning. The @mcp-use/client HTTP connector sets Mcp-Name.Event list changes
Event list changes
The server answers a
subscriptions/listen request whose filter sets
eventsListChanged: true, and sends notifications/events/list_changed when
the event catalog changes: on a hot reload in mcp-use dev, or after a deploy
on instances that share the store (checked every 30 seconds).Platform environment variables
Platform environment variables
On Manufact Cloud the store is configured from
MCP_USE_PLATFORM_STORAGE_URL,
MCP_USE_PLATFORM_STORAGE_TOKEN and MCP_USE_PLATFORM_STORAGE_PREFIX.
MCP_USE_PLATFORM_NAMESPACE sets the key namespace, and
MCP_USE_PLATFORM_SECRET encrypts stored webhook secrets (comma-separated for
rotation).Delivery failure logs
Delivery failure logs
A failed attempt is logged as
[mcp-use] events delivery failed: <name> <subscriptionId> -> <origin> <status|error> attempt <n>.examples/mcp-events for a complete server.