Skip to content

Commit 528588d

Browse files
SEP-1699: Support SSE polling via server-side disconnect
This implements the specification changes for SEP-1699: * When a server starts an SSE stream, it MUST immediately send an SSE event consisting of an [`id`][SSE `id`] and an empty [`data`][SSE `data`] string in order to prime the client to reconnect with that event ID as the `Last-Event-ID`. Note that the SSE standard explicitly [permits setting `data` to an empty string][SSE empty `data`], and says that the appropriate client-side handling is to record the `id` for `Last-Event-ID` but otherwise ignore the event (i.e., not call the event handler callback). * At any point after the server has sent an event ID to the client, the server MAY disconnect at will. * If a server disconnects, the client will interpret the disconnection the same as a network failure, and will attempt to reconnect. In order to prevent clients from reconnecting / polling excessively, the server SHOULD send an SSE event with a [`retry`][SSE `retry`] field indicating how long the client should wait before reconnecting. Clients MUST respect the `retry` field. [SSE `id`]: https://html.spec.whatwg.org/multipage/server-sent-events.html#:~:text=field%20name%20is%20%22id%22 [SSE `data`]: https://html.spec.whatwg.org/multipage/server-sent-events.html#:~:text=field%20name%20is%20%22data%22 [SSE empty `data`]: https://html.spec.whatwg.org/multipage/server-sent-events.html#:~:text=data%20buffer%20is%20an%20empty%20string [SSE `retry`]: https://html.spec.whatwg.org/multipage/server-sent-events.html#:~:text=field%20name%20is%20%22retry%22
1 parent d847a00 commit 528588d

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

docs/specification/draft/basic/transports.mdx

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,16 +103,26 @@ MCP endpoint.
103103
`Content-Type: application/json`, to return one JSON object. The client **MUST**
104104
support both these cases.
105105
6. If the server initiates an SSE stream:
106-
- The SSE stream **SHOULD** eventually include JSON-RPC _response_ for the
106+
- The server **SHOULD** immediately send an SSE event consisting of an event
107+
ID and an empty `data` field in order to prime the client to reconnect
108+
(using that event ID as `Last-Event-ID`).
109+
- After the server has sent an SSE event with an event ID to the client, the
110+
server **MAY** close the _connection_ (without terminating the _SSE stream_)
111+
at any time in order to avoid holding a long-lived connection. The client
112+
**SHOULD** then "poll" the SSE stream by attempting to reconnect.
113+
- If the server does close the _connection_ prior to terminating the _SSE stream_,
114+
it **SHOULD** send an SSE event with a standard `retry` field before
115+
closing the connection. The client **MUST** respect the `retry` field,
116+
waiting the given number of milliseconds before attempting to reconnect.
117+
- The SSE stream **SHOULD** eventually include a JSON-RPC _response_ for the
107118
JSON-RPC _request_ sent in the POST body.
108119
- The server **MAY** send JSON-RPC _requests_ and _notifications_ before sending the
109120
JSON-RPC _response_. These messages **SHOULD** relate to the originating client
110121
_request_.
111-
- The server **SHOULD NOT** close the SSE stream before sending the JSON-RPC _response_
112-
for the received JSON-RPC _request_, unless the [session](#session-management)
122+
- The server **MAY** terminate the SSE stream if the [session](#session-management)
113123
expires.
114-
- After the JSON-RPC _response_ has been sent, the server **SHOULD** close the SSE
115-
stream.
124+
- After the JSON-RPC _response_ has been sent, the server **SHOULD** terminate the
125+
SSE stream.
116126
- Disconnection **MAY** occur at any time (e.g., due to network conditions).
117127
Therefore:
118128
- Disconnection **SHOULD NOT** be interpreted as the client cancelling its request.

docs/specification/draft/changelog.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ the previous revision, [2025-06-18](/specification/2025-06-18).
1919
1. Clarify that servers must respond with HTTP 403 Forbidden for invalid Origin headers in Streamable HTTP transport. (PR [#1439](https://github.com/modelcontextprotocol/modelcontextprotocol/pull/1439))
2020
2. Updated the [Security Best Practices guidance](https://modelcontextprotocol.io/specification/draft/basic/security_best_practices).
2121
3. Clarify that input validation errors should be returned as Tool Execution Errors rather than Protocol Errors to enable model self-correction ([SEP-1303](https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1303)).
22+
4. Support polling SSE streams by allowing servers to disconnect at will ([SEP-1699](https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1699)).
2223

2324
## Other schema changes
2425

0 commit comments

Comments
 (0)