# SDK

The machine tools as a library for your own program: the same tools an agent calls through MCP, under
the same grant and ceiling, each call recorded under the agent whose token the program holds.

**In short:** `npm install @cmdop/sdk` or `pip install cmdop`; set `CMDOP_TOKEN` (an agent token) and `CMDOP_URL`
(your page's address); `connect().machine("box").run("uptime")`.

| Language | Package | Page |
|---|---|---|
| TypeScript, Node 20+ | npm [`@cmdop/sdk`](https://www.npmjs.com/package/@cmdop/sdk) | [TypeScript](https://docs.cmdop.ai/reference/sdk/typescript.md) |
| Python 3.10+ | PyPI [`cmdop`](https://pypi.org/project/cmdop/) | [Python](https://docs.cmdop.ai/reference/sdk/python.md) |

The current version is the one npm and PyPI show; what changed in each: [changelog](https://docs.cmdop.ai/help/changelog.md).

Source: [github.com/commandoperator/cmdop-sdk](https://github.com/commandoperator/cmdop-sdk). License: MIT.

## What both have

- **A typed method per tool** on a machine, with the arguments and result of its
  [tool page](https://docs.cmdop.ai/reference/tools.md), also under its group (`box.fs.read`). A tool added to CMDOP comes with
  the next SDK version.
- **`run` and `stream`** for commands: `run` waits for the result; `stream` gives the output as it
  comes, then the same result. Leaving the loop early stops the command.
- **`call(tool, args)`** reaches any tool by name.
- **The contour's own tools** as methods of the client, with no machine: `machines_list`, `tasks_list`,
  `history_search` and `showtime_guide`, the guide an agent follows for a short live demo on your machines.
  They are the same tools an agent sees over MCP.
- **A deadline per call.** The call keeps the shorter of yours and the tool's own time; past it the
  answer is `timed_out`.
- **One error type** with the [error code](https://docs.cmdop.ai/reference/errors.md) as `code`. Decide by the code, never by
  the message. A connection that breaks is a separate error, not a result.

## Before you start

A machine online on your page and an agent token for your program from the Agents tab, in the
environment as `CMDOP_TOKEN`; your page's address (`https://<address>.cmdop.dev`) as `CMDOP_URL`.
The token is held to the agent's grant. Never put it in code you commit, in a URL or in a log.

The SDK uses the [HTTP API](https://docs.cmdop.ai/reference/http.md): `/api/v1/machines`, `/api/v1/call` and
`/api/v1/call/stream`. Calls from a paired client, encrypted end to end, are not in the published
packages yet: [sealed calls](https://docs.cmdop.ai/concepts/sealed-calls.md).

## The same tools over MCP

CMDOP is also an MCP server. An agent reaches the same tools at `https://<address>.cmdop.dev/mcp`
(streamable HTTP) with an agent token as `Authorization: Bearer`: the kind of token the SDK takes,
held to the same grant, each call recorded the same way. Give each program and each agent its own
token, so the record says which one acted. The command or settings for each client:
[Connect an agent](https://docs.cmdop.ai/guides/connect.md).

## Versions

One version for both languages. Within a major version, tools, arguments, result fields and error
codes are only added; a program written against 3.x keeps working. A machine with an older `cmdop`
program answers a tool it does not have yet with `unknown_tool`.
