class

Autobot::Mcp::Client

Inherits Reference < Object

JSON-RPC 2.0 client that communicates with an MCP server over stdio.

Spawns a child process, performs the MCP protocol handshake, and provides methods to discover and call remote tools. All requests are serialized through a mutex (stdio is single-threaded).

Env isolation: only configured env vars + PATH/HOME/LANG are passed. Stderr is drained in a background fiber to prevent the child from blocking.

Constants

ALLOWED_HOST_VARS = {"PATH", "HOME", "LANG"}
CALL_TIMEOUT = 60.seconds
INIT_TIMEOUT = 30.seconds
Log = ::Log.for("mcp.client")
MAX_RESPONSE_SIZE = 50000
PROTOCOL_VERSION = "2025-03-26"
SHUTDOWN_GRACE = 2.seconds

Constructors

new(server_name : String, command : String, args : Array(String) = [] of String, env : Hash(String, String) = {} of String => String)
Source

Instance methods

alive?
Source
call_tool(name : String, arguments : Hash(String, JSON::Any)) : String

Calls a tool on the MCP server and returns the text content. Result is truncated at MAX_RESPONSE_SIZE bytes.

Source
list_tools

Sends tools/list to the server and returns the tool definitions.

Source
server_name
Source
start

Spawns the MCP server process and performs the protocol handshake. Raises on failure (e.g. command not found, handshake timeout).

Source
stop

Gracefully stops the MCP server: SIGTERM, wait, then SIGKILL if needed.

Source