Table of Contents

Class StdioTransport

Namespace
LMKit.Mcp.Transport
Assembly
LM-Kit.NET.dll

MCP transport implementation using stdio (standard input/output) communication with a subprocess.

public sealed class StdioTransport : IMcpTransport, IDisposable
Inheritance
StdioTransport
Implements
Inherited Members

Examples

// Using the filesystem MCP server
var options = new StdioTransportOptions
{
    Command = "npx",
    Arguments = "@modelcontextprotocol/server-filesystem /path/to/dir",
    StderrHandler = line => Console.WriteLine($"[Server] {line}")
};

using var transport = new StdioTransport(options);
await transport.ConnectAsync();

// Send initialize request
var response = await transport.SendRequestAsync(1, "initialize", new { ... });

Remarks

The stdio transport spawns a subprocess and communicates via JSON-RPC 2.0 messages over stdin/stdout using newline-delimited JSON (JSONL) format. This is the standard transport for local MCP servers as defined in the MCP specification.

Message Format: Each JSON-RPC message is written as a single line of JSON followed by a newline character. The transport handles message framing automatically.

Thread Safety: This transport is thread-safe. Multiple concurrent requests can be sent, and responses are correlated by request ID.

Process Lifecycle: The transport manages the subprocess lifecycle including startup, health monitoring, and graceful/forceful termination.

Constructors

StdioTransport(StdioTransportOptions)

Initializes a new stdio transport with detailed options.

StdioTransport(string, string)

Initializes a new stdio transport with the specified command.

Properties

IsConnected

Gets whether the transport connection is currently established and ready for communication.

TransportType

Gets the transport type identifier for logging and diagnostics.

Methods

CloseAsync(CancellationToken)

Closes the transport connection gracefully.

ConnectAsync(CancellationToken)

Establishes the transport connection asynchronously.

Dispose()
SendNotificationAsync(string, object, CancellationToken)

Sends a JSON-RPC notification (fire-and-forget, no response expected).

SendRequestAsync(long, string, object, CancellationToken)

Sends a JSON-RPC request and waits for the corresponding response.

Events

Disconnected

Raised when the transport connection is unexpectedly lost.

ServerNotificationReceived

Raised when a server-initiated notification is received.

StderrReceived

Raised when the subprocess writes to stderr.