Model Context Protocol defines stdio and Streamable HTTP transport mechanisms for communication between client and server. MCP messages are encoded using JSON-RPC and use UTF-8. Both transports carry messages between client and server; the connection is established and messages are delivered in different ways.
In the MCP architecture, a host manages one or more clients. Each client maintains a separate connection to its corresponding server. According to the Model Context Protocol architecture description, a local server using stdio typically serves a single client, while a remote server using Streamable HTTP typically serves multiple clients.
Interprocess communication with stdio
According to the Model Context Protocol transport rules, when stdio is used, the client launches the MCP server as a subprocess. The server reads JSON-RPC messages from standard input and sends its messages through standard output. Each message is a single JSON-RPC request, notification, or response.
Messages are separated by newlines. A message must not contain embedded newlines. The server must not write anything to standard output that is not a valid MCP message. The client must not send anything to the server's standard input that is not a valid MCP message.
The server may write UTF-8 text to standard error for logging. The client may capture these logs, forward them elsewhere, or ignore them. Model Context Protocol states that clients should support stdio whenever possible.
Sending messages with Streamable HTTP
A server using Streamable HTTP runs as an independent process and can handle multiple client connections. Communication uses HTTP POST and GET. The server may optionally use Server-Sent Events, or SSE, to stream multiple server messages.
According to the Model Context Protocol transport rules, the server must provide a single MCP endpoint path that supports both POST and GET methods. A separate HTTP POST request must be made to this endpoint for each JSON-RPC message the client sends to the server.
The client must list both application/json and text/event-stream content types in the Accept header of the POST request. The request body must contain a single JSON-RPC request, notification, or response. The server's HTTP response varies according to the type of JSON-RPC message it receives.
If the incoming message is a JSON-RPC response or notification and the server accepts it, the server must return an HTTP 202 Accepted response with no body. If the server cannot accept the message, it must return an HTTP error status code. The body of this error response may contain a JSON-RPC error response without an id.
If the incoming message is a JSON-RPC request, the server must use one of two response types. It may use Content-Type: application/json to return a single JSON object. It may use Content-Type: text/event-stream to start an SSE stream. The client must support both cases.
SSE stream associated with a POST request
If the server starts an SSE stream in response to a POST request, the stream must end with a response to the JSON-RPC request in the POST body. The server may also send JSON-RPC request and notification messages before the response. These messages must relate to the client request that initiated the stream.
The Model Context Protocol transport rules state that the server should not close the SSE stream before sending the JSON-RPC response, except when the session expires. The server should close the stream after sending the response.
The connection can be interrupted at any time for reasons such as network conditions. According to the transport rules, this interruption must not be interpreted as the client canceling its request. The client must explicitly send an MCP CancelledNotification to cancel the request. The server may support resuming the stream to prevent message loss when the connection is interrupted.
Listening for server messages with GET
The client may open an SSE stream by sending an HTTP GET to the MCP endpoint. This stream allows the server to send messages to the client without the client first sending data through HTTP POST. The Accept header of the GET request must list text/event-stream as a supported content type.