class

Smith::MCP::StdioTransport

Inherits Smith::MCP::Transport < Reference < Object

A child process speaking JSON-RPC over its stdin/stdout.

stderr is drained by its own fiber and never mixed into the protocol stream: servers log to stderr freely, and a single stray line on the wrong stream would otherwise desynchronise the connection.

Constants

GRACE = 3.seconds

Time a terminated server gets to exit before it is killed outright.

STDERR_TAIL = 20

How many stderr lines to keep. Enough to explain a failed handshake, little enough that a chatty server cannot grow the process.

Constructors

new(process : Process)
Source
spawn_server(command : String, args : Array(String) = [] of String, env : Hash(String, String) = Hash(String, String).new, chdir : String | Nil = nil) : StdioTransport
Source

Instance methods

alive?
Source
close

SIGTERM, then SIGKILL. Both are needed: a server that ignores TERM would otherwise be left behind as an orphan holding whatever it opened.

Source
receive

nil at end of stream. Blocking; called only from the reader fiber.

Source
send(line : String) : Nil

One complete message. Framing is line-based, so neither side may embed a raw newline — JSON escapes them, which is why this works at all.

Source
stderr_tail
Source