Struct StdioTransport

Source
pub struct StdioTransport { /* private fields */ }
Expand description

Implements a standard I/O transport for MCP communication.

This module provides the StdioTransport struct, which serves as a transport layer for the Model Context Protocol (MCP) using standard input/output (stdio). It supports both client-side and server-side communication by optionally launching a subprocess or using the current process’s stdio streams. The transport handles message streaming, dispatching, and shutdown operations, integrating with the MCP runtime ecosystem.

Implementations§

Source§

impl StdioTransport

Source

pub fn new(options: TransportOptions) -> Result<StdioTransport, TransportError>

Creates a new StdioTransport instance for MCP Server.

This constructor configures the transport to use the current process’s stdio streams,

§Arguments
  • options - Configuration options for the transport, including timeout settings.
§Returns

A TransportResult containing the initialized StdioTransport instance.

§Errors

Currently, this method does not fail, but it returns a TransportResult for API consistency.

Source

pub fn create_with_server_launch<C>( command: C, args: Vec<String>, env: Option<HashMap<String, String>>, options: TransportOptions, ) -> Result<StdioTransport, TransportError>
where C: Into<String>,

Creates a new StdioTransport instance with a subprocess for MCP Client use.

This constructor configures the transport to launch a MCP Server with a specified command arguments and optional environment variables

§Arguments
  • command - The command to execute (e.g., “rust-mcp-filesystem”).
  • args - Arguments to pass to the command. (e.g., “~/Documents”).
  • env - Optional environment variables for the subprocess.
  • options - Configuration options for the transport, including timeout settings.
§Returns

A TransportResult containing the initialized StdioTransport instance, ready to launch the MCP server on start.

Trait Implementations§

Source§

impl<R, S> Transport<R, S> for StdioTransport
where R: RpcMessage + Clone + Send + Sync + DeserializeOwned + 'static, S: McpMessage + Clone + Send + Sync + Serialize + 'static,

Source§

fn start<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(Pin<Box<dyn Stream<Item = R> + Send>>, MessageDispatcher<R>, IoStream), TransportError>> + Send + 'async_trait>>
where 'life0: 'async_trait, MessageDispatcher<R>: McpDispatch<R, S>, StdioTransport: 'async_trait,

Starts the transport, initializing streams and the message dispatcher.

If configured with a command (MCP Client), launches the MCP server and connects its stdio streams. Otherwise, uses the current process’s stdio for server-side communication.

§Returns

A TransportResult containing:

  • A pinned stream of incoming messages.
  • A MessageDispatcher<R> for sending messages.
  • An IoStream for stderr (readable) or stdout (writable) depending on the mode.
§Errors

Returns a TransportError if the subprocess fails to spawn or stdio streams cannot be accessed.

Source§

fn is_shut_down<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where 'life0: 'async_trait, StdioTransport: 'async_trait,

Checks if the transport has been shut down.

Source§

fn shut_down<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>
where 'life0: 'async_trait, StdioTransport: 'async_trait,

Sends a shutdown signal via the watch channel and kills the subprocess if present.

§Returns

A TransportResult indicating success or failure.

§Errors

Returns a TransportError if the shutdown signal fails or the process cannot be killed.

Auto Trait Implementations§

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: 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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,