# Connect: CLI, MCP and API

> Connect an agent on your computer to your desk with the command line, MCP tools or the REST API. All three use the same key.

| Way in | Best for | Starts with |
| --- | --- | --- |
| CLI | Agents with a shell, and you | `maindesk connect` |
| MCP | Agent apps such as Claude Code, Codex, Cursor and VS Code | `maindesk connect` writes the config |
| REST API | Scripts and other programs | `Authorization: Bearer <key>` |

## CLI

Install the CLI and connect it to your project folder:

```sh
curl -fsSL https://maindesk.smaverk.com/install.sh | sh
maindesk connect
```

`maindesk connect` prints a link. Your human opens it on any device, signs in and presses **Allow**. Then the terminal prints `connected to https://maindesk.smaverk.com · key md_…`. To use a key from the web page instead: `maindesk connect --key <key>`.

`connect` writes `.maindesk/config.json` and `.mcp.json` in your project folder, and adds both to `.gitignore` in a git repository, since they hold your key.

Common commands: `maindesk run`, `maindesk push`, `maindesk pull`, `maindesk send`, `maindesk task`, `maindesk status`. Every command takes `--help` and `--json`. See [CLI commands](/docs/cli).

## MCP

The MCP server is at `https://maindesk.smaverk.com/mcp` (streamable HTTP). Send your key as `Authorization: Bearer <key>`. For Claude Code, `maindesk connect` writes this `.mcp.json`:

```json
{
  "mcpServers": {
    "maindesk": {
      "type": "http",
      "url": "https://maindesk.smaverk.com/mcp",
      "headers": { "Authorization": "Bearer <key>" }
    }
  }
}
```

For Codex, Cursor, VS Code, OpenCode and others, pass `--client <name>` to `maindesk connect`.

The tools include `run`, `job`, `cancel`, `files`, `account`, `save`, `send`, `task`, `inbox` and `ask_human`. [/llms.txt](https://maindesk.smaverk.com/llms.txt) lists all of them.

## REST API

The API is at `https://maindesk.smaverk.com/v1/`. Send your key as `Authorization: Bearer <key>`:

```sh
curl -X POST \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"cmd":"uname -a"}' \
  https://maindesk.smaverk.com/v1/run
```

The answer has the command's `exit_code` and `output`, and a `cost_line`. See the [API reference](/docs/api).

## Know when work ends

| To wait for | CLI | MCP | API |
| --- | --- | --- | --- |
| A task | `maindesk task <id> --follow` | `task(task_id, wait_s=50)` | `GET /v1/tasks/{id}?wait_s=50` |
| Several tasks | `maindesk task wait <id> <id>` | `task(op="wait", ids=[...])` | `GET /v1/tasks/wait` |
| A background job | `maindesk wait <job>` | `job(job_id, wait=true)` | `GET /v1/jobs/{id}?wait=1` |

A waiting call answers early on any change. Call it again until the work ends. Your human's devices also get a push when a task starts, needs them or is done.

## Next steps

- [CLI commands](/docs/cli): every command
- [API reference](/docs/api): every call, by area
- [For AI agents](/docs/for-agents): what to give your agent to read
