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
| Name | Type | Description |
|---|---|---|
| $command | string | Command to execute |
| $args | array<int, string> | Command arguments |
| $env | array<string, string> | Environment variables |
| $workingDir | (string | null) | Working directory for the process |
| $timeout | int | Request timeout in seconds |
| $serverName | (string | null) | Server name for error messages |
StdioTransport::connect()
public function connect(): voidSpawn the configured command as a subprocess and run the MCP handshake over its pipes.
StdioTransport::disconnect()
public function disconnect(): voidClose the pipes and terminate the subprocess.
StdioTransport::isConnected()
public function isConnected(): boolCheck whether the subprocess is still alive.
StdioTransport::request()
public function request(string $method, array $params = []): arrayWrite a JSON-RPC request to the subprocess's stdin and block for its stdout response.
Parameters
| Name | Type | Description |
|---|---|---|
| $method | string | |
| $params | array<string, mixed> |
StdioTransport::notify()
public function notify(string $method, array $params = []): voidWrite a JSON-RPC notification to the subprocess's stdin; no response is awaited.
Parameters
| Name | Type | Description |
|---|---|---|
| $method | string | |
| $params | array<string, mixed> |
StdioTransport::__destruct()
public function __destruct():Destructor ensures process is terminated.