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
impl StdioTransport
Sourcepub fn new(options: TransportOptions) -> Result<StdioTransport, TransportError>
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.
Sourcepub fn create_with_server_launch<C>(
command: C,
args: Vec<String>,
env: Option<HashMap<String, String>>,
options: TransportOptions,
) -> Result<StdioTransport, TransportError>
pub fn create_with_server_launch<C>( command: C, args: Vec<String>, env: Option<HashMap<String, String>>, options: TransportOptions, ) -> Result<StdioTransport, TransportError>
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 StdioTransportwhere
R: RpcMessage + Clone + Send + Sync + DeserializeOwned + 'static,
S: McpMessage + Clone + Send + Sync + Serialize + 'static,
impl<R, S> Transport<R, S> for StdioTransportwhere
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>>
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>>
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,
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.