Skip to content
docsv0.1.0

StdioTransport

Stdio Transport for MCP servers. This transport spawns a subprocess and communicates via stdin/stdout. Used for local MCP servers like @anthropic/mcp-server-* packages. Communication flow: 1. Spawn process with given command 2. Send JSON-RPC requests via stdin (newline-delimited) 3. Read JSON-RPC responses from stdout

StdioTransport::__construct()

public function __construct(string $command, array $args = [], array $env = [], ?string $workingDir = null, int $timeout = 30, ?string $serverName = null):

Parameters

Parameters of __construct()
NameTypeDescription
$commandstringCommand to execute
$argsarray<int, string>Command arguments
$envarray<string, string>Environment variables
$workingDir(string | null)Working directory for the process
$timeoutintRequest timeout in seconds
$serverName(string | null)Server name for error messages

StdioTransport::connect()

public function connect(): void

Spawn the configured command as a subprocess and run the MCP handshake over its pipes.

StdioTransport::disconnect()

public function disconnect(): void

Close the pipes and terminate the subprocess.

StdioTransport::isConnected()

public function isConnected(): bool

Check whether the subprocess is still alive.

StdioTransport::request()

public function request(string $method, array $params = []): array

Write a JSON-RPC request to the subprocess's stdin and block for its stdout response.

Parameters

Parameters of request()
NameTypeDescription
$methodstring
$paramsarray<string, mixed>

StdioTransport::notify()

public function notify(string $method, array $params = []): void

Write a JSON-RPC notification to the subprocess's stdin; no response is awaited.

Parameters

Parameters of notify()
NameTypeDescription
$methodstring
$paramsarray<string, mixed>

StdioTransport::__destruct()

public function __destruct():

Destructor ensures process is terminated.