Sub topic 2
Transports: stdio versus Streamable HTTP
Assume you can use a terminal, edit JSON, and read basic Python. MCP (Model Context Protocol) uses a transport to carry JSON-RPC messages between an assistant and an MCP server.
Choosing a transport
stdio connects the assistant to a local process through standard input and standard output. The assistant launches the server, writes requests to its input, and reads responses from its output. This is simple and keeps communication on one machine.
Streamable HTTP connects to a server through an HTTP endpoint. It supports remote servers, multiple clients, authentication, and streaming responses. The server must be reachable over the network and configured to protect the endpoint.
| Transport | Best fit | Main concern |
|---|---|---|
| stdio | A local server used by one assistant | Process and environment setup |
| Streamable HTTP | A shared or remote service | Authentication and network security |
Initialization and capability negotiation
Before normal requests, the client sends an initialize request. It includes protocol information and client capabilities. The server responds with its protocol version and server capabilities, such as support for tools, resources, or prompts. The client then sends an initialized notification.
This handshake lets both sides avoid using features the other side does not support. A failed handshake usually indicates an incompatible protocol version, an invalid server response, or a transport problem.
Adding a server to configuration
A coding assistant commonly stores server definitions under an mcpServers object. This example launches a local server over stdio:
{
"mcpServers": {
"calculator": {
"command": "python",
"args": ["server.py"],
"env": {
"API_TOKEN": "<set-in-your-environment>"
}
}
}
}For Streamable HTTP, the entry normally specifies the server URL and may include authentication settings. Follow the assistant's configuration format because field names differ between clients.
Following a tool call
- You ask the assistant to calculate a value.
- The assistant discovers the server's tools, usually with
tools/list. - The model selects a tool and supplies arguments.
- The client sends
tools/callover stdio or HTTP. - The server validates the arguments and runs the operation.
- The server returns structured content.
- The client gives the result to the model, which explains it to you.
Exercise
Which transport is usually the better starting point for a server running on your own laptop?
Show answer
stdio, because the assistant can launch the local process without exposing a network endpoint.