Class StdioMcpClient

java.lang.Object
com.shaft.commandline.mcp.AbstractMcpClient
com.shaft.commandline.mcp.StdioMcpClient
All Implemented Interfaces:
McpClient, AutoCloseable

public final class StdioMcpClient extends AbstractMcpClient
MCP client speaking newline-delimited JSON-RPC over a child process's stdio (one-shot mode). The server's stdout carries only JSON-RPC messages; its stderr (logs) is drained separately to avoid the classic pipe-buffer deadlock.
  • Constructor Details

    • StdioMcpClient

      public StdioMcpClient(InputStream serverStdout, OutputStream serverStdin)
      Wraps an already-connected pair of streams. Used for in-process testing.
      Parameters:
      serverStdout - the stream carrying the server's JSON-RPC output
      serverStdin - the stream to write JSON-RPC requests to
  • Method Details

    • spawn

      public static StdioMcpClient spawn(List<String> command)
      Spawns a shaft-mcp stdio child from the given command and connects to it. The child's stderr is redirected away from this process so log output cannot block the protocol channel.
      Parameters:
      command - the process command (e.g. [java, @shaft-mcp.args])
      Returns:
      a connected client owning the child process
    • close

      public void close()