Skip to main content

run_proxy_loop

Function run_proxy_loop 

Source
pub async fn run_proxy_loop<CR, CW, UR, UW>(
    client_reader: CR,
    client_writer: Arc<Mutex<CW>>,
    upstream_reader: UR,
    upstream_writer: Arc<Mutex<UW>>,
    engine: Arc<RwLock<Engine>>,
    audit: Arc<Mutex<AuditLogger>>,
    _fail_open: bool,
    approval_backend: Option<Arc<dyn ApprovalBackend>>,
) -> Result<(), Box<dyn Error + Send + Sync>>
where CR: AsyncBufRead + Unpin + Send + 'static, CW: AsyncWrite + Unpin + Send + 'static, UR: AsyncBufRead + Unpin + Send + 'static, UW: AsyncWrite + Unpin + Send + 'static,
Expand description

Runs the bidirectional proxy loop.

Reads MCP JSON-RPC messages from client_reader, evaluates tool calls against the policy engine, forwards allowed messages to upstream_writer, and sends deny/approval responses back through client_writer. Server responses from upstream_reader are forwarded back to client_writer.

If approval_backend is provided, RequireApproval decisions will be sent to the backend for human review. If not provided, they are denied by default (fail-closed).