Skip to main content

Module registry

Module registry 

Source
Expand description

Global pending response registry for bidirectional communication

This module provides a global registry for pending bidirectional requests, enabling transports like MCP (which are fundamentally request-response) to route responses back to the correct BidirChannel.

§Architecture

  1. When a BidirChannel sends a request, it registers a callback in this registry
  2. The transport (e.g., MCP) sends the request to the client as a notification
  3. The client responds via a tool call (e.g., _plexus_respond)
  4. The transport looks up the request in this registry and forwards the response
  5. The registry callback deserializes and sends to the waiting BidirChannel

§Thread Safety

The registry uses a RwLock for concurrent read access with exclusive write access. Registrations and lookups are fast; response handling is done outside the lock.

Functions§

handle_pending_response
Handle a response for a pending request
is_request_pending
Check if a request is pending
pending_count
Get the count of pending requests (for monitoring/debugging)
register_pending_request
Register a pending request in the global registry
unregister_pending_request
Remove a pending request from the registry (e.g., on timeout)