pub struct ServerToClientAdapter { /* private fields */ }Expand description
Adapter that implements the ServerToClientRequests trait by delegating to BidirectionalRouter.
This adapter bridges the gap between the generic ServerToClientRequests trait (defined in
turbomcp-protocol) and the concrete BidirectionalRouter implementation (in turbomcp-server).
§Thread Safety
This adapter is Send + Sync because:
BidirectionalRouterimplementsCloneand contains onlyArc<dyn ServerRequestDispatcher>- All interior state is immutable after construction
§Performance
Zero-overhead abstraction:
- No intermediate serialization (types flow directly through)
- One
Arcclone when creating the adapter (shared state) - Direct delegation to underlying router (no indirection)
- Context propagation with zero allocation
§Design Improvement (v2.0.0)
Previously named ServerCapabilitiesAdapter, this was renamed to ServerToClientAdapter
for clarity and redesigned to eliminate double serialization.
Implementations§
Source§impl ServerToClientAdapter
impl ServerToClientAdapter
Sourcepub fn new(bidirectional: BidirectionalRouter) -> Self
pub fn new(bidirectional: BidirectionalRouter) -> Self
Create a new adapter wrapping a bidirectional router.
§Example
use turbomcp_server::capabilities::ServerToClientAdapter;
use turbomcp_server::routing::BidirectionalRouter;
let router = BidirectionalRouter::new();
let adapter = ServerToClientAdapter::new(router);Sourcepub fn supports_bidirectional(&self) -> bool
pub fn supports_bidirectional(&self) -> bool
Check if bidirectional communication is supported.
Returns true if a dispatcher has been configured, false otherwise.
Trait Implementations§
Source§impl Clone for ServerToClientAdapter
impl Clone for ServerToClientAdapter
Source§fn clone(&self) -> ServerToClientAdapter
fn clone(&self) -> ServerToClientAdapter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for ServerToClientAdapter
impl Debug for ServerToClientAdapter
Source§impl ServerToClientRequests for ServerToClientAdapter
impl ServerToClientRequests for ServerToClientAdapter
Source§fn create_message(
&self,
request: CreateMessageRequest,
ctx: RequestContext,
) -> BoxFuture<'_, Result<CreateMessageResult, McpError>>
fn create_message( &self, request: CreateMessageRequest, ctx: RequestContext, ) -> BoxFuture<'_, Result<CreateMessageResult, McpError>>
Send a sampling/createMessage request to the client Read more
Source§fn elicit(
&self,
request: ElicitRequest,
ctx: RequestContext,
) -> BoxFuture<'_, Result<ElicitResult, McpError>>
fn elicit( &self, request: ElicitRequest, ctx: RequestContext, ) -> BoxFuture<'_, Result<ElicitResult, McpError>>
Send an elicitation request to the client for user input Read more
Source§fn list_roots(
&self,
ctx: RequestContext,
) -> BoxFuture<'_, Result<ListRootsResult, McpError>>
fn list_roots( &self, ctx: RequestContext, ) -> BoxFuture<'_, Result<ListRootsResult, McpError>>
List client’s root capabilities Read more
Auto Trait Implementations§
impl Freeze for ServerToClientAdapter
impl !RefUnwindSafe for ServerToClientAdapter
impl Send for ServerToClientAdapter
impl Sync for ServerToClientAdapter
impl Unpin for ServerToClientAdapter
impl !UnwindSafe for ServerToClientAdapter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more