# MCP server

Connect an MCP client to your VM so it reads, writes and runs commands with only the access you grant.

Source: https://slashinfra.com/docs/build/mcp
Last modified: 2026-11-30T16:36:19.000Z

Your VM has an MCP server. An MCP client can read files, write files and run commands in it, within the access a grant allows.

## Before you start

- An approved [account](https://app.slashinfra.com/) and an API key from the [API keys](https://app.slashinfra.com/keys) page. 
- A VM. Make one with [Files and programs over HTTP](https://slashinfra.com/docs/build/files-and-programs). 
- An MCP client that reads `.mcp.json` from the project directory, such as Claude Code.

## 1. Create a folder and a grant

A grant names the HTTP methods and paths that a client may use. This grant allows reads and writes under one folder for one day. It does not allow commands, because running a command is a `POST`.

### curl

```bash
export SI_API_KEY=si_...
export VM=6f1c0f0e8a
curl -sS -X POST "https://$VM.slashinfra.dev/usr/bin/env?arg=mkdir&arg=-p&arg=/home/user/project" \
-H "Authorization: Bearer $SI_API_KEY"
curl -sS -X POST "https://api.slashinfra.com/svms/$VM/grants" \
-H "Authorization: Bearer $SI_API_KEY" -H "Content-Type: application/json" \
-d '{"methods":["GET","PUT"],"paths":["/home/user/project/**"],"ttl_s":86400}'
```

### Python

```python
import os, requests

vm = os.environ["VM"]
headers = {"Authorization": f"Bearer {os.environ['SI_API_KEY']}"}
requests.post(
f"https://{vm}.slashinfra.dev/usr/bin/env",
params=[("arg", "mkdir"), ("arg", "-p"), ("arg", "/home/user/project")],
headers=headers,
).raise_for_status()
res = requests.post(
f"https://api.slashinfra.com/svms/{vm}/grants",
headers=headers,
json={"methods": ["GET", "PUT"], "paths": ["/home/user/project/**"], "ttl_s": 86400},
)
res.raise_for_status()
print(res.json()["url"])
```

### TypeScript

```ts
const vm = process.env.VM!
const headers = { Authorization: `Bearer ${process.env.SI_API_KEY!}` }
const mkdirUrl = new URL(`https://${vm}.slashinfra.dev/usr/bin/env`)
for (const arg of ['mkdir', '-p', '/home/user/project']) mkdirUrl.searchParams.append('arg', arg)
const mkdir = await fetch(mkdirUrl, { method: 'POST', headers })
if (!mkdir.ok) throw new Error(`mkdir failed: ${mkdir.status}`)
const res = await fetch(`https://api.slashinfra.com/svms/${vm}/grants`, {
method: 'POST',
headers: { ...headers, 'Content-Type': 'application/json' },
body: JSON.stringify({ methods: ['GET', 'PUT'], paths: ['/home/user/project/**'], ttl_s: 86400 }),
})
if (!res.ok) throw new Error(`grant failed: ${res.status}`)
const grant = (await res.json()) as { url: string }
console.log(grant.url)
```

Output

```text
{"url":"https://6f1c0f0e8a.slashinfra.dev/?si_access=eyJ...","expires_at":...,"generation":...}
```

The `si_access` value in `url` is the grant. Keep it private. It stops working when you rotate the grants of the VM.

## 2. Add the server to your client

Save this file as `.mcp.json` in the project directory. Replace `<id>` with your VM id and `<grant>` with the `si_access` value.

.mcp.json

```json
{
"mcpServers": {
"vm": {
"type": "http",
"url": "https://<id>.slashinfra.dev/.well-known/si/mcp",
"headers": { "X-Si-Authorization": "Bearer <grant>" }
}
}
}
```

Start the client from that directory. It lists five tools from the server.

| Tool | Arguments | What it does |
| --- | --- | --- |   
| `exec` | `path`, `args?`, `stdin?`, `cwd?`, `timeout_s?` | Runs the executable at `path` and returns its exit code, stdout and stderr. Use `/bin/bash` with `["-c", "…"]` for a shell command. | 
| `read` | `path` | Reads a file or lists a directory. | 
| `write` | `path`, `content` | Replaces a file atomically. | 
| `job_start` | `script`, `cwd?` | Starts a [background job](https://slashinfra.com/docs/build/background-work) and returns its number. | 
| `job_wait` | `number`, `timeout_s?` | Waits for a job and returns its log and exit code. |

## 3. Call a tool

Ask the client to write a file, then read it back. For example, ask it to write `/home/user/project/notes.txt` with `write`, then to read the same path with `read`.

The grant admits `GET` and `PUT` under `/home/user/project`, so `read` and `write` succeed. The grant refuses `exec` and `job_start`, because they send a `POST`. A refused call does not wake the VM.

The MCP server counts as VM API traffic. The transfer limits and the per-VM request limit apply, and a tool call keeps the VM awake. `job_wait` waits in steps of at most 25 seconds, so set `timeout_s` to cap the whole wait. A grant for the desktop (port `6080`) or for `/bin/bash` gives full control of the VM. Read [security](https://slashinfra.com/docs/how/isolation) before you grant either.

There is no MCP server for the control API, so a chat app cannot create or delete a VM through MCP. An agent with a shell uses the `si` CLI instead. Its skill file is at [slashinfra.com/skills/si/SKILL.md](https://slashinfra.com/skills/si/SKILL.md).

## Check it works

You should see the text you wrote in the result of `read`.

## If it doesn’t work

| Symptom | Cause | Fix |
| --- | --- | --- |   
| The client lists no tools | The client did not start in the folder with `.mcp.json`. | Start the client from that folder, then check the file’s `url` and header. | 
| The call fails with an authorization error | The grant is wrong, expired or was rotated. | Create a new grant in step 1 and replace the header value. | 
| A tool call is refused | The method or the path is outside the grant. | Create a grant that includes that method and path. |

## Clean up

Rotating the grants ends every grant that the VM issued, so the client stops working. The folder stays until you delete the VM.

### curl

```bash
curl -sS -X POST "https://api.slashinfra.com/svms/$VM/grants/rotate" \
-H "Authorization: Bearer $SI_API_KEY"
```

### Python

```python
import os, requests

res = requests.post(
f"https://api.slashinfra.com/svms/{os.environ['VM']}/grants/rotate",
headers={"Authorization": f"Bearer {os.environ['SI_API_KEY']}"},
)
res.raise_for_status()
print(res.json()["generation"])
```

### TypeScript

```ts
const res = await fetch(`https://api.slashinfra.com/svms/${process.env.VM!}/grants/rotate`, {
method: 'POST',
headers: { Authorization: `Bearer ${process.env.SI_API_KEY!}` },
})
if (!res.ok) throw new Error(`rotate failed: ${res.status}`)
const rotated = (await res.json()) as { generation: number }
console.log(rotated.generation)
```

Output

```text
{"generation":1}
```

## Next

- [Files and programs over HTTP](https://slashinfra.com/docs/build/files-and-programs): the requests behind these five tools. 
- [Grants](https://slashinfra.com/docs/platform/grants): mint a grant with other methods, paths or a shorter life. 
- [Security](https://slashinfra.com/docs/how/isolation): what a full-control grant allows.
