pub struct ClientStdioTransport { /* private fields */ }
Expand description
Client transport that communicates with an MCP server over standard I/O.
The ClientStdioTransport
launches a child process specified by the provided
program and arguments, then communicates with it using the standard input and output
streams. It implements the Transport
trait to send requests and receive responses
over these streams.
This transport is useful for:
- Running local MCP servers as child processes
- Command-line tools that need to communicate with MCP servers
- Testing and development scenarios
§Example
use mcp_core::transport::{ClientStdioTransport, Transport};
use anyhow::Result;
async fn example() -> Result<()> {
let transport = ClientStdioTransport::new("my-mcp-server", &["--flag"])?;
transport.open().await?;
// Use transport...
transport.close().await?;
Ok(())
}
Implementations§
Trait Implementations§
Source§impl Clone for ClientStdioTransport
impl Clone for ClientStdioTransport
Source§fn clone(&self) -> ClientStdioTransport
fn clone(&self) -> ClientStdioTransport
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Transport for ClientStdioTransport
impl Transport for ClientStdioTransport
Source§fn open<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn open<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Opens the transport by launching the child process and setting up the communication channels.
This method:
- Spawns the child process with the configured program and arguments
- Sets up pipes for stdin and stdout
- Starts a background task for handling incoming messages
§Returns
A Result
indicating success or failure
Source§fn close<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn close<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Closes the transport by terminating the child process and cleaning up resources.
This method:
- Kills the child process
- Clears the stdin and stdout handles
§Returns
A Result
indicating success or failure
Source§fn poll_message<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<Message>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn poll_message<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Option<Message>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Polls for incoming messages from the child process’s stdout.
This method reads a line from the child process’s stdout and parses it as a JSON-RPC message.
§Returns
A Result
containing an Option<Message>
. None
indicates EOF.
Source§fn request(
&self,
method: &str,
params: Option<Value>,
options: RequestOptions,
) -> Pin<Box<dyn Future<Output = Result<JsonRpcResponse>> + Send + Sync>>
fn request( &self, method: &str, params: Option<Value>, options: RequestOptions, ) -> Pin<Box<dyn Future<Output = Result<JsonRpcResponse>> + Send + Sync>>
Sends a request to the child process and waits for a response.
This method:
- Creates a new request ID
- Constructs a JSON-RPC request
- Sends it to the child process’s stdin
- Waits for a response with the same ID
§Arguments
method
- The method name for the requestparams
- Optional parameters for the requestoptions
- Request options (like timeout)
§Returns
A Future
that resolves to a Result
containing the response