# MCP server

The MCP server gives an AI assistant typed tools for Unikraft Cloud.
An assistant such as Claude Code, Claude Desktop, or Cursor then manages instances, volumes, services, and sandboxes without running CLI commands and parsing their output.
The server speaks the [Model Context Protocol](https://modelcontextprotocol.io) (MCP).

You can use the server in two ways:

- The **hosted server** at `https://mcp.unikraft.com/mcp`.
  You sign in through the console and install nothing.
- The **local server**, `unikraft mcp`.
  It runs on your machine and uses your CLI profile.

Both serve the same tools, with the [differences](#differences-between-the-two-servers) listed below.

## Use the hosted server

Add the server to your assistant by its address, `https://mcp.unikraft.com/mcp`.
The page at [mcp.unikraft.com](https://mcp.unikraft.com) has the same steps, with buttons that add the server to Cursor and VS Code.

### Claude

This works on claude.ai, and in the Claude desktop and mobile apps:

- Open **Settings**, then **Connectors**, and select **Add custom connector**.
- Name it `Unikraft Cloud`, and enter the address `https://mcp.unikraft.com/mcp`.
- Select **Add**, then **Connect**, and sign in to Unikraft Cloud.

On a Team or Enterprise plan, an owner first adds the connector under **Organization settings**, then **Connectors**.

### Claude Code

```bash
claude mcp add --transport http --scope user unikraft-cloud https://mcp.unikraft.com/mcp
```

Then, in Claude Code, run `/mcp`, choose `unikraft-cloud`, and choose **Authenticate** to sign in.
Without `--scope user`, only the current project gets the server.

### Cursor

Add the server under `mcpServers` in `~/.cursor/mcp.json`:

```json
"unikraft-cloud": { "url": "https://mcp.unikraft.com/mcp" }
```

Then sign in from **Customize** in the sidebar, or run `agent mcp login unikraft-cloud`.

### VS Code

{/* vale off */}
The tools work in the agent mode of GitHub Copilot Chat.
{/* vale on */}

```bash
code --add-mcp '{"name":"unikraft-cloud","type":"http","url":"https://mcp.unikraft.com/mcp"}'
```

VS Code asks you to sign in when it starts the server.

### Codex

```bash
codex mcp add unikraft-cloud --url https://mcp.unikraft.com/mcp
codex mcp login unikraft-cloud
```

### Gemini CLI

```bash
gemini mcp add --transport http --scope user unikraft-cloud https://mcp.unikraft.com/mcp
```

Then, in Gemini CLI, run `/mcp auth unikraft-cloud` to sign in.

### Other clients

Any MCP client with the Streamable HTTP transport and OAuth can connect.
Give it the address `https://mcp.unikraft.com/mcp`.
The client registers itself with the server.

### Sign in

The first time the assistant connects, it opens your browser:

- You sign in to the console and pick an organization.
- A page asks if the assistant may manage the resources of that organization.
  Select **Allow**.
- The browser returns to the assistant, which can now call the tools.

The first connection can take up to 20 seconds, while the metros learn the new sign-in.

Each sign-in acts on one organization, across its metros.
To work on another organization, sign in again and pick it.
The server accepts only its own sign-in, so an API token from the console doesn't work as a credential.

The sign-in lasts 30 days, and the assistant renews its access by itself during that time.
It ends earlier when you sign out of the console or leave the organization.
The assistant then asks you to sign in again.

### Check that it works

Ask your assistant:

```text
List the Unikraft Cloud metros I can deploy to, and the instances in my organization. Only read: don't create, change or delete anything.
```

The assistant only lists them, so nothing in your organization changes.

## Use the local server

`unikraft mcp` serves the protocol over standard input and output.
Register it with your assistant as a command.
In Claude Code:

```bash
claude mcp add unikraft -- unikraft mcp
```

In a client that takes a JSON configuration:

```json
{"mcpServers": {"unikraft": {"command": "unikraft", "args": ["mcp"]}}}
```

The tools use the current profile and query every metro of it, like the matching CLI commands.
The server reads the configuration file again on every tool call.
`unikraft login` and `unikraft profile use` take effect without a restart.
To keep the server on one profile, start it with `--profile <name>`.

### Limit the tools

Two flags reduce what the assistant can do:

| Flag | Effect |
|------|--------|
| `--read-only` | Serve only the tools that can't change anything: the list tools, `image_get`, `instance_logs`, and `sandbox_read`. |
| `--resources` | Serve only the tools of the resource types that you list, for example `--resources instance,volume,metro`. |

The resource types are the prefixes of the tool names: `certificate`, `image`, `instance`, `instance_checkpoint`, `instance_template`, `metro`, `profile`, `sandbox`, `service`, `volume`, and `volume_template`.
A type matches only its own tools, so `instance` doesn't include the `instance_template` or `sandbox` tools.
You can combine both flags.

:::tip
A shorter tool list costs the assistant less context on every turn.
:::

### Serve over HTTP

With `--listen`, the local server speaks HTTP at `/mcp`, with a liveness check at `/healthz`:

```bash
unikraft mcp --listen 127.0.0.1:8080
```

Clients then register the server by its address:

```json
{"mcpServers": {"unikraft": {"type": "http", "url": "http://127.0.0.1:8080/mcp"}}}
```

Add `--tls-cert` and `--tls-key` to serve HTTPS.

:::caution
The local server doesn't authenticate its clients.
Every client acts with the credentials of your profile.
The server accepts only loopback addresses unless you pass `--allow-remote`.
TLS encrypts the traffic but doesn't authenticate anyone, so use `--allow-remote` only behind a proxy that authenticates the clients, or on a private network.
:::

## Tools

Each resource type has the tools `<type>_list`, `<type>_create`, `<type>_edit`, and `<type>_delete`.
The types are instances, instance templates, instance checkpoints, volumes, volume templates, services, and certificates.
Metros have only `metro_list`.

| Tool | Description |
|------|-------------|
| `<type>_list` | List every resource of the type, or fetch specific ones with `keys`, and narrow the result with `filter`, `sort`, and `fields`. |
| `<type>_create` | Create a resource from the field values in `set`. |
| `<type>_edit` | Change a resource with `set`, `add`, and `del`. |
| `<type>_delete` | Delete resources by key, which is permanent. |
| `instance_control` | Start, stop, restart, or suspend instances. |
| `instance_logs` | Read the last lines of the console output of an instance, 200 by default. |
| `image_list` | List the images in your account. |
| `image_get` | Inspect any image reference, public ones included (local server only). |
| `image_delete` | Delete images (local server only). |
| `sandbox_exec` | Run a command in a sandbox, with a limit of 5 minutes by default that you can raise to 30 minutes. |
| `sandbox_read` | Read a text file of at most 1 MiB from a sandbox. |
| `sandbox_write` | Write or append to a text file in a sandbox. |
| `profile_use` | List the profiles, or switch to another one (local server only). |

A key is a name or a UUID.
Prefix it with a metro, as in `fra/my-app`, to target one metro.

The `set`, `add`, and `del` parameters take [field paths](/cli/fields), like the `--set`, `--add`, and `--del` flags of the CLI.
The create and edit tools take `dry_run`, which returns the resulting change without applying it.

A sandbox is an instance with the [sandbox plugin](/features/plugins#sandbox-plugin) loaded.
The sandbox tools work on any running instance that has it.

`profile_use` changes the default profile in the configuration file, so it also applies to the CLI.
The local server doesn't offer it when `--profile` or `UNIKRAFT_PROFILE` selects the profile.

The server returns at most 1 MiB of output for each tool call.

## Documentation as resources

Both servers also serve this documentation as MCP resources.
`unikraft://docs` is the table of contents, and `unikraft://docs/<path>` is a page, for example `unikraft://docs/cli/fields`.
The server fetches a page only when the assistant reads it, so the documentation costs no context until then.

For the local server, the `UNIKRAFT_DOCS_URL` environment variable selects another documentation site.
An empty value turns the resources off.

## Differences between the two servers

| | Hosted server | Local server |
|---|---------------|--------------|
| Credentials | Console sign-in, one organization for each sign-in | The CLI profile |
| `image_get`, `image_delete`, `profile_use` | Not available | Available |
| `--read-only` and `--resources` | Not available | Available |
| Files on your machine | Not available: images must be registry references, and a ROM must be an image | Available |

## Troubleshooting

| Message | What to do |
|---------|------------|
| `Your account has no organization.` | Create an organization in the console, then connect again from the assistant. |
| `The sign-in expired.` | The sign-in page stays valid for 10 minutes, so connect again from the assistant. |
| `the organization has all its access tokens: delete one at the console, then sign in again` | Each sign-in uses one access token of the organization, so delete an unused token in the console, then sign in again. |
| `instance ... has plugin ... attached but not loaded yet; restart it with instance_control` | A plugin loads at boot, so restart the instance. |
| `--listen ... binds a non-loopback address and the server has no authentication` | Pass `--allow-remote` only if a proxy authenticates the clients, see [serve over HTTP](#serve-over-http). |
| `--resources: unknown resource types: ...` | Use the resource types from [limit the tools](#limit-the-tools). |

For all flags, see the [`unikraft mcp`](/cli/unikraft/mcp) reference.
