<!-- SPDX-License-Identifier: AGPL-3.0-only -->
# MCP

`hermitbox mcp` exposes this project's sandboxes through stdio. On the machine where you ran the
installer, it reads the credentials the installer saved, so no key goes in any agent's config: each
agent's one step is in [Use with your agent](https://docs.hermitbox.dev/v0.2.0/agents.md). For a remote install, set
`HERMITBOX_API_URL` and `HERMITBOX_API_KEY` in the agent's environment, never in a file you share.
Standard output contains only MCP messages. The optional command
`hermitbox mcp --http 8090` instead serves stateless Streamable HTTP on
`http://127.0.0.1:8090/mcp`; every request needs `Authorization: Bearer <project-key>`.
The HTTP listener checks Host and Origin and binds loopback.

For a `.mcp.json` configuration:

```json
{
  "mcpServers": {
    "hermitbox": {
      "command": "hermitbox",
      "args": ["mcp"],
      "env": {
        "HERMITBOX_API_URL": "https://hermitbox.example.com",
        "HERMITBOX_API_KEY": "replace-with-project-key"
      }
    }
  }
}
```

For a `config.toml` configuration:

```toml
[mcp_servers.hermitbox]
command = "hermitbox"
args = ["mcp"]
[mcp_servers.hermitbox.env]
HERMITBOX_API_URL = "https://hermitbox.example.com"
HERMITBOX_API_KEY = "replace-with-project-key"
```

An HTTP configuration uses the same project's key:

```json
{
  "mcpServers": {
    "hermitbox": {
      "type": "http",
      "url": "http://127.0.0.1:8090/mcp",
      "headers": { "Authorization": "Bearer replace-with-project-key" }
    }
  }
}
```

Tools cover create, list, get, delete, run, background start, read, write, list files,
snapshot, fork, sleep, wake, expose and project usage. State and logs are resources under
`hermitbox://sandboxes/<id>/state` and `hermitbox://sandboxes/<id>/logs`. All calls use the public SDK
and retain project admission and isolation. Tool errors are explicit; uncertain commands are
never resubmitted. File reads are limited to 1 MiB; use SDK streaming for larger files.

A single sandbox also has its own MCP endpoint. Obtain its expiring URL with
`hermitbox sandbox mcp-url <id>`, `await box.mcpUrl()` in TypeScript, or `box.mcp_url()` in Python
(`await box.mcp_url()` for the async handle). The URL contains a scoped sandbox capability;
put it in an HTTP client's URL field. It permits only that sandbox, expires on the existing
agent token schedule, and can be regenerated when needed. It contains no project key.
Its tools cover run, background processes, stdin, signals, files and exposed ports;
resources are `hermitbox://sandbox/state` and `hermitbox://sandbox/logs`. Browser Origin requests are
refused. The agent can be built without this optional surface using
`cargo build -p hermitbox-agent --no-default-features --features server`.

Both surfaces speak MCP 2025-11-25.
