Expand description
Protocol client for JSON-RPC communication
This module provides the ProtocolClient which handles the low-level JSON-RPC protocol communication with MCP servers.
§Bidirectional Communication Architecture
The ProtocolClient uses a MessageDispatcher to solve the bidirectional
communication problem. Instead of directly calling transport.receive(),
which created race conditions when multiple code paths tried to receive,
we now use a centralized message routing layer:
ProtocolClient::request()
↓
1. Register oneshot channel with dispatcher
2. Send request via transport
3. Wait on oneshot channel
↓
MessageDispatcher (background task)
↓
Continuously reads transport.receive()
Routes responses → oneshot channels
Routes requests → Client handlersThis ensures there’s only ONE consumer of transport.receive(), eliminating the race condition.