Transports in MCP
The idea with transports in MCP is that they define how clients and servers communicate. MCP is transport agnostic, meaning it can work over HTTP, WebSockets, STDIO, and more. The transport is the layer that handles the underlying message exchange. It exchanges messages of type JSON-RPC.
MCP has a set of transports it supports from STDIO (for servers running locally) to streamable transports such as WebSockets and Server-Sent-Events (SSEs), and finally request/response transports such as HTTP.
For each of the specified transports, they all have in common that they operate on streams. All the transports have a method exposing those streams, like so:
async with anyio.create_task_group() as tg
    ...
    yield (read_stream, write_stream)
There’s also a BaseSession class that all transports use to send raw JSON-RPC messages, which looks like so.
class BaseSession(
    Generic[
        SendRequestT,
        SendNotificationT,
        SendResultT... 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                