# MCP

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

`hermitbox mcp` exposes a project's sandboxes to MCP clients over stdio or loopback HTTP. On the
machine where you ran the installer, it reads the saved credentials automatically; see
[Use with your agent](https://docs.hermitbox.dev/v0.2.4/get-started/agents.md) for local setup.

## Remote stdio configuration

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.

For a `.mcp.json` configuration:

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

For a `config.toml` configuration:

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

## Loopback HTTP transport

`hermitbox mcp --http 8090` serves stateless Streamable HTTP on `http://127.0.0.1:8090/mcp`
instead. Every request needs `Authorization: Bearer <project-key>`. The HTTP listener checks Host
and Origin and binds loopback.

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 <project-key>" }
    }
  }
}
```

## Tools and resources

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/<sandbox-id>/state` and `hermitbox://sandboxes/<sandbox-id>/logs`.

All calls use the public SDK and keep project admission and isolation. Tool errors are explicit,
and uncertain commands are never resubmitted. File reads are limited to 1 MiB; use SDK streaming for
larger files.

## Per-sandbox MCP endpoint

A single sandbox also has its own MCP endpoint. Get its expiring URL with
`hermitbox sandbox mcp-url <sandbox-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, and its
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.
