Class StdioMcpClient
java.lang.Object
com.shaft.commandline.mcp.AbstractMcpClient
com.shaft.commandline.mcp.StdioMcpClient
- All Implemented Interfaces:
McpClient, AutoCloseable
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 Summary
ConstructorsConstructorDescriptionStdioMcpClient(InputStream serverStdout, OutputStream serverStdin) Wraps an already-connected pair of streams. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()static StdioMcpClientSpawns a shaft-mcp stdio child from the given command and connects to it.Methods inherited from class AbstractMcpClient
callTool, callToolRaw, initialize, listTools, listTools, listToolsRaw, listToolsRaw
-
Constructor Details
-
StdioMcpClient
Wraps an already-connected pair of streams. Used for in-process testing.- Parameters:
serverStdout- the stream carrying the server's JSON-RPC outputserverStdin- the stream to write JSON-RPC requests to
-
-
Method Details
-
spawn
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()
-