Lesson 35.4 · 4 of 6 · 6 min read · Reviewed 24 Nov 2026
Transports: stdio and HTTP
By the end, you can
- Compare the stdio and HTTP transports.
- Choose a transport for local and remote servers.
A transport is how JSON-RPC messages travel between client and server.
stdio
The host starts the server as a child process and talks over stdin and stdout.
- Great for local tools: file access, a local database, a CLI wrapper.
- No network setup; it runs with the user’s own permissionsPermission rule: An allow, ask or deny rule that controls which tools, commands or paths a coding agent may use..
- Gotcha: the server must write logs to stderr. Anything printed to stdout is read as protocol data and breaks the connection.
Streamable HTTP
The server runs as a web service. Clients send requests over HTTP and can receive streamedStreaming: Receiving a response as a series of server-sent events while it is generated, instead of waiting for the whole reply. responses.
- Great for shared or remote services: one server for a whole team, run by the team that owns the system.
- Uses normal web authentication, such as OAuthOAuth: A standard for granting an application limited access to a user’s account on another service without sharing their password..
- Needs the usual web care: TLS, auth, rate limitsRate limit: A cap on how many requests or tokens you can use in a period, such as per minute..
What changed in the 2026-07-28 revision
The current spec makes Streamable HTTP stateless, which is what lets one server sit behind an ordinary load balancer:
| Before (2025-11-25 and earlier) | Now (2026-07-28) |
|---|---|
initialize handshake, then an Mcp-Session-Id header on every call |
No handshake and no session id. Each request carries its protocol version and capabilities (35.6) |
| Gateways had to read the JSON body to route a call | Mcp-Method and Mcp-Name headers (for example tools/call and search) let a gateway route, rate-limit and log without parsing the body |
| A long-lived GET stream for server notifications | One opt-in subscriptions/listen stream, per notification type |
| Servers asked the client for input mid-call over a held-open stream | The server returns input_required with what it needs, and the client retries the call with the answers |
| List results with no caching hints | tools/list, resources/list and similar carry a TTL, so clients can cache them |
Any state that must last across calls now travels as an explicit handle, such as an id a tool returns and the next call passes back.
DeprecatedDeprecation: Announcing that a model or feature will be retired on a set date., not yet removed: the old HTTP+SSEServer-sent events (SSE): A simple protocol for a server to push a stream of events to a client over one HTTP connection. transport (replaced by Streamable HTTP, with a year-long off-ramp) and the roots, samplingSampling: Choosing the next token from the model’s probability distribution, rather than always taking the most likely one. and logging features. They keep working for at least 12 months. For new servers, take paths as tool parameters or config instead of roots, call a model API directly instead of sampling, and log to stderr or OpenTelemetryOpenTelemetry: An open standard and toolkit for collecting traces, metrics and logs from software.. Lesson 36.5 covers how authorization changed.
Choosing
| Need | Transport |
|---|---|
| Personal, local tool | stdio |
| Shared service, central auth | Streamable HTTP |
| Wraps a local CLI | stdio |
| Owned by another team | Streamable HTTP |
Key points
- stdio runs the server as a local process and talks over standard input and output.
- Streamable HTTP runs the server remotely, shared by many users, with normal web authentication.
- stdio servers must never print logs to stdout, because that corrupts the protocol stream.
- In the 2026-07-28 revision, Streamable HTTP is stateless: no session id, routing headers on every request, and one opt-in stream for notifications. The older HTTP+SSE transport is deprecated.
Catch a stray print in a stdio stream
See why a log line on stdout breaks an stdio MCP connection, and fix it by sending logs to stderr.
You will have: A simulated stdio server and client that first fails on a log line, then works once logs go to stderr.
Steps
- Read the toy server: it writes JSON-RPC lines to a list called stdout.
- Run it: the client parses each stdout line as JSON and reports the first bad line.
- Change the server's log() so it writes to stderr instead of stdout.
- Run it again and check every stdout line parses.
- Print what ended up on stderr to show the logs are still visible.
Done when
- The broken run prints a parse error naming the log line.
- The fixed run parses every stdout line.
- The log line appears on stderr, not stdout.
Open in the Playground No API key needed.
Starter code (Python)
import json
def run_server(stdout, stderr):
def log(text):
stdout.append(text) # TODO: logs must go to stderr, never stdout
log("Server ready on stdio")
stdout.append(json.dumps({"jsonrpc": "2.0", "id": 1, "result": {"tools": []}}))
def client_read(stdout):
for line in stdout:
try:
json.loads(line)
except ValueError:
return f"parse error on line: {line!r}"
return "all lines parsed"
out, err = [], []
run_server(out, err)
print("client:", client_read(out))
print("stderr:", err)
Show a solution
import json
def run_server(stdout, stderr, fixed):
def log(text):
(stderr if fixed else stdout).append(text)
log("Server ready on stdio")
stdout.append(json.dumps({"jsonrpc": "2.0", "id": 1, "result": {"tools": []}}))
def client_read(stdout):
for line in stdout:
try:
json.loads(line)
except ValueError:
return f"parse error on line: {line!r}"
return "all lines parsed"
for fixed in (False, True):
out, err = [], []
run_server(out, err, fixed)
print("fixed" if fixed else "broken", "client:", client_read(out))
print(" stderr:", err)