Skip to main content

Crate turbomcp_websocket

Crate turbomcp_websocket 

Source
Expand description

§TurboMCP WebSocket Transport

WebSocket bidirectional transport implementation for the TurboMCP SDK. This crate provides MCP 2025-11-25 bidirectional communication, server-initiated requests, and elicitation handling.

§Features

  • Bidirectional Communication: Full request-response patterns with correlation
  • Elicitation Support: Server-initiated requests with timeout handling
  • Automatic Reconnection: Configurable exponential backoff retry logic
  • Keep-Alive: Periodic ping/pong to maintain connections
  • Compression: Optional message compression support
  • TLS Support: Secure WebSocket connections (WSS)
  • Metrics Collection: Comprehensive transport metrics and monitoring
  • Background Tasks: Efficient management of concurrent operations

§Quick Start

use turbomcp_websocket::{WebSocketBidirectionalTransport, WebSocketBidirectionalConfig};
use turbomcp_transport_traits::Transport;

// Create client configuration
let config = WebSocketBidirectionalConfig::client("ws://localhost:8080".to_string())
    .with_max_concurrent_elicitations(5)
    .with_compression(true);

// Create and connect transport
let transport = WebSocketBidirectionalTransport::new(config).await?;
transport.connect().await?;

// Use the transport...

§Architecture

The WebSocket transport is organized into focused components:

turbomcp-websocket/
├── config.rs        # Configuration types and builders
├── types.rs         # Core types and type aliases
├── connection.rs    # Connection management and lifecycle
├── tasks.rs         # Background task management
├── elicitation.rs   # Elicitation handling and timeout management
├── mcp_methods.rs   # MCP protocol method implementations
├── transport.rs     # Main Transport trait implementation
└── bidirectional.rs # BidirectionalTransport trait implementation

Re-exports§

pub use bidirectional::CorrelationInfo;
pub use config::ReconnectConfig;
pub use config::TlsConfig;
pub use config::WebSocketBidirectionalConfig;
pub use elicitation::ElicitationInfo;
pub use transport::TransportStatus;
pub use types::MessageProcessingResult;
pub use types::PendingElicitation;
pub use types::WebSocketBidirectionalTransport;
pub use types::WebSocketConnectionStats;
pub use types::WebSocketStreamHandler;

Modules§

bidirectional
Bidirectional transport implementation for WebSocket
config
Configuration types for WebSocket bidirectional transport
connection
Connection management for WebSocket bidirectional transport
elicitation
Elicitation handling for WebSocket bidirectional transport
mcp_methods
MCP bidirectional methods for WebSocket transport
tasks
Background task management for WebSocket bidirectional transport
transport
Main transport implementation for WebSocket bidirectional transport
types
Core types and type aliases for WebSocket bidirectional transport

Structs§

ConnectionState
Connection state for bidirectional communication
CorrelationContext
Correlation context for request-response patterns
TransportCapabilities
Describes the capabilities of a transport implementation.
TransportConfig
Configuration for a transport instance.
TransportEventEmitter
An emitter for broadcasting TransportEvents to listeners.
TransportMessage
A wrapper for a message being sent or received over a transport.
TransportMessageMetadata
Metadata associated with a TransportMessage.
TransportMetrics
A serializable snapshot of a transport’s performance metrics.

Enums§

MessageDirection
Message direction in the transport layer
TransportError
Represents errors that can occur during transport operations.
TransportEvent
Represents events that occur within a transport’s lifecycle.
TransportState
Represents the current state of a transport connection.
TransportType
Enumerates the types of transports supported by the system.

Traits§

BidirectionalTransport
A trait for transports that support full-duplex, bidirectional communication.
Transport
The core trait for all transport implementations.

Type Aliases§

TransportResult
A specialized Result type for transport operations.