C.W.K.
Stream
Lesson 04 of 05 · published

Streaming and Resumability

~22 min · streaming, resumability, last-event-id, reconnect

Level 0Curious Reader
0 XP0/48 lessons0/14 achievements
0/100 XP to next level100 XP to go0% complete

Streamable HTTP carries long-running results and notifications over an SSE stream. SSE is robust to reconnects by design: each event has an optional id field, and a client that disconnects can reconnect with a Last-Event-Id header asking for everything since that id.

MCP builds on this with explicit resumability: a server that supports it issues monotonically increasing event ids, retains a window of recent events in memory, and on reconnect re-emits everything since the client's Last-Event-Id. From the client's view, a network hiccup looks like a brief stall instead of a lost result.

Resumability is how long-running tools survive flaky networks. Without it, a 10-minute build that streams progress notifications turns into a 10-minute lost connection if the client's wifi drops at minute 7. With it, the client reconnects at minute 7-and-a-half and gets the missed events plus the eventual completion.

The cost is a buffer the server has to hold. Most production servers cap the buffer at something like 5,000 events or 5 minutes — enough for a typical reconnect, not enough to memory-leak. Buffer eviction policy and limits are server choices the client cannot control; clients should be prepared to receive a fresh-start signal if they wait too long to reconnect.

Code

Reconnect with Last-Event-Id·text
GET /mcp HTTP/1.1
Mcp-Session-Id: sess_abc123
Accept: text/event-stream
Last-Event-Id: 0042

HTTP/1.1 200 OK
Content-Type: text/event-stream

id: 0043
data: {"jsonrpc":"2.0","method":"notifications/progress","params":{...}}

id: 0044
data: {"jsonrpc":"2.0","id":7,"result":{...}}
Server-side: emitting resumable ids·python
# Pseudocode — actual SDK does this for you when resumability is enabled
event_id = next_event_id()
sse.send(id=event_id, data=json.dumps(message))
buffer.append((event_id, message))
buffer.evict_older_than(now() - 300)  # 5-minute window

External links

Exercise

Find or write a long-running MCP tool (anything > 30s with progress notifications). Run it from your client, kill the client's network mid-stream, restore it, and verify the client picks up the missed events plus the final result. The smoothness of that recovery is the value of resumability.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.