Expand description
Server-to-client request adapter for bidirectional MCP communication.
This module provides the adapter that bridges the ServerToClientRequests trait
(defined in turbomcp-protocol) to the concrete BidirectionalRouter implementation,
enabling tools to make server-initiated requests to clients.
§Architecture
Tool Handler (ctx.create_message)
↓
ServerToClientRequests trait (turbomcp-protocol) ← TYPE-SAFE INTERFACE
↓
ServerToClientAdapter (this module) ← THE BRIDGE
↓
BidirectionalRouter (turbomcp-server)
↓
ServerRequestDispatcher (transport abstraction)
↓
Transport Layer (stdio, HTTP, WebSocket, etc.)§Design Improvements (v2.0.0)
This adapter was redesigned to leverage the new type-safe trait:
- Before: Double serialization (typed → JSON → typed → JSON)
- After: Zero serialization (typed → typed)
- Before: Cannot propagate RequestContext
- After: Full context propagation for tracing and attribution
- Before: Generic
Box<dyn Error>return type - After: Structured
ServerErrorwith pattern matching
§Bug Fix History
v1.x: Fixed critical bug where RequestContext.server_capabilities was never populated,
causing all sampling/elicitation requests to fail.
v2.0: Improved trait design to eliminate double serialization and enable context propagation.
Structs§
- Server
ToClient Adapter - Adapter that implements the
ServerToClientRequeststrait by delegating toBidirectionalRouter.