---
title: 'MCP Events'
description: 'Get a webhook when an agent run finishes or an automation runs'
seo:
    title: 'Modem MCP Events'
    description: 'Subscribe to Modem MCP Server events to get a signed webhook when a Modem Agent run finishes or an automation runs, instead of polling.'
slug: api/mcp-events
---

**MCP Events** lets a client of the [Modem MCP Server](/docs/api/modem-mcp-server) subscribe to an event and receive it as a signed webhook. The server offers two events:

| Event                  | Sent when                                                                                      | Subscribe with             | Scope          |
| ---------------------- | ---------------------------------------------------------------------------------------------- | -------------------------- | -------------- |
| `agent_run.completed`  | A [Modem Agent](/docs/features/agent) run you started completes, fails, or is cancelled. Sent once. | `{ "run_id": "…" }`        | `agent:invoke` |
| `automation.triggered` | An automation set to **Push to MCP subscribers** runs. Sent on every run.                      | `{ "automation_id": "…" }` | `data:read`    |

Without `agent_run.completed`, a client that starts a run has to keep calling `modem_agent_get_run` until the run ends. With it, Modem sends your endpoint a notice when the run ends. For `automation.triggered`, see [Automation runs](#automation-runs).

:::warning
MCP Events implements the webhook mode of the [MCP Events extension](https://github.com/modelcontextprotocol/ext-events/blob/main/specification/beta/events/events.mdx), which is in beta. Its wire format can change as the specification changes.
:::

## Use MCP Events in ChatGPT

ChatGPT supports MCP Events with the [Modem plugin](/docs/api/modem-mcp-server#chatgpt). You don't need an endpoint or a secret: ask in a conversation, and ChatGPT subscribes for you and posts in that conversation when the notice arrives.

Use a **Work** chat (the **Chat | Work** toggle at the top of ChatGPT). ChatGPT supports event subscriptions in Work chats.

Hand off a long question and come back to the answer:

> **Prompt:** Ask the Modem agent which customers asked for SSO this quarter and what we shipped for them. Don't wait for it: subscribe to the run's completion and post the answer here when it finishes.

Watch an automation set to **Push to MCP subscribers**:

> **Prompt:** Subscribe to my Modem automation 'your_automation_name' and, each time it runs, summarize what triggered it here.

The rest of this page is for building your own client or receiver.

## When to use `agent_run.completed`

Use the event when nothing should wait on the run:

- **A backend or bot starts runs.** A support tool asks the agent to research a ticket's customer, then adds the answer to the ticket when the notice arrives. No worker sits in a polling loop while the run works.
- **The client's session ends first.** You start a long research run from a script or a laptop that goes to sleep. The run keeps going in Modem, and the notice reaches your endpoint when it finishes.
- **Many runs at once.** A nightly job starts one run per key account ("summarize what this customer asked for this week"). One endpoint receives every notice, and each answer is read when its run ends rather than in start order.

Polling still suits a client that waits in the same turn. `modem_agent_get_run` with `wait_seconds: 25` returns as soon as the run ends, needs no public endpoint, and puts the answer straight into the assistant's context.

|                    | Polling `modem_agent_get_run`       | `agent_run.completed`                                                       |
| ------------------ | ----------------------------------- | --------------------------------------------------------------------------- |
| Client disconnects | The wait ends. The run keeps going. | The notice still arrives at your URL.                                       |
| What you need      | Any MCP client                      | ChatGPT, or your own code with a public HTTPS endpoint                      |
| Cost while waiting | One tool call every 25 seconds      | None                                                                        |
| What arrives       | The answer                          | A notice with the run's status. Read the answer with `modem_agent_get_run`. |

## How it works

The notice carries no answer, only the run's ids and status. Your client reads the answer under its own access token, so a webhook URL alone never exposes what the agent said.

1. **Start a run**

    Call `modem_agent_invoke` or `modem_agent_send_message`. Save the `run_id` it returns. See [How an agent run works](/docs/api/modem-mcp-server#how-an-agent-run-works).

2. **Subscribe**

    Call `events/subscribe` with the event name, `{ "run_id": "…" }`, your endpoint URL, and a signing secret you generate. The first subscription to a URL triggers a [verification request](#verify-your-endpoint).

3. **Receive the notice**

    When the run ends, Modem POSTs a signed `agent_run.completed` notice to your URL. If the run had already ended when you subscribed, the notice is sent within a few seconds.

4. **Read the result**

    Call `modem_agent_get_run` with the run's `conversation_id` and `run_id`. A completed run includes the answer in `result.text`.

## Subscribe to a run

Your token needs the `agent:invoke` scope, the same scope as the agent-run tools. When a token holds the scope of at least one event, the server advertises the Events extension (`io.modelcontextprotocol/events`) in its capabilities, and `events/list` lists the events your scopes allow.

This request subscribes to one run:

```json
{
    "jsonrpc": "2.0",
    "id": 7,
    "method": "events/subscribe",
    "params": {
        "name": "agent_run.completed",
        "arguments": { "run_id": "chat:5b0c8f9e-1a2b-4c3d-8e4f-5a6b7c8d9e0f:mcp:6c1d9f0a-2b3c-4d4e-9f50-6b7c8d9e0f1a" },
        "delivery": {
            "mode": "webhook",
            "url": "https://hooks.example.com/modem/runs",
            "secret": "whsec_your_base64_secret_here"
        },
        "ttlMs": 3600000
    }
}
```

| Parameter          | Value                                                                                                                        |
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------- |
| `name`             | `agent_run.completed`                                                                                                        |
| `arguments.run_id` | The `run_id` from `modem_agent_invoke` or `modem_agent_send_message`. Only the user who started the run can subscribe to it. |
| `delivery.mode`    | `webhook`. Modem does not offer the `poll` or `stream` modes.                                                                |
| `delivery.url`     | A public HTTPS URL, with no username, password, or fragment.                                                                 |
| `delivery.secret`  | `whsec_` followed by the base64 of 24 to 64 random bytes. Modem signs every request to this URL with it.                     |
| `ttlMs`            | How long the subscription lasts, in milliseconds. Modem grants between 2 minutes and 1 hour, and 1 hour when you omit it.    |

The result names the subscription and when it expires:

```json
{
    "id": "sub_9d1c4a7e0b2f4c6a8e3d5f7a9b1c3e5d",
    "refreshBefore": "2026-11-25T10:42:11.000Z",
    "cursor": null,
    "truncated": false,
    "deliveryStatus": { "active": true, "lastDeliveryAt": null, "lastError": null }
}
```

Subscribing again with the same URL and run refreshes the same subscription and returns the same `id`. Once the notice has been delivered, `deliveryStatus.lastDeliveryAt` says when, and a refresh does not send it again. Call `events/unsubscribe` with the name, arguments, and URL to remove a subscription before it expires.

Each subscription is sent the run's notice once. A retry can repeat it in rare cases, so deduplicate on `eventId`. Subscribe again only to change the URL or extend the expiry.

## Verify your endpoint

Before Modem accepts a URL, it sends the URL a signed verification request:

```json
{ "type": "verification", "challenge": "9f2c4e1a7b3d5f60a8c2e4b6d1f3a5c7" }
```

Verify the signature, then answer with a 2xx status and the challenge echoed back:

```json
{ "challenge": "9f2c4e1a7b3d5f60a8c2e4b6d1f3a5c7" }
```

If your endpoint does not answer or does not echo the challenge, `events/subscribe` fails with error `-32027` and a `reason`, such as `challenge_failed` or `timeout`. The check stops anyone from subscribing a URL they do not control. While you hold a live subscription to a URL, further subscriptions to it skip the check.

## What Modem sends

When the run ends, Modem POSTs this body with `content-type: application/json`:

```json
{
    "eventId": "evt_4e8a1f0c9b2d47e6a3c5b7d9f1e2a4c6",
    "name": "agent_run.completed",
    "timestamp": "2026-11-25T09:46:03.000Z",
    "data": {
        "run_id": "chat:5b0c8f9e-1a2b-4c3d-8e4f-5a6b7c8d9e0f:mcp:6c1d9f0a-2b3c-4d4e-9f50-6b7c8d9e0f1a",
        "conversation_id": "5b0c8f9e-1a2b-4c3d-8e4f-5a6b7c8d9e0f",
        "status": "completed"
    }
}
```

| Field                                 | Value                                                                                              |
| ------------------------------------- | -------------------------------------------------------------------------------------------------- |
| `eventId`                             | The same for every copy of this run's notice, across subscriptions and retries. Deduplicate on it. |
| `name`                                | Always `agent_run.completed`.                                                                      |
| `timestamp`                           | When Modem sent the notice, as an ISO 8601 timestamp.                                              |
| `data.run_id`, `data.conversation_id` | The run, and the conversation to pass to `modem_agent_get_run` or `modem_agent_send_message`.      |
| `data.status`                         | `completed`, `failed`, or `cancelled`, as `modem_agent_get_run` reports it.                        |

Each request carries the [Standard Webhooks](https://www.standardwebhooks.com) headers `webhook-id`, `webhook-timestamp`, and `webhook-signature`, signed with your `delivery.secret`. The `X-MCP-Subscription-Id` header names the subscription, so one endpoint can pick the right secret when it serves several. Verify the signature exactly as for an [automation webhook](/docs/features/webhooks#verify-the-signature).

## Receive notices

Answer each request with a 2xx status within 10 seconds, then do the work, such as calling `modem_agent_get_run`. Modem ignores the response body, except during [verification](#verify-your-endpoint).

Requests come from `34.70.85.166` and `34.9.237.160`. If your endpoint accepts traffic only from known IP addresses, allow both.

Modem retries a notice for about 2 minutes after a 408, 429, or 5xx response, a timeout, or a dropped connection. It does not retry any other 4xx response, a redirect, or a TLS failure. If the notice never arrives, you can still read the run's status with `modem_agent_get_run`.

## Automation runs [#automation-runs]

`automation.triggered` pushes each run of an [automation](/docs/features/automations) to the MCP clients subscribed to it. Set the automation's **Then** to **Push to MCP subscribers**, and each time its trigger fires, Modem sends a notice to every live subscription instead of running the agent. Like a [webhook](/docs/features/webhooks) outcome, the run has no prompt and calls no model.

The difference is who chooses the endpoint. A webhook outcome sends to one URL that someone who can edit the automation configures. With MCP Events, any member's MCP client can subscribe its own endpoint, under its own OAuth token, without changing the automation. Use it when:

- **Your own agent reacts to Modem events.** A coding agent or bot subscribes to an automation that fires when a pull request merges, and drafts the release note when the notice arrives.
- **Several people or tools want the same events.** Up to 25 subscriptions share one automation, each with its own URL and secret.
- **The subscription should end with the client.** A subscription lasts at most an hour unless the client refreshes it, so an endpoint stops receiving events soon after its client stops running.

### Subscribe to an automation

Find the automation's id on its page in the dashboard, which also shows how many live subscribers it has. `events/list` names up to 20 automations you can subscribe to in the event's description. Subscribe with the same request as for a run, with `"name": "automation.triggered"` and `"arguments": { "automation_id": "…" }`. Your token needs the `data:read` scope.

Deleting the automation, or changing its **Then** to another outcome, removes its subscriptions.

### What an automation run sends

```json
{
    "eventId": "evt_018f6b2a-0000-7000-8000-000000000a31",
    "name": "automation.triggered",
    "timestamp": "2026-11-25T09:42:11.000Z",
    "data": {
        "organization_id": "1842",
        "automation": { "id": "018f6b2a-0000-7000-8000-000000000902", "name": "Pull request merged" },
        "event": {
            "name": "pull_request.activity",
            "data": { "change": { "kind": "merged" } }
        }
    }
}
```

| Field             | Value                                                                                                                                                                                                                        |
| ----------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `eventId`         | Names the run. Every subscriber and every retry gets the same one, so deduplicate on it.                                                                                                                                     |
| `timestamp`       | When the run started, as an ISO 8601 timestamp.                                                                                                                                                                              |
| `data.automation` | The automation's `id` and `name`, so one endpoint can serve several automations.                                                                                                                                             |
| `data.event`      | The trigger event's `name` and `data`, the same payload a [webhook](/docs/features/webhooks#what-modem-sends) delivers. Shortened above. A scheduled automation sends `schedule.tick`. Omitted when the run has no trigger event. |

Signatures, the `X-MCP-Subscription-Id` header, and IP addresses are the same as for [agent runs](#what-modem-sends). Modem retries a failed notice like a webhook delivery, up to 6 attempts over about 5 minutes. A subscriber's failed delivery does not fail the automation's run.

## Limits and errors

- Up to 5 live subscriptions per run, 25 per automation, and 100 per user across all events.
- A subscription lasts at most 1 hour. Subscribe again before `refreshBefore` to keep it.

| Code     | When                                                                                                                                                                                                                                   |
| -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `-32602` | `arguments` is not exactly `{ "run_id": "…" }` or `{ "automation_id": "…" }`, the run does not exist or another user started it, or the automation is not set to **Push to MCP subscribers**. Also an invalid URL, secret, or `ttlMs`. |
| `-32023` | The event name is unknown, or `events/unsubscribe` found no matching subscription.                                                                                                                                                     |
| `-32024` | Your token lacks the event's scope.                                                                                                                                                                                                    |
| `-32025` | A subscription limit is reached (`data.limit: "subscriptions"`), or you sent too many `events/*` requests (`data.limit: "rate"`).                                                                                                      |
| `-32026` | You asked for a delivery mode other than `webhook`.                                                                                                                                                                                    |
| `-32027` | [Endpoint verification](#verify-your-endpoint) failed.                                                                                                                                                                                 |
| `-32020` | A request on MCP protocol version `2026-07-28` has a missing or wrong `Mcp-Name` header.                                                                                                                                               |
| `-32603` | Modem could not record the subscription. Try again.                                                                                                                                                                                    |

## Related

**[Modem MCP Server](/docs/api/modem-mcp-server)**

Connect a client and run the Modem Agent.

**[MCP Tool Reference](/docs/api/mcp-tools)**

Parameters and results for `modem_agent_invoke` and `modem_agent_get_run`.

**[Webhooks](/docs/features/webhooks)**

Send an automation's trigger events to one fixed endpoint.
