Entropic 2.3.8
Local-first agentic inference engine
Loading...
Searching...
No Matches
entropic::StdioTransport Class Reference

Stdio transport: fork/exec child, pipe stdin/stdout. More...

#include <entropic/mcp/transport_stdio.h>

Inheritance diagram for entropic::StdioTransport:
Collaboration diagram for entropic::StdioTransport:

Public Member Functions

 StdioTransport (std::string command, std::vector< std::string > args, std::map< std::string, std::string > env={}, uint32_t default_timeout_ms=30000)
 Construct with command, arguments, and environment.
 
 StdioTransport (std::string display_name, std::string command, std::vector< std::string > args, std::map< std::string, std::string > env, uint32_t default_timeout_ms)
 Construct with a display name for stderr labeling (gh#19).
 
 ~StdioTransport () override
 Destructor — ensures child is cleaned up.
 
bool open () override
 Spawn child process and open pipes.
 
void close () override
 Send SIGTERM, reap child, close pipes.
 
std::string send_request (const std::string &request_json, uint32_t timeout_ms=0) override
 Send JSON-RPC request via stdin, read response from stdout.
 
bool is_connected () const override
 Check if child process is alive.
 
void interrupt () override
 Abort any blocking read and mark transport uncancellable.
 
const std::string & display_name () const
 Get the sanitized display name used for stderr labeling.
 

Detailed Description

Stdio transport: fork/exec child, pipe stdin/stdout.

JSON-RPC 2.0 over newline-delimited JSON. Child process lifetime tied to transport lifetime (SIGTERM on close, SIGKILL if needed).

Version
1.8.7

Definition at line 37 of file transport_stdio.h.

Constructor & Destructor Documentation

◆ StdioTransport() [1/2]

entropic::StdioTransport::StdioTransport ( std::string  command,
std::vector< std::string >  args,
std::map< std::string, std::string >  env = {},
uint32_t  default_timeout_ms = 30000 
)

Construct with command, arguments, and environment.

Parameters
commandExecutable to spawn.
argsCommand-line arguments.
envEnvironment variable overrides (merged with parent).
default_timeout_msDefault timeout for send_request (0 = 30s).
Version
1.8.7
Parameters
commandExecutable to spawn.
argsCommand-line arguments.
envEnvironment variable overrides.
default_timeout_msDefault request timeout.

Definition at line 82 of file transport_stdio.cpp.

◆ StdioTransport() [2/2]

entropic::StdioTransport::StdioTransport ( std::string  display_name,
std::string  command,
std::vector< std::string >  args,
std::map< std::string, std::string >  env,
uint32_t  default_timeout_ms 
)

Construct with a display name for stderr labeling (gh#19).

Construct with explicit display name (gh#19, v2.1.5).

The display name is used as the bracketed label on every child stderr line, replacing the v2.1.4 behavior of using the resolved spawn command (argv[0]). When multiple servers spawn via the same entrypoint (e.g. /usr/bin/env python), the command-based label collides and consumers cannot tell servers apart. The display name (typically the registered server name) is unique per registration and free of leading slashes, which also avoids Rich BBCode parsing collisions on consumers that pipe stderr through rich.console.print.

Parameters
display_nameBracketed label used for stderr lines and lifecycle log messages. Should be the server name passed to entropic_register_mcp_server.
commandExecutable to spawn.
argsCommand-line arguments.
envEnvironment variable overrides.
default_timeout_msDefault timeout for send_request.
Version
2.1.5

Use this overload when registering an MCP server so stderr lines carry the registered server name instead of the resolved spawn command.

Parameters
display_nameBracketed label for stderr/lifecycle logs.
commandExecutable to spawn.
argsCommand-line arguments.
envEnvironment variable overrides.
default_timeout_msDefault request timeout.

Definition at line 108 of file transport_stdio.cpp.

◆ ~StdioTransport()

entropic::StdioTransport::~StdioTransport ( )
override

Destructor — ensures child is cleaned up.

Definition at line 126 of file transport_stdio.cpp.

Member Function Documentation

◆ close()

void entropic::StdioTransport::close ( )
overridevirtual

Send SIGTERM, reap child, close pipes.

Version
1.8.7

Implements entropic::Transport.

Definition at line 210 of file transport_stdio.cpp.

◆ display_name()

const std::string & entropic::StdioTransport::display_name ( ) const
inline

Get the sanitized display name used for stderr labeling.

Exposed for unit tests (gh#19) and consumer diagnostics. The value is the bracketed label that appears in log lines from the stderr pump and lifecycle events. Sanitization (leading / stripped, bracket / control chars removed) is applied at construction.

Returns
Reference to the sanitized display name. @utility
Version
2.1.5

Definition at line 141 of file transport_stdio.h.

◆ interrupt()

void entropic::StdioTransport::interrupt ( )
overridevirtual

Abort any blocking read and mark transport uncancellable.

Cancel any in-flight read by tripping cancel_flag_.

Sets cancel_flag_ which poll_until_ready() checks after every poll tick. The next send_request() returns empty immediately. (P1-10, 2.0.6-rc16)

Version
2.0.6-rc16

read_line / poll_until_ready short-circuit the next poll tick so the pending send_request returns empty within ~50ms (one poll slice). Subsequent send_request calls also early-exit until the flag is cleared implicitly by a successful open(). (P1-10)

Reimplemented from entropic::Transport.

Definition at line 285 of file transport_stdio.cpp.

◆ is_connected()

bool entropic::StdioTransport::is_connected ( ) const
overridevirtual

Check if child process is alive.

Check if child process is alive via kill(pid, 0).

Returns
true if connected.
Version
1.8.7
Returns
true if connected.

Implements entropic::Transport.

Definition at line 264 of file transport_stdio.cpp.

◆ open()

bool entropic::StdioTransport::open ( )
overridevirtual

Spawn child process and open pipes.

Returns
true on success.
Version
1.8.7
Returns
true on success.

Implements entropic::Transport.

Definition at line 154 of file transport_stdio.cpp.

◆ send_request()

std::string entropic::StdioTransport::send_request ( const std::string &  request_json,
uint32_t  timeout_ms = 0 
)
overridevirtual

Send JSON-RPC request via stdin, read response from stdout.

Parameters
request_jsonJSON-RPC request string.
timeout_msTimeout in milliseconds (0 = default).
Returns
JSON-RPC response string, or empty on error/timeout.
Version
1.8.7
Parameters
request_jsonJSON-RPC request string.
timeout_msTimeout (0 = default).
Returns
Response string, or empty on error.

Implements entropic::Transport.

Definition at line 233 of file transport_stdio.cpp.


The documentation for this class was generated from the following files: