Transports in the Model Context Protocol (MCP) provide the foundation for communication between clients and servers. A transport handles the underlying mechanics of how messages are sent and received.
MCP uses JSON-RPC 2.0 as its wire format. The transport layer is responsible for converting MCP protocol messages into JSON-RPC format for transmission and converting received JSON-RPC messages back into MCP protocol messages.There are three types of JSON-RPC messages used:
The stdio transport enables communication through standard input and output streams. This is particularly useful for local integrations and command-line tools.Use stdio when:
Building command-line tools
Implementing local integrations
Needing simple process communication
Working with shell scripts
Copy
const server = new Server({ name: "example-server", version: "1.0.0"}, { capabilities: {}});const transport = new StdioServerTransport();await server.connect(transport);
MCP makes it easy to implement custom transports for specific needs. Any transport implementation just needs to conform to the Transport interface:You can implement custom transports for:
Custom network protocols
Specialized communication channels
Integration with existing systems
Performance optimization
Copy
interface Transport { // Start processing messages start(): Promise<void>; // Send a JSON-RPC message send(message: JSONRPCMessage): Promise<void>; // Close the connection close(): Promise<void>; // Callbacks onclose?: () => void; onerror?: (error: Error) => void; onmessage?: (message: JSONRPCMessage) => void;}