pub struct StdioTransport<R>{ /* 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<R> StdioTransport<R>
impl<R> StdioTransport<R>
Sourcepub fn new(
options: TransportOptions,
) -> Result<StdioTransport<R>, TransportError>
pub fn new( options: TransportOptions, ) -> Result<StdioTransport<R>, 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<R>, TransportError>
pub fn create_with_server_launch<C>( command: C, args: Vec<String>, env: Option<HashMap<String, String>>, options: TransportOptions, ) -> Result<StdioTransport<R>, 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 McpDispatch<ClientMessages, ServerMessages, ClientMessage, ServerMessage> for StdioTransport<ClientMessage>
impl McpDispatch<ClientMessages, ServerMessages, ClientMessage, ServerMessage> for StdioTransport<ClientMessage>
Source§fn send_message<'life0, 'async_trait>(
&'life0 self,
message: ServerMessages,
request_timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<ClientMessages>, TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
StdioTransport<ClientMessage>: 'async_trait,
fn send_message<'life0, 'async_trait>(
&'life0 self,
message: ServerMessages,
request_timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<ClientMessages>, TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
StdioTransport<ClientMessage>: 'async_trait,
S
and optionally includes a request_id
.
The request_id
is used when sending a message in response to an MCP request.
It should match the request_id
of the original request.fn send<'life0, 'async_trait>(
&'life0 self,
message: ServerMessage,
request_timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<ClientMessage>, TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
StdioTransport<ClientMessage>: 'async_trait,
fn send_batch<'life0, 'async_trait>(
&'life0 self,
message: Vec<ServerMessage>,
request_timeout: Option<Duration>,
) -> Pin<Box<dyn Future<Output = Result<Option<Vec<ClientMessage>>, TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
StdioTransport<ClientMessage>: 'async_trait,
Source§fn write_str<'life0, 'life1, 'async_trait>(
&'life0 self,
payload: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
StdioTransport<ClientMessage>: 'async_trait,
fn write_str<'life0, 'life1, 'async_trait>(
&'life0 self,
payload: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<(), TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
StdioTransport<ClientMessage>: 'async_trait,
Source§impl<R, S, M, OR, OM> Transport<R, S, M, OR, OM> for StdioTransport<M>
impl<R, S, M, OR, OM> Transport<R, S, M, OR, OM> for StdioTransport<M>
Source§fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ReceiverStream<R>, TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
MessageDispatcher<M>: McpDispatch<R, OR, M, OM>,
StdioTransport<M>: 'async_trait,
fn start<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<ReceiverStream<R>, TransportError>> + Send + 'async_trait>>where
'life0: 'async_trait,
MessageDispatcher<M>: McpDispatch<R, OR, M, OM>,
StdioTransport<M>: '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<M>: '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<M>: 'async_trait,
Checks if the transport has been shut down.