# Use Green Compute from AI assistants (MCP)

Green Compute is an [MCP](https://modelcontextprotocol.io) server, so an assistant such as Claude can find a free GPU, rent it, check on it and stop it for you, without you writing any integration code.

| | |
|---|---|
| Address | `https://api.green-compute.com/mcp` |
| Transport | Streamable HTTP (JSON replies, no event stream) |
| Authentication | Your API key, as `Authorization: Bearer <key>` |

## Connect

**Claude Code:**

```bash
claude mcp add --transport http green-compute https://api.green-compute.com/mcp \
  --header "Authorization: Bearer $GC_KEY"
```

**Other clients** that support remote MCP servers over HTTP with a custom header: give them the address above and the `Authorization` header. Where to put them depends on the client.

## Give the assistant its own key

The assistant can rent machines, which spends your credit. Create a key just for it under [Settings](https://www.green-compute.com/settings) or with `POST /platform/api-keys`:

- scopes `read` and `rentals`: it can see and manage rentals, but can't top up, fetch payment details or make keys;
- a `daily_spend_limit_usd` and `max_active_rentals`, so a mistake can't run up a large bill.

Each tool does what the matching REST call does, with the same checks: a key without the `rentals` scope can look but not rent.

## Tools

| Tool | Does |
|---|---|
| `list_gpus` | GPU models for rent: free now, the most free on one machine, VRAM and price per GPU-hour. |
| `get_balance` | Your balance, what everything running costs per hour, and how many hours that lasts. |
| `list_rentals` | Your rentals and private models; by default those running, starting or paused. |
| `get_rental` | One rental's state and, once it's ready, its SSH command and host keys. |
| `rent_gpu` | Start a rental. Give it your SSH **public** key; optionally a GPU model and count, image, name, start command, restart policy, environment, maximum runtime and an idempotency key. |
| `stop_rental` | Stop a rental for good: billing stops and its disk is deleted. |
| `rental_logs` | The last lines of a running rental's start command log and container output. |
| `run_command` | Run a shell command in a running rental, as root, and get its exit code and output (waits up to 120 s). |
| `rental_stats` | Live CPU, memory, disk and per-GPU use, temperature, power and clocks. |
| `recent_events` | What changed since a cursor: ready, failed, paused, ended, balance low, GPUs free. See [Events and webhooks](https://www.green-compute.com/docs/events.md). |
| `alert_when_free` | Be emailed once when GPUs of a model are free. |

## Good to know

- Errors come back as tool results with the API's `error` object (`code`, `message`, `retryable`; see [Errors](https://www.green-compute.com/docs/errors.md)). `no_capacity` means nothing is free right now: retry later, or use `alert_when_free`.
- A private SSH key is never returned through MCP, because it would end up in the assistant's context. Pass your own public key to `rent_gpu`.
- Up to 120 MCP requests a minute per key.
- Asking the assistant to "rent a 4090, run my script, and stop it when it's done" works best with `command` and `max_runtime_minutes` on `rent_gpu`, so the job runs and stops even if the conversation ends.
