Stdio
Category: Mcp_client
Source: stdio.dart
Subprocess-backed JSON-RPC transport for MCP stdio servers.
Wraps Process.start with: • env hygiene — scrub the parent environment to a small allowlist so user secrets (OPENAI_API_KEY, AWS creds, .netrc) don't leak into every MCP server they install. Explicitly listed env: entries from the server config are added back. • clean shutdown — close() sends SIGTERM, waits 2s, then SIGKILL. • exposes the underlying [JsonRpcTransport] surface for [McpClient].
Orphan-prevention (PR_SET_PDEATHSIG on Linux, kqueue watchdog on macOS) is a deferred follow-up — for now we rely on the SIGTERM path during normal Glue shutdown.
Classes
McpStdioTransportSpawnError
Constructor
const McpStdioTransportSpawnError(this.command, this.cause)Properties
| Property | Type | Description |
|---|---|---|
command | String | |
cause | Object |
Methods
String toString()
McpStdioTransport
Properties
| Property | Type | Description |
|---|---|---|
incoming | Stream<JsonRpcMessage> get | |
pid | int get | The OS PID of the spawned server. Useful for tests and diagnostics. |
exitCode | Future<int> get | Resolves to the child's exit code. Lets callers detect "the server died on its own" vs. "we shut it down". |
incoming | Stream<JsonRpcMessage> get | |
pid | int get | The OS PID of the spawned server. Useful for tests and diagnostics. |
exitCode | Future<int> get | Resolves to the child's exit code. Lets callers detect "the server died on its own" vs. "we shut it down". |
Methods
`static Future<McpStdioTransport> spawn({
required String command,
List<String> args = const [],
Map<String, String> extraEnv = const {},
String? workingDirectory,
bool inheritFullEnv = false,
})`
Spawn a subprocess. The child receives only [_alwaysForwardedEnvKeys] plus any keys in [extraEnv] (which is the server config's env: block resolved through env-var interpolation).
Pass [inheritFullEnv] = true to opt out of scrubbing (matches Claude Desktop's behaviour) — should be rare and explicit.
void send(JsonRpcMessage message)
Future<void> close()
Functions
`Map<String, String> buildMcpStdioEnv(
Map<String, String> parent, Map<String, String> extra, )`
Builds the env the child subprocess sees: the always-forwarded allowlist from [parent] plus any [extra] keys from the server config. extra wins on conflict (the config is the authority).
Public for testing. Production code uses it via [McpStdioTransport.spawn].