class LittleGhost::Harnesses::ToolServer
Serves Tool instances to a harness over the Model Context Protocol’s Streamable HTTP transport on a Unix socket, so a coding-agent tool can call the same tools as the Agent that delegated to it.
registry = LittleGhost::ToolRegistry.new([HelpCenterLookupTool], binding:) server = LittleGhost::Harnesses::ToolServer.new( tools: registry, socket_path: "/run/harness-tools/tools.sock", context: ).start # The harness reaches the socket through a relay at http://127.0.0.1:3133/mcp. server.close
Each call runs Tool#execute with context, so the Run’s cancellation and deadline stop it, and returns the tool’s content as text with isError set for failed calls. The server answers initialize, ping, tools/list, and tools/call with JSON responses and accepts notifications; it does not open server-to-client streams.
Calls run Tool#execute directly: Agent callbacks such as :before_tool, tool instrumentation, and the exclusive-tool lock, which the delegating Harnesses::Tool already holds, do not apply. Serve only tools whose safeguards live in the tool itself.
Anyone who can connect to the socket can call every served tool, so keep socket_path in a directory that only the harness can reach. start raises ToolError when another server is already listening there. Harnesses::Tool#serve_tools starts one server per delegated task.
Constants
- ENDPOINT
Attributes
Filesystem path of the listening socket.
Public Class Methods
# File lib/little_ghost/harnesses/tool_server.rb, line 51 def initialize(tools:, socket_path:, context: nil, name: "little_ghost", mode: 0o600) @tools = tools.to_h { |tool| [tool.tool_name, tool] }.freeze @socket_path = String(socket_path) raise ArgumentError, "tool server socket_path must be absolute" unless @socket_path.start_with?("/") @context = context @name = String(name) @mode = Integer(mode) @mutex = Mutex.new @clients = [] @workers = [] @stopping = false end
Builds a server for tools, a ToolRegistry or Array of Tool instances, listening at socket_path with permission bits mode. name is reported to clients as the server’s name.
Public Instance Methods
Source
# File lib/little_ghost/harnesses/tool_server.rb, line 78 def close @stopping = true @server&.close unless @server&.closed? @thread&.join unless @thread == Thread.current clients, workers = @mutex.synchronize { [@clients.dup, @workers.dup] } clients.each { |client| client.close unless client.closed? } workers.each do |worker| next if worker.join(SHUTDOWN_TIMEOUT) worker.kill worker.join end remove_socket if @bound @bound = false nil end
Stops accepting, closes open connections, waits briefly for in-flight calls, and removes the socket. Calling close more than once is safe.