Skip to main content

Crate turbomcp_tcp

Crate turbomcp_tcp 

Source
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§

AtomicMetrics
A lock-free, atomic structure for high-performance metrics updates.
TcpConfig
TCP transport configuration
TcpTransport
TCP transport implementation
TcpTransportBuilder
TCP transport builder
TransportCapabilities
Describes the capabilities of a transport implementation.
TransportMessage
A wrapper for a message being sent or received over a transport.
TransportMetrics
A serializable snapshot of a transport’s performance metrics.

Enums§

TransportError
Represents errors that can occur during transport operations.
TransportState
Represents the current state of a transport connection.
TransportType
Enumerates the types of transports supported by the system.

Traits§

Transport
The core trait for all transport implementations.

Type Aliases§

TransportResult
A specialized Result type for transport operations.