pub struct StdioTransport<R, W> { /* private fields */ }Expand description
Stdio transport implementation.
Reads from stdin and writes to stdout using NDJSON framing. Integrates with asupersync for cancel-correct operation.
§Wire Format
Messages are newline-delimited JSON:
- Each message is serialized as a single line of JSON
- Lines are terminated by
\n(LF, not CRLF) - Empty lines are ignored
- UTF-8 encoding is required
Implementations§
Source§impl<R, W> StdioTransport<R, W>
impl<R, W> StdioTransport<R, W>
Sourcepub fn new(reader: R, writer: W) -> StdioTransport<R, W>
pub fn new(reader: R, writer: W) -> StdioTransport<R, W>
Creates a new stdio transport with custom reader/writer.
This is useful for testing with mock I/O.
Source§impl StdioTransport<Stdin, Stdout>
impl StdioTransport<Stdin, Stdout>
Sourcepub fn stdio() -> StdioTransport<Stdin, Stdout>
pub fn stdio() -> StdioTransport<Stdin, Stdout>
Creates a transport using standard stdin/stdout.
This is the primary constructor for MCP servers running as subprocess.
Source§impl<R, W> StdioTransport<R, W>
Helper to create request/response without cloning for internal use.
impl<R, W> StdioTransport<R, W>
Helper to create request/response without cloning for internal use.
Sourcepub fn send_request_direct(
&mut self,
cx: &Cx,
request: &JsonRpcRequest,
) -> Result<(), TransportError>
pub fn send_request_direct( &mut self, cx: &Cx, request: &JsonRpcRequest, ) -> Result<(), TransportError>
Send a request directly (avoids clone in trait method).
Sourcepub fn send_response_direct(
&mut self,
cx: &Cx,
response: &JsonRpcResponse,
) -> Result<(), TransportError>
pub fn send_response_direct( &mut self, cx: &Cx, response: &JsonRpcResponse, ) -> Result<(), TransportError>
Send a response directly (avoids clone in trait method).
Trait Implementations§
Source§impl<R, W> Transport for StdioTransport<R, W>
impl<R, W> Transport for StdioTransport<R, W>
Source§fn send(
&mut self,
cx: &Cx,
message: &JsonRpcMessage,
) -> Result<(), TransportError>
fn send( &mut self, cx: &Cx, message: &JsonRpcMessage, ) -> Result<(), TransportError>
Send a JSON-RPC message through this transport. Read more
Source§fn recv(&mut self, cx: &Cx) -> Result<JsonRpcMessage, TransportError>
fn recv(&mut self, cx: &Cx) -> Result<JsonRpcMessage, TransportError>
Receive the next JSON-RPC message from this transport. Read more
Source§fn send_request(
&mut self,
cx: &Cx,
request: &JsonRpcRequest,
) -> Result<(), TransportError>
fn send_request( &mut self, cx: &Cx, request: &JsonRpcRequest, ) -> Result<(), TransportError>
Send a request through this transport. Read more
Source§fn send_response(
&mut self,
cx: &Cx,
response: &JsonRpcResponse,
) -> Result<(), TransportError>
fn send_response( &mut self, cx: &Cx, response: &JsonRpcResponse, ) -> Result<(), TransportError>
Send a response through this transport. Read more
Source§impl<R, W> TwoPhaseTransport for StdioTransport<R, W>
impl<R, W> TwoPhaseTransport for StdioTransport<R, W>
Source§fn reserve_send(
&mut self,
cx: &Cx,
) -> Result<SendPermit<'_, <StdioTransport<R, W> as TwoPhaseTransport>::Writer>, TransportError>
fn reserve_send( &mut self, cx: &Cx, ) -> Result<SendPermit<'_, <StdioTransport<R, W> as TwoPhaseTransport>::Writer>, TransportError>
Reserve a send slot. Read more
Auto Trait Implementations§
impl<R, W> Freeze for StdioTransport<R, W>
impl<R, W> RefUnwindSafe for StdioTransport<R, W>where
W: RefUnwindSafe,
R: RefUnwindSafe,
impl<R, W> Send for StdioTransport<R, W>
impl<R, W> Sync for StdioTransport<R, W>
impl<R, W> Unpin for StdioTransport<R, W>
impl<R, W> UnwindSafe for StdioTransport<R, W>where
W: UnwindSafe,
R: UnwindSafe,
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).