# Class LittleGhost::Harnesses::ToolServer

Documentation version: Edge

Canonical HTML: https://littleghostai.org/docs/LittleGhost/Harnesses/ToolServer.html

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.

## Inheritance

`LittleGhost::Harnesses::ToolServer < Object`

## Constants

### `ENDPOINT`

## Attributes

<a id="attribute-i-socket_path"></a>
### `socket_path` (R)

Filesystem path of the listening socket.

## Class methods

<a id="method-c-new"></a>
### `.new`

```ruby
.new(tools:, socket_path:, context: nil, name: "little_ghost", mode: 0o600)
```

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.

## Instance methods

<a id="method-i-close"></a>
### `#close`

```ruby
#close()
```

Stops accepting, closes open connections, waits briefly for in-flight calls,
and removes the socket. Calling `close` more than once is safe.

<a id="method-i-start"></a>
### `#start`

```ruby
#start()
```

Binds the socket and serves requests on a background thread. Returns `self`;
call #close to stop.
