> ## Documentation Index
> Fetch the complete documentation index at: https://axe-engine.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Agents over MCP

> Let an agent drive the sandbox directly through Model Context Protocol tools: run commands, follow their output and handle files.

axed can serve the [Model Context Protocol](https://modelcontextprotocol.io) (MCP), so an agent host such as Claude Code, or your own harness, can use the sandbox through tools, with no SDK or glue code in between. It is off by default. Each `--mcp-listen` endpoint you add serves MCP at the path `/mcp`.

MCP drives a sandbox that already exists. Creating, routing to and deleting sandboxes stays with your platform.

## Turn it on

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
axed --mcp-listen tcp://0.0.0.0:7070 --auth-token-file /etc/axe/token
```

With the default image, publish the port and pass the flags after the image name. The image runs as user 1000, so the token file must be readable by it:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
echo -n "$(openssl rand -hex 16)" > token
docker run -d --name axed -p 127.0.0.1:7070:7070 -v "$PWD/token:/run/token:ro" \
  ghcr.io/vincent0426/axe:latest --mcp-listen tcp://0.0.0.0:7070 --auth-token-file /run/token
```

`--mcp-listen` takes the same URIs as `--listen`: `tcp://`, `unix://`, `vsock://` and `fd://`, repeatable, with `?auth=none` allowed except on TCP. See [Listeners and auth](https://axe-engine.mintlify.site/reference/axed.md#listeners-and-auth). It is independent of the other APIs: the native API, the Agent Sandbox adapter and the Agent Substrate adapter keep running as configured, and processes started over MCP show up in `axectl ps` like any other.

With a token configured, clients send it as `Authorization: Bearer <token>`. Anyone who can call these tools can run any command as axed's user, so always set a token on a TCP endpoint. See [Security](#security).

## Connect a client

Point any MCP client that supports the Streamable HTTP transport at `http://<sandbox>:7070/mcp`, with the token as a header. For example, with Claude Code:

```sh theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
claude mcp add --transport http sandbox http://localhost:7070/mcp \
  --header "Authorization: Bearer $(cat token)"
```

From the official SDKs, pass the header to the Streamable HTTP transport. In TypeScript:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";

const client = new Client({ name: "my-agent", version: "1.0.0" });
await client.connect(new StreamableHTTPClientTransport(new URL("http://localhost:7070/mcp"), {
  requestInit: { headers: { Authorization: `Bearer ${token}` } },
}));
const result = await client.callTool({ name: "run", arguments: { command: "ls -la" } });
```

In Python, with the `mcp` package (version 2), pass an HTTP client that carries the header. Turn off its read timeout, which defaults to 5 seconds, shorter than `run` waits:

```python theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import asyncio
import httpx2
from mcp import Client
from mcp.client.streamable_http import streamable_http_client

async def main(token: str):
    http = httpx2.AsyncClient(headers={"Authorization": f"Bearer {token}"}, timeout=None)
    async with Client(streamable_http_client("http://localhost:7070/mcp", http_client=http)) as client:
        result = await client.call_tool("run", {"command": "ls -la"})
        print(result.structured_content["output"])

asyncio.run(main(open("token").read().strip()))
```

The end-to-end suite (`tests/run.sh mcp`) runs the TypeScript SDK v1, the TypeScript client v2 and the Python SDK against axed. Each connects with the `2025-11-25` handshake, and the TypeScript client v2 and the Python SDK also with `2026-07-28`.

## Tools

| Tool | Arguments | What it does |
| - | - | - |
| `run` | `command`; optional `cwd`, `env`, `input`, `keep_input_open`, `timeout_seconds`, `wait_seconds`, `name`, `max_bytes` | Runs a shell command (`/bin/sh -c`) and waits up to `wait_seconds` (default 30) for it to exit. Returns the exit status and the combined stdout and stderr. A command still running then keeps running in the background. |
| `read_output` | `process`; optional `offset`, `tail`, `wait_seconds`, `max_bytes` | Returns a process's output from `offset`, usually the `next_offset` of the last call, or its last `tail` bytes, and its state. With `wait_seconds`, waits up to that long for the process to exit first. |
| `send_input` | `process`; optional `input`, `close` | Writes to the stdin of a process started with `keep_input_open`, and closes it with `close`. |
| `kill` | `process`; optional `signal`, `wait_seconds` | Sends a signal (default `TERM`) to a process and its process group, then waits up to `wait_seconds` (default 5) for it to exit. |
| `list_processes` | none | Lists the processes axed tracks, running and recently exited. |
| `read_file` | `path`; optional `offset`, `max_bytes`, `encoding` | Reads a file from `offset`, up to `max_bytes`. UTF-8 text comes back as is and anything else base64-encoded; `encoding: base64` forces base64. |
| `write_file` | `path`, `content`; optional `append`, `encoding` | Writes a file, creating missing parent directories. A replacement is atomic and keeps the file's permissions. With `append`, appends instead. `encoding: base64` takes binary content. |
| `list_dir` | optional `path` (default the root), `depth` | Lists a directory, up to `depth` levels (default 1, at most 10). |

Processes are named by their id or by the `name` given to `run`. Paths are relative to `--root-dir` and [confined](https://axe-engine.mintlify.site/files/confinement.md) to it like every other file operation.

Each tool's input schema in `tools/list` describes every argument. Each result has a text part and `structuredContent` with the same information: process results carry `id`, `output`, `state`, `exit_code`, `signal`, `exit_reason`, `next_offset`, `output_end` and `dropped_bytes`. A tool that fails returns its error as a result with `isError: true`, so the model can read it and correct the call.

### Long-running commands

`run` returns after `wait_seconds` even if the command is still running, so a build or a dev server never blocks the agent or hits the client's request timeout. The process keeps running whether or not the client stays connected. Continue with `read_output` from the returned `next_offset`: each call returns only what is new, and a character is never split between calls. To check on a process without reading everything it printed, such as a dev server started earlier, pass `tail` for its last bytes instead, for example `{"process": "dev", "tail": 4000}`. With `wait_seconds` too, `tail` waits for the exit first, so it returns the end of a build's output once the build finishes.

A background job the command starts, such as `npm run dev &`, keeps running after the command exits. While it holds the command's output open, axed waits up to 5 seconds for more output before reporting the exit. Redirect the job's output, as in `npm run dev > dev.log 2>&1 &`, and the exit is reported at once.

`wait_seconds` is at most 300. Keep it below your client's request timeout, which is 60 seconds in the TypeScript SDK by default.

### Limits

* Each call returns at most `max_bytes` of output or file content (default 64 KiB, at most 1 MiB). The rest is read from `next_offset`. Agent hosts limit the size of a tool result: Claude Code, for example, saves a result over about 50,000 characters to a local file and has the model read that file instead. An agent that cannot read local files should pass a smaller `max_bytes`, such as 32768.
* axed keeps `--retain` bytes of output per process (default 1 MiB). Output older than that is discarded, and the next read reports how much as `dropped_bytes`.
* `list_dir` fails on a listing of more than 2,000 entries or 1 MiB of names. List a subdirectory or a smaller `depth`.
* A request is at most 16 MiB, which bounds a `write_file`, base64 included.
* [Default policies](https://axe-engine.mintlify.site/reference/axed.md#default-policies) and `--default-user` apply as on every other API. A `timeout_seconds` above `--max-timeout` fails.
* `run` needs `/bin/sh` in the sandbox.

## Protocol

axed serves MCP's Streamable HTTP transport without sessions. Every request is a single JSON-RPC message sent with `POST /mcp`, and gets one `application/json` response. `GET` and `DELETE` get `405`, and batches are refused.

It serves both generations of the protocol, so older and newer clients both work:

| Client sends | axed serves |
| - | - |
| `_meta` with `io.modelcontextprotocol/protocolVersion` on each request | Version `2026-07-28`, stateless: `server/discover`, `tools/list` and `tools/call`, with the `MCP-Protocol-Version` and `Mcp-Method` headers, and `Mcp-Name` on `tools/call`, checked against the body |
| `initialize` | Versions `2025-11-25`, `2025-06-18` and `2025-03-26`: the handshake, `ping`, `tools/list` and `tools/call` |

## Security

The tools give whoever calls them a shell in the sandbox as axed's user. Treat an MCP endpoint like any other axed listener:

* **Use a token on TCP.** axed logs a warning at startup when any TCP listener, MCP included, has no token. `--auth-token-file` and `--auth-token-sha256` cover MCP listeners too, and [rotation](https://axe-engine.mintlify.site/deploy/security.md#rotate-the-token) works the same way. MCP accepts the token only as `Authorization: Bearer`.
* **Browsers need a token.** Without a token, axed refuses any request that carries an `Origin` header with `403`, so a web page cannot reach a local endpoint through DNS rebinding.
* **Prefer a channel the platform controls.** For an agent host on the same machine, `unix:///path?auth=none` is created with mode `0600`. For a microVM, `vsock://any:PORT?auth=none` refuses connections from inside the guest.
* **Run commands as another user** with `--default-user`, so the agent's commands do not run with axed's own permissions. See [Run processes as another user](https://axe-engine.mintlify.site/deploy/security.md#run-processes-as-another-user).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.