Class StdioClientTransport
- Namespace
- ModelContextProtocol.Protocol.Transport
- Assembly
- ModelContextProtocol.dll
Provides a IClientTransport implemented via "stdio" (standard input/output).
public sealed class StdioClientTransport : IClientTransport
- Inheritance
-
StdioClientTransport
- Implements
- Inherited Members
Remarks
This transport launches an external process and communicates with it through standard input and output streams. It's used to connect to MCP servers launched and hosted in child processes.
The transport manages the entire lifecycle of the process: starting it with specified command-line arguments and environment variables, handling output, and properly terminating the process when the transport is closed.
Constructors
StdioClientTransport(StdioClientTransportOptions, ILoggerFactory?)
Initializes a new instance of the StdioClientTransport class.
public StdioClientTransport(StdioClientTransportOptions options, ILoggerFactory? loggerFactory = null)
Parameters
options
StdioClientTransportOptionsConfiguration options for the transport, including the command to execute, arguments, working directory, and environment variables.
loggerFactory
ILoggerFactoryLogger factory for creating loggers used for diagnostic output during transport operations.
Properties
Name
Gets a transport identifier, used for logging purposes.
public string Name { get; }
Property Value
Methods
ConnectAsync(CancellationToken)
Asynchronously establishes a transport session with an MCP server and returns a transport for the duplex message stream.
public Task<ITransport> ConnectAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenThe CancellationToken to monitor for cancellation requests. The default is None.
Returns
- Task<ITransport>
Returns an interface for the duplex message stream.
Remarks
This method is responsible for initializing the connection to the server using the specific transport mechanism implemented by the derived class. The returned ITransport interface provides methods to send and receive messages over the established connection.
The lifetime of the returned ITransport instance is typically managed by the ModelContextProtocol.Client.McpClient that uses this transport. When the client is disposed, it will dispose the transport session as well.
This method is used by McpClientFactory to initialize the connection.
Exceptions
- McpTransportException
The transport connection could not be established.