Skip to main content

StdioTransport

Struct StdioTransport 

Source
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>
where R: Read, W: Write,

Source

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>

Source

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>
where R: Read, W: Write,

Helper to create request/response without cloning for internal use.

Source

pub fn send_request_direct( &mut self, cx: &Cx, request: &JsonRpcRequest, ) -> Result<(), TransportError>

Send a request directly (avoids clone in trait method).

Source

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>
where R: Read, W: Write,

Source§

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>

Receive the next JSON-RPC message from this transport. Read more
Source§

fn close(&mut self) -> Result<(), TransportError>

Close the transport gracefully. Read more
Source§

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>

Send a response through this transport. Read more
Source§

impl<R, W> TwoPhaseTransport for StdioTransport<R, W>
where R: Read, W: Write,

Source§

type Writer = W

The writer type for permits.
Source§

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>
where W: Freeze, R: Freeze,

§

impl<R, W> RefUnwindSafe for StdioTransport<R, W>

§

impl<R, W> Send for StdioTransport<R, W>
where W: Send, R: Send,

§

impl<R, W> Sync for StdioTransport<R, W>
where W: Sync, R: Sync,

§

impl<R, W> Unpin for StdioTransport<R, W>
where W: Unpin, R: Unpin,

§

impl<R, W> UnwindSafe for StdioTransport<R, W>
where W: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more