Sub topic 5
Choosing a transport: stdio or Streamable HTTP
This chapter assumes you can read async Python and know that an MCP host talks to servers through a client. Here you will learn what a transport is and how to pick one for your application.
What a transport does
A transport is the channel that carries MCP's JSON-RPC messages between a client and a server. The messages and the lifecycle stay the same whichever transport you choose. Only the way the bytes travel changes. The current MCP specification defines two standard transports: stdio and Streamable HTTP.
stdio: a local subprocess
With stdio, your host starts the server as a child process. It writes messages to the server's standard input and reads replies from its standard output. Each message is one line of JSON.
Two rules cause most stdio bugs:
- The server must write only protocol messages to stdout. A stray
print()corrupts the stream. Send logs to stderr instead. - The server's lifetime is tied to your host. When the host closes the connection, the process ends.
The SDK handles the launch for you. This is the client code from the earlier chapters:
from mcp import StdioServerParameters
from mcp.client.stdio import stdio_client
server_params = StdioServerParameters(command="python", args=["server.py"])
# stdio_client(server_params) starts the subprocess and yields
# (read, write) streams for a ClientSession.Streamable HTTP: a remote service
With Streamable HTTP, the server runs on its own and exposes a single HTTP endpoint, for example https://example.com/mcp. The client sends each JSON-RPC message as an HTTP POST. The server can reply with a plain JSON response or open a Server-Sent Events (SSE) stream. The stream lets the server send progress updates and its own requests before the final result.
Because the server is a separate service, many clients can share it. That also means you must handle authentication, network failures and reconnection. Authorization is covered in a later chapter.
In the Python SDK you can serve this transport with mcp.run(transport="streamable-http"). On the client side, mcp.client.streamable_http.streamablehttp_client(url) replaces stdio_client, and the ClientSession code is unchanged. Check your SDK version, because helper names have changed between releases.
How to choose
| Question | stdio | Streamable HTTP |
|---|---|---|
| Where does the server run? | On the same machine | Anywhere reachable by URL |
| Who starts it? | Your host | An operator or hosting platform |
| Sharing across users | One process per client | Many clients, one service |
| Authentication | Usually none; the OS user's permissions apply | Required in practice |
| Setup effort | Low | Higher: deployment, TLS, auth |
A good default is stdio for development, desktop tools and servers that touch local files. Choose Streamable HTTP when the server needs shared state, central updates or access control, or when it wraps a hosted service.
Exercise
Your stdio server prints debug messages with print() and the client fails during initialization with a JSON parse error. What is the cause, and how do you fix it?
Show answer
stdout carries the JSON-RPC stream, so the printed text corrupts it. Write debug output to stderr, for example with print(..., file=sys.stderr) or the logging module configured for stderr.
Exercise
You want ten employees' chat applications to share one internal MCP server that is updated centrally. Which transport fits, and what extra concern does it bring?
Show answer
Streamable HTTP. It lets many clients reach one deployed service. The extra concern is authentication and authorization, along with network failure handling.