Sub topic 4
Choosing a transport: stdio or Streamable HTTP
This chapter assumes you have read the lifecycle chapter and have the team-tools server from "Your first tool" or can write an equivalent. A transport is the channel that carries JSON-RPC messages between an MCP client and a server. The messages and the initialization handshake are identical on every transport. Only the delivery mechanism changes.
The two standard transports
MCP defines two transports.
- stdio. The host launches your server as a subprocess. The client writes messages to the server's standard input and reads replies from its standard output.
- Streamable HTTP. Your server runs as an independent process that exposes one HTTP endpoint, such as
/mcp. The client sends each message as an HTTP POST. The server replies with a JSON body or with a Server-Sent Events stream, which lets it send several messages over one response.
stdio: one server per user
With stdio, the host starts and stops the process. There is no network port, no URL, and no login step. The server inherits the permissions of the user who started the host. That makes stdio the simplest option for tools that read local files or use the developer's own credentials.
The cost is distribution. Every user needs your code, a compatible Python version, and any secrets installed locally. Updating the server means updating every machine.
The FastMCP helper defaults to stdio, so the first-tool server needs no changes:
if __name__ == "__main__":
mcp.run() # same as mcp.run(transport="stdio")Streamable HTTP: one server for many users
With Streamable HTTP, you run the server once, for example on an internal host, and many clients connect to its URL. You deploy updates in one place, and the server can hold shared credentials that users never see.
You also take on the work of a web service: authentication, TLS, and monitoring. The SDK sets the host and port when you create the server, then you select the transport at run time:
from mcp.server.fastmcp import FastMCP
mcp = FastMCP("team-tools", host="127.0.0.1", port=8000)
# ... register tools, resources, and prompts as before ...
if __name__ == "__main__":
mcp.run(transport="streamable-http") # serves at http://127.0.0.1:8000/mcpThe server keeps its normal tools. You can check it with the Inspector by choosing the Streamable HTTP transport and entering http://127.0.0.1:8000/mcp.
Comparing the options
| Concern | stdio | Streamable HTTP |
|---|---|---|
| Who starts the server | The host | You |
| Number of users | One per process | Many per process |
| Authentication | Not needed, runs as the user | Required for anything shared |
| Updates | Every machine | One deployment |
| Logging | Must use stderr | Normal stdout is fine |
Common errors
- Binding to
0.0.0.0during development. This exposes the server to the whole network. Keep127.0.0.1until authentication is in place. - Skipping Origin checks. A local HTTP server can be reached by web pages in the user's browser. The spec tells servers to validate the
Originheader. Use the SDK's protections and do not turn them off. - Printing to stdout under stdio. This is the most common cause of a server that works in the Inspector but fails in a host.
- Assuming one process means one session. Over HTTP, each client has its own session. Do not keep per-user state in module-level variables.
Exercise
Your team's server calls an internal API using a shared service token that should not be copied to developer laptops. Which transport fits, and what must you add that stdio would not need?
Show answer
Streamable HTTP. The token stays on the server you run. You must add authentication for clients, TLS, and Origin validation, and bind the server only to the interfaces you intend.