> ## 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.

# Server

> Configure the Mirage server with config.toml and MIRAGE_* environment variables.

Server settings apply to everything one Mirage server runs: its port,
sign-in, rate limits, and the ceilings every workspace on it stays under.
They are separate from [workspace](https://docs.mirage.strukto.ai/home/configuration/workspace.md) settings,
which each workspace sets for itself.

Each setting comes from the first of these that sets it:

1. An option, for a [Python](https://docs.mirage.strukto.ai/python/access/server.md) or
   [TypeScript](https://docs.mirage.strukto.ai/typescript/access/server.md) server you start in code, or the
   [Cloudflare app](https://docs.mirage.strukto.ai/typescript/cloudflare-quickstart.md).
2. Its environment variable, such as `MIRAGE_MAX_SESSIONS`.
3. Its key in the `[daemon]` section of `~/.mirage/config.toml`.

A server you start in code takes `idle_grace_seconds` only as an option
(`idleGraceSeconds` in TypeScript); its default is `30`. `port`, `workers` and
`worker_type` are only for `mirage daemon`: in code, you serve the app
yourself.

The Cloudflare app has no `config.toml`. It reads only the sign-in settings
and the six ceilings, `max_workspaces` to `max_env`, from options or the
Worker's variables. Its `max_sessions` defaults to `4`.

## Set a value

`mirage daemon config` edits `~/.mirage/config.toml`:

```bash theme={null}
mirage daemon config set max_sessions 8
mirage daemon restart
```

The file then holds:

```toml ~/.mirage/config.toml theme={null}
[daemon]
max_sessions = 8
```

Changes apply on the next start. `mirage daemon config get|unset|list` read
and remove keys.

## Settings

Each key's environment variable is `MIRAGE_` and the key in capitals:
`max_sessions` is `MIRAGE_MAX_SESSIONS`.

| Key | Default |
| - | - |
| `port` | `8765`; its environment variable is `MIRAGE_DAEMON_PORT` |
| `auth_mode` | `local` |
| `allowed_hosts` | `127.0.0.1,localhost,::1` |
| `idle_grace_seconds` | `30` |
| `max_workspaces` | no cap; past it a new workspace answers 503 |
| `max_sessions` | `16`; past it a new session answers 429 |
| `max_memory` | none; the most any workspace's `max_memory` reaches, as a [size](https://docs.mirage.strukto.ai/home/configuration/workspace.md#sizes) |
| `max_processes` | none; the most any session's `processes.max` reaches |
| `max_line_seconds` | none; the most seconds any line runs |
| `max_env` | none; the most any workspace's `max_env` reaches, as a [size](https://docs.mirage.strukto.ai/home/configuration/workspace.md#sizes) |
| `workers` | `1`; see [Workers](https://docs.mirage.strukto.ai/typescript/access/server.md#workers) |
| `worker_type` | `thread` in TypeScript; in Python, `thread` without the GIL, else `process` |
| `rate_limits` | `ip=1000/minute`; see [Rate limits](https://docs.mirage.strukto.ai/home/access/http.md#rate-limits) |
| `forwarded_allow_ips` | none; the proxies whose `X-Forwarded-For` names the client |
| `graceful_timeout` | `0`; seconds running lines get to finish on shutdown |
| `policy_file` | none; see [Server policies](https://docs.mirage.strukto.ai/home/access/http.md#server-policies) |
| `resource_store` | `files`, under `~/.mirage/resources`; `memory` keeps saved templates and connections only until the daemon stops, and does not combine with `workers` |
| `ssh_*` | see [SSH](https://docs.mirage.strukto.ai/home/access/ssh.md#set-up) |
| `jwt_*` | see [Configure authentication](https://docs.mirage.strukto.ai/home/access/http.md#configure-authentication) |
| `login_client_id` | see [Log in](https://docs.mirage.strukto.ai/home/access/cli.md#log-in) |

Two keys are for the CLI, not the server. They tell `mirage` how to reach
the server on this machine, its `local` context:

* `url`, or `MIRAGE_DAEMON_URL`: `http://127.0.0.1:PORT`.
  `mirage login URL` adds another server.
* `auth_token`, or `MIRAGE_TOKEN`: the token it sends. See
  [Log in](https://docs.mirage.strukto.ai/home/access/cli.md#log-in).

The server's own token is `MIRAGE_AUTH_TOKEN`, else `~/.mirage/auth_token`. It
has no key in `config.toml`. See
[Configure authentication](https://docs.mirage.strukto.ai/home/access/http.md#configure-authentication).

`MIRAGE_HOME` sets the folder Mirage keeps its files in, `~/.mirage` by
default: `config.toml`, `state/`, `snapshots/`, the daemon's log and the rest.
It has no key in `config.toml`, because that file lives inside it.


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