CapVM docs

MCP

CapVM's MCP server lets AI agents and coding tools (Cursor, Codex, Claude Code and other streamable HTTP clients) rent and use machines with the same ak_ key as the REST API. The CapVM team issues API keys after signup and Terms acceptance; they aren't self-serve (self-serve dashboard keys are Coming soon).

Available: the server at https://api.capvm.com/mcp with the tools below, including exec, the Terms acceptance gate on create_machine (Signup and Terms acceptance) .

Coming soon: Connect with OAuth, so an interactive client such as Codex can sign in through your browser instead of holding an ak_ key, and MCP Apps views for machines and balance in hosts that support them, and card top-ups with create_checkout_session. For now, CapVM adds credits to your account.

CapVM serves the Model Context Protocol over streamable HTTP (stateless sessions). The tools are a thin layer over the same billing service as the REST API, so holds, spend caps, concurrency limits and new-account limits work exactly the same way.

URL https://api.capvm.com/mcp. It's on the API host, not under /v1.
Auth Authorization: Bearer ak_test_… or ak_live_…, the same agent keys as /v1. Coming soon: or an OAuth access token, see Connect with OAuth.
Scope Every tool only sees the calling key's machines and usage. get_balance is for the whole organization.
Rate limit Each HTTP request counts toward the same per-key limit as /v1 (120 per 60 s)

A missing, unknown or revoked key is rejected with HTTP 401 and the same error body as /v1 (unauthorized, invalid_api_key, key_revoked) before any tool runs.

Connect a client

Cursor (.cursor/mcp.json)

{
  "mcpServers": {
    "capvm": {
      "url": "https://api.capvm.com/mcp",
      "headers": {
        "Authorization": "Bearer ak_test_..."
      }
    }
  }
}

Any streamable HTTP client

Point the client at https://api.capvm.com/mcp and send the header Authorization: Bearer ak_test_... on every request. Use the same JSON as above for any client that reads an mcpServers block with url and headers.

Connect with OAuth (Coming soon)

Coming soon. Details may change before release. It uses the dashboard sign-in, also Coming soon.

An interactive client can connect without an ak_ key: it opens your browser, you sign in to CapVM and approve it with a spend cap, and the client gets short-lived tokens. ak_ keys keep working on /mcp exactly as above, so use a key for headless agents (cloud agents, CI) that have no human to approve them.

Codex

Codex 0.77.0 or later:

codex mcp add capvm --url https://api.capvm.com/mcp
codex mcp login capvm

The second command opens your browser. Codex registers itself (as Codex) and listens for the answer on http://127.0.0.1:<port>/callback/…. Don't add an Authorization header to this server's config: the client gets its own tokens.

What happens in the browser

  1. Sign in. If you aren't signed in, CapVM sends you to /signin. You get one email with a single-use link and an 8-character code (see Dashboard sign-in). Signing in from this flow also counts as the fresh sign-in the approval needs, so it takes one email, not two.
  2. Confirm it's you. If you're signed in but your last sign-in or confirmation is more than 5 minutes old, CapVM sends you to /signin/reauth and emails you a code first.
  3. Approve. The approval page shows: - the redirect host as its heading: where the client receives the approval. For Codex that's 127.0.0.1 (your own computer). If you didn't just start a login, or the host is one you don't recognise, click Deny. - the name the client gave itself, followed by Unverified app. Clients register themselves, so CapVM doesn't check the name. A client that gives no name is shown just as "Unverified app" (once). - "can create machines and spend up to $25 of your credit", and a Spend cap (USD) field: a whole number of dollars from 1 to 1000, default 25. The sentence shows the starting value; the cap that counts is the one in the field when you click Approve. - Approve and Deny. Deny sends the client error=access_denied.

After you approve, CapVM emails you (the person who approved) a security alert (subject CapVM security alert, event oauth_grant) with the time in Europe/Zurich and UTC, the IP, the user agent and the client name. Like the sign-in alert, it has a "This wasn't me" link: single-use, valid for 7 days, and it runs the lockdown (signs out every session, revokes API keys created in the last 24 hours, freezes the organization). The email ends "Questions: hello@capvm.com." The refresh_reuse_detected alert has the same link.

The approval is refused when:

Case What you see
Your organization is frozen The client gets error=access_denied with error_description=org_frozen (and your state)
Your organization hasn't accepted the Terms yet (pending_acceptance) The client gets error=access_denied with error_description=org_pending (and your state)
The client asked for a scope other than mcp and offline_access, or didn't ask for mcp The client gets error=invalid_scope (scope must include mcp.)
The spend cap isn't a whole number from 1 to 1000 400 validation_error spend_cap_usd must be a whole number of dollars from 1 to 1000.
The approve form has no valid antiforgery token 400 validation_error Antiforgery token is missing or invalid.

What a connected client can do

Tokens

Access token 15 minutes. Token responses always include "expires_in": 900. Opaque: CapVM looks it up on every call, so a revoked grant stops working on its next request.
Refresh token Issued when the client asks for offline_access. A new one with every refresh. It expires after 7 days without use, and the connection ends 30 days after you approved it at the latest (invalid_grant The grant has expired.): run codex mcp login capvm again.
Retried refresh Sending the same refresh token again within 60 seconds returns exactly the same response as the first time, so two parallel refreshes don't lock you out. Sending it again later is treated as theft: CapVM revokes the whole grant, emails the person who approved it a security alert (refresh_reuse_detected), and returns invalid_grant The refresh token was reused.
Authorization code 60 seconds, single use, with no clock-skew allowance. PKCE with S256 is required; plain is rejected.

resource is required. The client must send resource=https://api.capvm.com/mcp (RFC 8707) on the authorize request and on every token request, code exchange and refresh alike. Missing or any other value: 400 {"error":"invalid_target","error_description":"resource must be https://api.capvm.com/mcp."}. Codex sends it.

How a client finds the sign-in (401 discovery)

A request to /mcp without a bearer gets 401 with:

WWW-Authenticate: Bearer resource_metadata="https://api.capvm.com/.well-known/oauth-protected-resource/mcp"

An expired or revoked OAuth token gets the same header plus , error="invalid_token", and the body {"error":{"code":"unauthorized","message":"Access token is expired or revoked."}}. From there the client reads the discovery documents and registers itself.

Disconnecting a client

The dashboard has a Connected apps section on /dashboard and /dashboard/keys: one row per approved OAuth client with the app name (marked "Unverified app"), redirect host, spend cap, spent, created and last used (in micro-USD and yyyy-MM-dd HH:mm:ss), an Update cap field ($1 to $1000; raising needs a fresh sign-in) and a Revoke button. The same routes are available as JSON: GET /v1/org/oauth/grants lists your organization's connected clients (name, "verified": false, redirect host, cap, spent, created, last used), and DELETE /v1/org/oauth/grants/{id} revokes one with all its tokens. Its next /mcp call gets 401 (above), and its refresh fails with invalid_grant. Revoking sends no email.

A client can also disconnect itself: revoking its access or refresh token at POST /oauth/revoke revokes the whole grant and all its tokens, the same as the DELETE route.

Signing out everywhere also revokes every OAuth grant you approved, and the "This wasn't me" lockdown revokes the OAuth grants of everyone in your organization.

Frozen organizations

While your organization is frozen, new approvals are refused (the client gets error=access_denied, error_description=org_frozen). On /mcp, an OAuth token is treated like an ak_ key: initialize, ping and tools/list go through, and each tool call is accepted or rejected on its own. create_machine, get_machine, list_machines, exec and create_checkout_session fail with the tool error org_frozen: This organization is frozen.; get_balance, get_usage and stop_machine keep working. A blocked tool call returns HTTP 200 with a tool result that has isError: true and the code org_frozen, not an HTTP error; REST calls still get 403 org_frozen. (create_checkout_session isn't available to OAuth clients anyway.) Revoking a grant and lowering its cap still work; raising it returns 403 org_frozen.

Keep the key safe

Your MCP client sends this key with every call, so anyone who has it can spend up to the key's cap.

The connection is always HTTPS, so a VPN isn't needed.

idempotency_key is required on create_machine. It follows the same rule as the REST Idempotency-Key header: 1 to 255 characters (UTF-16 code units) after trimming, no control characters, scoped to your API key. If you retry with the same key and the same sku/ttl_seconds, you get the same machine back, with a single hold. That makes it safe to retry after a timeout. Use a stable value per task, for example job-42. Today the rules for a blank key differ between create_machine and create_checkout_session (see each tool).

Tools

Money is always integer micro-USD (1 USD = 1,000,000). Successful results are JSON in a text content block.

create_machine

Rents a machine. The full TTL is held before launch, and a rejected hold launches nothing.

Param Type Required Notes
sku string yes arm-small ($0.20/h) or gpu-l4 ($2.00/h). Must be on the key's allow-list.
ttl_seconds integer yes 60 to 7200
idempotency_key string yes 1 to 255 visible characters (trimmed). Scoped to the API key and shared with the REST Idempotency-Key. Same key + same sku/ttl_seconds → the existing machine, no second hold. A different sku or ttl_seconds → idempotency_conflict.

Errors for the key (exact text):

Case Tool error text
idempotency_key missing (or null) idempotency_key_required: idempotency_key is required.
Empty string "" idempotency_key_required: idempotency_key is required.
Only whitespace, longer than 255 after trimming, or contains a control character idempotency_key_invalid: idempotency_key must be 1 to 255 visible characters.

create_checkout_session treats a whitespace-only key as idempotency_key_required instead (see below).

Coming soon: one shared key check for machine create and checkout over REST and MCP (keys trimmed and stored trimmed, emoji allowed, only control characters rejected), with slightly different error messages.

A rejected key takes no hold and launches nothing.

Arguments:

{"sku":"arm-small","ttl_seconds":900,"idempotency_key":"job-42"}

Result (a Machine, the same shape as REST):

{
  "id": "m_9b1c0e6f2d8a4c3b9e7f1a2b3c4d5e6f",
  "sku": "arm-small",
  "state": "provisioning",
  "instance_id": "i-0abc…",
  "public_ip": null,
  "region": "eu-central-2",
  "ttl_seconds": 900,
  "price_per_hour_micro": 200000,
  "hold_micro": 50000,
  "charge_micro": null,
  "created_at": "2026-10-25T11:00:00Z",
  "expires_at": "2026-10-25T11:15:00Z",
  "ready_at": null,
  "stop_requested_at": null,
  "terminated_at": null
}

get_machine

Param Type Required
machine_id string (m_…) yes

Returns a Machine. Machines created by another key aren't visible (not_found), even within the same organization.

list_machines

No params. Returns {"machines":[Machine, …]}: up to 100 machines for this key, newest first.

stop_machine

Param Type Required
machine_id string (m_…) yes

Charges the billed seconds (at least 60, at most ttl_seconds) and releases the rest of the hold. Returns the Machine with state: "terminated" and charge_micro set. Stopping a machine that's already settled returns it again. This is the same as DELETE /v1/machines/{id}.

exec

Param Type Required Notes
machine_id string (m_…) yes Must be ready and owned by this key
command string yes 1 to 8192 characters, no NUL
timeout_seconds integer no 1 to 300, default 30. Outside that range → timeout_out_of_range: timeout_seconds must be between 1 and 300.
working_directory string no Absolute path on the machine; leave it out for the default. Same rules as REST, otherwise working_directory_invalid

Arguments:

{"machine_id":"m_9b1c0e6f2d8a4c3b9e7f1a2b3c4d5e6f","command":"uname -a","timeout_seconds":30}

Result:

{"stdout":"…","stderr":"","exit_code":0,"truncated":false}

The tool works like POST /v1/machines/{id}/exec, with a 256 KiB cap per stream (truncated) and the REST exec errors as <code>: <message> text, for example command_timeout: Command timed out. or provider_error: The machine did not report an exit code. See API reference → exec.

get_usage

No params. Same payload as GET /v1/usage, for the calling key only: other keys in the organization aren't included. events lists up to 100 recent charges, newest first.

{
  "spend_micro": 3334,
  "held_micro": 0,
  "spend_cap_micro": 5000000,
  "events": [
    {
      "id": "3f0c2a9e-6b1d-4e8a-9c7f-2d5b8e1a4c6f",
      "machine_id": "m_9b1c0e6f2d8a4c3b9e7f1a2b3c4d5e6f",
      "sku": "arm-small",
      "seconds": 60,
      "amount_micro": 3334,
      "created_at": "2026-10-25T11:01:00Z"
    }
  ]
}

spend_micro is what the key has been charged, held_micro is its open holds, and spend_cap_micro is its cap. Event id is a UUID.

get_balance

No params. The organization's balance, including holds from other keys:

{"available_micro":9796666,"held_micro":203334,"currency":"USD","unit":"micro_usd"}

create_checkout_session

Coming soon. For now, CapVM adds credits to your account. The amount_usd format may change, possibly to integer cents. Its errors don't use the tool-error format yet (see below).

Starts a prepaid credit top-up by card: it creates a Stripe Checkout Session and returns its link. A human must open the link and pay. The agent can't. Same rules as POST /v1/checkout/sessions, including the Terms gate. Prices exclude VAT. Marked idempotent.

Param Type Required Notes
amount_usd number or string yes USD, the same rules as the REST body: a JSON number is whole dollars (50; 50.5 is rejected with validation_error), a string may have at most two decimals ("50", "50.00"). $10 to $1000. Both forms are tested (REST).
idempotency_key string yes 1 to 255 visible characters after trimming (no control characters). A whitespace-only key is idempotency_key_required here (create_machine says idempotency_key_invalid). The same key from the same API key, with the same amount, returns the same session. Keys are per API key, as for create_machine.
success_url string no Absolute http(s) URL Stripe returns the payer to. Default https://capvm.com/checkout/success (page not built yet).
cancel_url string no Absolute http(s) URL if the payer cancels. Default https://capvm.com/checkout/cancel (page not built yet).

Result:

{"id":"cs_test_…","url":"https://checkout.stripe.com/…"}

Pass url to a human. Credits arrive in get_balance once Stripe confirms the payment. You're credited the amount before VAT, in USD.

Errors use the same codes and messages as REST (validation_error, idempotency_key_required, idempotency_key_invalid, min_topup_not_met, max_topup_exceeded, terms_not_accepted, idempotency_conflict, stripe_not_configured, stripe_error). A missing, empty or blank idempotency_key gives idempotency_key_required: idempotency_key is required. One over 255 characters or with a control character gives idempotency_key_invalid: idempotency_key must be 1 to 255 visible characters. (create_machine uses its own codes, above). An open payment dispute doesn't block this tool; it blocks create_machine (account_suspended).

How errors come back today: unlike the other tools, this one doesn't wrap CapVM's errors into the <code>: <message> text and structuredContent.error described in Errors: it lets them propagate to the MCP SDK, so the extra fields of terms_not_accepted (required_versions, accept_url) aren't passed on. idempotency_key is a required parameter in the tool schema.

Coming soon: this tool will return its errors in the same format as the other tools, so terms_not_accepted carries required_versions and accept_url.

Errors

A rejected tool call comes back as an MCP tool error (isError: true) whose text is <code>: <message>, using the same codes as the REST API, for example:

insufficient_credits: …

The same result also carries structuredContent with the same error object as the REST API: code and message nested under error, plus any extra fields the error has, inside error too:

{"error": {"code": "insufficient_credits", "message": "…"}}

An error without extra fields has only code and message inside error. Extra fields can't override code or message: an extra field with either name is dropped, so error.code and error.message are always the error's own. The text line and error.message carry the same message.

This applies to every tool except create_checkout_session (see above); that's Coming soon.

Codes you may see: idempotency_key_required, idempotency_key_invalid, sku_required, unknown_sku, ttl_out_of_range, insufficient_credits, spend_cap_exceeded, sku_not_allowed, account_limit_reached, concurrency_limit_exceeded, idempotency_conflict, capacity_unavailable, launches_disabled, provider_error, not_found, command_required, command_too_long, timeout_out_of_range, machine_not_ready, machine_not_running, terms_not_accepted, account_suspended. See API reference → Errors.

MCP Apps views (Coming soon)

Coming soon. Details may change before release.

CapVM will support the MCP Apps extension io.modelcontextprotocol/ui (spec 2026-01-26). A host that supports it can show a small interactive page next to some tool results.

Tools View What it shows
list_machines, get_machine ui://capvm/machines.html One card per machine: state, SKU, id, TTL remaining (ticks every second), Estimated cost (see below), hold, price per hour, region, instance type, and public IP if it has one. A Refresh button asks the host to call the same tool again.
get_balance, get_usage ui://capvm/balance.html get_balance: available and held credits. get_usage: spend, held, spend cap, and a table of recent charges (when, machine, SKU, seconds, amount). Both show a top-up form and a Refresh button. Refresh re-runs the tool that opened the view, with the arguments the host passed it: get_usage keeps the usage table, get_balance the balance.

create_machine, stop_machine, exec and create_checkout_session have no view. exec has no view yet.

Estimated cost is only an estimate. The view works it out itself, with the clock of the device showing it: seconds from created_at to now (or to expires_at if that's earlier), at least 60, at most the TTL, then ceil(price_per_hour_micro × seconds / 3600), at most the hold. Once the machine has a charge_micro, the view shows that amount as Charged instead. The view says so: "The charged amount is final and comes from the server." CapVM has no server-side running-cost field yet.

Where the data comes from. The view reads the JSON text of the tool result that the host passes it. It holds no API key and makes no network requests of its own. Refresh and top-up are tool calls the view asks the host to make. The pages are text/html;profile=mcp-app, with inline CSS and script and no external origins. Their _meta.ui sets an empty CSP connectDomains and resourceDomains, and prefersBorder: true. Machine and charge fields are shown as text, not HTML.

Top-up from the balance view:

  1. Enter whole dollars from 10 to 1000. The view checks this before calling anything.
  2. Click Open checkout. The button is disabled until the request finishes, so a double click sends one request. The view asks the host to call create_checkout_session with that amount_usd and a random idempotency_key (ui- plus 32 hex characters).
  3. If the result has a link starting https://, the view asks the host to open it (ui/open-link). Any other link is refused, and the view shows the result text instead (or "Checkout did not return an https link." if there is none). A human pays on Stripe's page; Stripe isn't embedded in the view.
  4. The view keeps the same key for a retry of the same amount when the first try got no definite answer from CapVM: the host reported an error (for example a transport error or timeout), or the result had no usable https:// link (not JSON, empty, or another scheme). The retry then returns the same Checkout Session if CapVM did create one.
  5. The view makes a new key after CapVM returns a session with an https:// link (even if the host then fails to open it), after a CapVM tool error (isError, or an error object in the result), and when the amount changes. So two successful clicks create two Checkout Sessions. Credits arrive only for a session that's paid.
  6. The view doesn't update itself after payment. Click Refresh (or call get_balance) once Stripe has confirmed it.

If the tool call fails, the view shows the error text as it gets it, for example a terms_not_accepted message. It doesn't offer the accept_url: a human still has to accept the Terms (see Signup → 403 terms_not_accepted). For how this tool's errors come back today, see above.

Clients without MCP Apps get the same tool results as before: same text, and still no structuredContent on success. tools/list still lists _meta.ui.resourceUri on the four tools above for every client, and the server advertises the extension and the two resources to every client. A client that doesn't understand them can ignore them.

Not in MCP