> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# MCP

> Connect Claude Code, Cursor, VS Code or Codex to a workspace.

Every workspace on the Mirage server is an [MCP](https://modelcontextprotocol.io) server at:

```
http://127.0.0.1:8765/v1/workspaces/{id}/mcp
```

An agent connected to it gets a shell and six file tools over the workspace's
files.

## Connect

On your own machine, let the client launch `mirage mcp`. It starts the server if needed and sends your token.
These examples use the `demo` workspace from the [CLI quickstart](https://docs.mirage.strukto.ai/home/access/cli.md#quickstart).

> [tab] Claude Code
>
> ```bash theme={null}
> claude mcp add mirage -- mirage mcp -w demo
> ```

> [tab] Cursor
>
> ```json .cursor/mcp.json theme={null}
> {
>   "mcpServers": {
>     "mirage": { "command": "mirage", "args": ["mcp", "-w", "demo"] }
>   }
> }
> ```

> [tab] VS Code
>
> ```json .vscode/mcp.json theme={null}
> {
>   "servers": {
>     "mirage": { "type": "stdio", "command": "mirage", "args": ["mcp", "-w", "demo"] }
>   }
> }
> ```

> [tab] Codex
>
> ```toml ~/.codex/config.toml theme={null}
> [mcp_servers.mirage]
> command = "mirage"
> args = ["mcp", "-w", "demo"]
> ```

For a server elsewhere, give the client the URL and a token:

> [tab] Claude Code
>
> ```bash theme={null}
> claude mcp add --transport http mirage https://mirage.example.com/v1/workspaces/demo/mcp \
>   --header "Authorization: Bearer $MIRAGE_TOKEN"
> ```

> [tab] Cursor
>
> ```json .cursor/mcp.json theme={null}
> {
>   "mcpServers": {
>     "mirage": {
>       "url": "https://mirage.example.com/v1/workspaces/demo/mcp",
>       "headers": { "Authorization": "Bearer ${env:MIRAGE_TOKEN}" }
>     }
>   }
> }
> ```

> [tab] VS Code
>
> ```json .vscode/mcp.json theme={null}
> {
>   "servers": {
>     "mirage": {
>       "type": "http",
>       "url": "https://mirage.example.com/v1/workspaces/demo/mcp",
>       "headers": { "Authorization": "Bearer ${env:MIRAGE_TOKEN}" }
>     }
>   }
> }
> ```

> [tab] Codex
>
> ```toml ~/.codex/config.toml theme={null}
> [mcp_servers.mirage]
> url = "https://mirage.example.com/v1/workspaces/demo/mcp"
> bearer_token_env_var = "MIRAGE_TOKEN"
> ```

## Auth

MCP uses the same bearer token as [HTTP](https://docs.mirage.strukto.ai/home/access/http.md#configure-authentication). `mirage mcp`
sends the CLI's token for you: a saved [login](https://docs.mirage.strukto.ai/home/access/cli.md#log-in),
`MIRAGE_TOKEN`, or the local token file. A client that connects by URL sends the
header itself; the endpoint does not start an OAuth sign-in.

## Tools

Every tool answers text, with `isError` set when it fails.

| Tool | Does | Read-only |
| - | - | - |
| [`shell`](#shell) | Run a shell line. | |
| [`read`](#read) | Read a file as numbered lines. | yes |
| [`write`](#write) | Write a file. | |
| [`edit`](#edit) | Replace a string in a file. | |
| [`ls`](#ls) | List a directory. | yes |
| [`grep`](#grep) | Search file contents. | yes |
| [`glob`](#glob) | Find paths by pattern. | yes |

A session sees only the tools its [session profile](https://docs.mirage.strukto.ai/home/policy/explain.md#which-tools-the-agent-gets)
allows: `shell` needs a command the allow list allows, `ls` and `grep` need
those commands, and `write` and `edit` need a mount the session may write. A
tool it does not see answers `not found`.

### shell

Runs a shell line in the session's working directory. A `cd` or `export` holds
for the next call.

**command** `string` *required*

The line to run.

Answers stdout, then stderr. `isError` is set when the line exits non-zero.

```text theme={null}
x = 2
print(x)

ls: cannot access '/nope': No such file or directory
```

### read

Reads a file as numbered lines.

**path** `string` *required*

Absolute path of the file.

**offset** `integer` (default: 0)

First line to return, zero-based.

**limit** `integer` (default: 2000)

Most lines to return.

```text theme={null}
     1	x = 1
     2	print(x)
```

### write

Writes a file, creating missing parent directories. To replace a file that
exists, `read` all of it first; the write fails if it changed since. Use
[`edit`](#edit) to change part of a file.

**path** `string` *required*

Absolute path of the file.

**content** `string` *required*

The text to write.

```text theme={null}
Written: /data/a.py
```

### edit

Replaces a string in a file. Fails if the file changed since it was read, or if
`old_string` is missing or appears more than once without `replace_all`.

**path** `string` *required*

Absolute path of the file.

**old\_string** `string` *required*

The exact text to replace.

**new\_string** `string` *required*

The text to put in its place.

**replace\_all** `boolean` (default: false)

Replace every occurrence.

```text theme={null}
Edited: /data/a.py (1 occurrence(s))
```

### ls

Lists a directory, one name per line.

**path** `string` *required*

Absolute path of the directory.

```text theme={null}
a.py
sub
```

### grep

Searches files under a path for a regular expression, as `grep -rn` does.
Finding nothing is not an error.

**pattern** `string` *required*

The regular expression.

**path** `string` *required*

Absolute path of the file or directory to search.

**ignore\_case** `boolean` (default: false)

Match case-insensitively (`-i`).

**fixed\_strings** `boolean` (default: false)

Read the pattern as plain text (`-F`).

**include** `string`

Search only files whose name matches this glob, such as `*.py` (`--include`).

**context** `integer`

Lines of context around each match (`-C`).

**files\_with\_matches** `boolean` (default: false)

Print only the names of matching files (`-l`).

**count** `boolean` (default: false)

Print only a count of matching lines per file (`-c`).

**max\_count** `integer`

Stop each file after this many matches (`-m`).

```text theme={null}
/data/a.py:2:print(x)
```

### glob

Finds files whose path matches a pattern, sorted. `**` matches any number of
directories. A pattern that matches more files than a mount's
[`walk_limit`](https://docs.mirage.strukto.ai/home/integration/search#walk_limit) is an error that
names the limit.

**pattern** `string` *required*

The pattern, such as `**/*.py`. A relative one is matched under `path`.

**path** `string` (default: /)

The directory a relative pattern is matched under.

```text theme={null}
/data/a.py
```

## Output progress

A `shell` call can send output previews while it runs. Pass a progress token in
the request's `_meta`:

```json theme={null}
{
  "jsonrpc": "2.0",
  "id": 7,
  "method": "tools/call",
  "params": {
    "name": "shell",
    "arguments": { "command": "echo ready; sleep 1; echo done" },
    "_meta": { "progressToken": "run-7" }
  }
}
```

Mirage then sends `notifications/progress` messages that start with `[stdout]`
or `[stderr]`, over HTTP and `mirage mcp` alike. Previews are trimmed and
batched, so take the full output from the final result.

## VFS calls

Add `?calls=all` to the URL, or `--all-calls` to `mirage mcp`, for 23 more
tools: `vfs_read`, `vfs_is_dir` and the rest, one per
[VFS call](https://docs.mirage.strukto.ai/api/reference.md). They take the same arguments and
return the same JSON as HTTP. A failed call sets `isError` and answers the
[HTTP error object](https://docs.mirage.strukto.ai/api/errors.md#error-body) as its text, such as
`{"code": "not_found", "message": "No such file or directory", "errno": "ENOENT"}`.
With them enabled, `shell` and every `vfs_<call>` also
take `explain: true`, which reports what the call would do without running it; see
[Explain](https://docs.mirage.strukto.ai/home/policy/explain.md).

## Sessions

Calls run in the workspace's default session. To use another, add
`?session_id=<id>` to the URL, or `-s <id>` to `mirage mcp`. The session's
[session profile](https://docs.mirage.strukto.ai/home/configuration/session.md) applies as it does to a shell line: a path
hidden from `cat` is hidden from `read`. Command rules apply only to `shell`,
`ls` and `grep`.


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