Sub topic 5
Transports: stdio versus Streamable HTTP
This chapter assumes you know the host, client and server roles and the JSON-RPC message format from earlier chapters. It also assumes you can read a JSON configuration file and run commands in a terminal.
What a transport does
A transport is the channel that carries MCP messages between a client and a server. The messages are the same JSON-RPC 2.0 requests, responses and notifications whatever the channel. The transport only decides how those bytes travel and who starts the server process.
MCP defines two standard transports: stdio and Streamable HTTP.
stdio: a child process
With stdio (standard input and output), the client launches the server as a child process. The client writes JSON-RPC messages to the server's standard input. The server writes replies to its standard output. Each message is a single line of JSON, so a message cannot contain a raw newline.
This is what the command and args fields in an mcpServers entry describe:
{
"mcpServers": {
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/project"]
}
}
}The assistant runs npx with those arguments and talks to it through pipes. When the assistant exits, it closes the pipes and the server stops.
The standard error stream is free for logging. The server can write diagnostics there without breaking the protocol.
Streamable HTTP: a web endpoint
With Streamable HTTP, the server runs independently and exposes a single HTTP endpoint, for example https://example.com/mcp. The client sends each JSON-RPC message as an HTTP POST request to that endpoint. The server answers in one of two ways:
- A plain JSON response, which suits quick request-and-reply calls.
- A Server-Sent Events (SSE) stream, which lets the server send several messages over one response. This is useful for progress updates or for requests the server makes back to the client.
The client can also open a GET request to receive server-initiated messages. Because the server is a long-running service, many clients can connect to it at once. A session identifier, sent in a header, lets the server tell their conversations apart.
Streamable HTTP replaced the older HTTP+SSE transport from earlier versions of the specification. You may still see the older form in older servers and documentation.
Comparing the two
| Aspect | stdio | Streamable HTTP |
|---|---|---|
| Who starts the server | The client, as a child process | You or a hosting service |
| Where it runs | Your own machine | Local or remote |
| Clients per server | One | Many |
| Authentication | Usually none; it inherits your user permissions and environment | HTTP-level, such as OAuth or tokens |
| Setup | A command in the configuration file | A URL, plus credentials if needed |
| Typical use | Local files, local tools, personal scripts | Shared team services, hosted SaaS integrations |
Choosing between them
Pick stdio when the server needs your local files or tools and only you use it. It is the simplest option, and nothing listens on a network port.
Pick Streamable HTTP when the server is shared, hosted by someone else, or must run on another machine. You gain central updates and real authentication, and you take on running a web service.
A common error is configuring a remote URL in a field meant for a command, or the reverse. Check your assistant's documentation for how it expresses each type, since field names for URLs vary between assistants.
Writing a server for either transport
With the Python SDK, the tool code stays the same. Only the final call changes. Recent SDK versions let you pass the transport name to run:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("calculator")
@mcp.tool()
def add(a: int, b: int) -> int:
"""Add two integers."""
return a + b
if __name__ == "__main__":
mcp.run(transport="stdio") # or "streamable-http" to serve over HTTPExercise
A teammate's stdio MCP server connects, then the assistant reports parse errors. The server code contains print("starting up") at the top. What is wrong, and how do you fix it?
Show answer
In a stdio server, standard output carries the JSON-RPC messages. The print call writes a non-JSON line into that stream, which the client cannot parse. Remove it or send it to standard error, for example with print("starting up", file=sys.stderr) after importing sys, or use a logging library configured to write to standard error.
Exercise
You want ten developers to use the same internal issue-tracker server, and access must depend on each person's identity. Which transport fits, and why?
Show answer
Streamable HTTP. One running service can serve many clients, and HTTP supports per-user authentication such as OAuth or tokens. A stdio server would run separately on each machine and inherit that user's local permissions, with no built-in identity check.