Expand description
§TurboMCP TCP Transport
TCP socket transport implementation for the TurboMCP SDK. This crate provides newline-delimited JSON-RPC communication over TCP sockets.
§Features
- Server Mode: Accept multiple client connections with automatic handling
- Client Mode: Connect to a remote TCP server
- Bidirectional Communication: Full-duplex message exchange
- Backpressure Handling: Bounded channels prevent memory exhaustion
- Graceful Shutdown: Clean task termination on disconnect
- Message Framing: Uses LinesCodec for reliable newline-delimited JSON
§Quick Start
§Server Mode
ⓘ
use turbomcp_tcp::{TcpTransport, TcpTransportBuilder};
use turbomcp_transport_traits::Transport;
use std::net::SocketAddr;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let addr: SocketAddr = "127.0.0.1:8080".parse()?;
let transport = TcpTransportBuilder::new()
.bind_addr(addr)
.build();
transport.connect().await?; // Starts listening
Ok(())
}§Client Mode
ⓘ
use turbomcp_tcp::{TcpTransport, TcpTransportBuilder};
use turbomcp_transport_traits::Transport;
use std::net::SocketAddr;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let bind_addr: SocketAddr = "127.0.0.1:0".parse()?;
let remote_addr: SocketAddr = "127.0.0.1:8080".parse()?;
let transport = TcpTransportBuilder::new()
.bind_addr(bind_addr)
.remote_addr(remote_addr)
.build();
transport.connect().await?;
Ok(())
}Structs§
- Atomic
Metrics - A lock-free, atomic structure for high-performance metrics updates.
- TcpConfig
- TCP transport configuration
- TcpTransport
- TCP transport implementation
- TcpTransport
Builder - TCP transport builder
- Transport
Capabilities - Describes the capabilities of a transport implementation.
- Transport
Message - A wrapper for a message being sent or received over a transport.
- Transport
Metrics - A serializable snapshot of a transport’s performance metrics.
Enums§
- Transport
Error - Represents errors that can occur during transport operations.
- Transport
State - Represents the current state of a transport connection.
- Transport
Type - Enumerates the types of transports supported by the system.
Traits§
- Transport
- The core trait for all transport implementations.
Type Aliases§
- Transport
Result - A specialized
Resulttype for transport operations.