Ch 3 — Transports Under the Hood

stdio byte framing, HTTP request/response lifecycle, SSE wire format, session tokens, and reconnection
Under the Hood
-
Click play or press Space to begin...
Step- / 10
Astdio InternalsProcess spawning, pipe wiring, and newline-delimited JSON
1
terminal
Spawn Processfork + exec with
stdin/stdout pipes
wire
cable
Pipe Pairhost.stdin → server
server → host.stdout
frame
2
wrap_text
NDJSONNewline-delimited
JSON framing
3
arrow_downward stdio edge cases: buffering, encoding, and stderr
Bstdio Edge CasesBuffering, UTF-8, stderr, and EOF detection
speed
Flush BuffersMust flush after
every message
+
translate
UTF-8 OnlyAll text must be
valid UTF-8
+
4
report
stderr = LogsNever mix logs
with MCP messages
5
arrow_downward HTTP POST: sending requests to the server
CHTTP POST Request FlowClient sends JSON-RPC, server responds with JSON or SSE
upload
POST /mcpContent-Type:
application/json
Accept
rule
Server DecidesJSON response
or SSE stream?
200 OK
6
download
Responseapplication/json
or text/event-stream
7
arrow_downward SSE wire format: event types and data framing
DSSE Wire FormatHow Server-Sent Events carry MCP messages
code
event: messageEvent type for
all MCP messages
+
data_object
data: JSONFull JSON-RPC
message on one line
+
8
tag
id: fieldLast-Event-ID for
reconnection
9
arrow_downward Session management: tokens, headers, and lifecycle
ESession Token LifecycleHow Mcp-Session-Id flows through HTTP requests
login
InitializeNo session ID yet
first POST
response
key
Get Session IDServer sets header
Mcp-Session-Id
reuse
repeat
All RequestsClient sends ID
on every request
10
arrow_downward Reconnection and session resumption
FReconnection & ResumptionRecovering from network drops without re-initializing
wifi_off
Connection LostNetwork drop or
server restart
retry
sync
ReconnectGET /mcp with
same session ID
resume
check_circle
ResumedServer replays
missed events
1
Detail