Skip to content
Search docs
Search the docs and jump to the section
Sign in

API, CLI and MCP

How operations are shared by the app, the HTTP API, the CLI and MCP. What a person does with them is in the CLI, MCP and API keys.

Operations

An operation (packages/core/src/operations/) is one thing a person can do: its name, kind, input (valibot), permission, audit and the use case it calls. operate has each by name for the app's remotes; operations lists them for callers that name one.

  • Kinds: read, write and answer. A key is checked against the kind first, then its owner's role against the permission. A session is checked against the role only.
  • Not found: a missing permission answers as if the thing were not there, as the app does.
  • Errors: OperationError (not_found, refused, conflict, invalid), or a use case's TypeError, which is the caller's mistake.
  • In the app: remotes call run or run_form (apps/app/src/lib/server/api/operations.ts) and keep form parsing, redirects and refreshes. Remotes for what is not an operation, such as connections, members and factory teams, check and record for themselves.

HTTP API

Routes are in apps/app/src/routes/api/v1/; with_api_key (apps/app/src/lib/server/api/api.ts) answers each.

RequestAnswers
GET /api/v1Who the key acts as
GET /api/v1/operationsEvery operation, input as JSON Schema
POST /api/v1/<operation>What the operation gives
GET /api/v1/runs/<id>/files/<file>A run's file, as a download
GET /api/v1/projects/<id>/downloadA project, as a zip
  • A key comes as Authorization: Bearer. A session is never accepted, and a key never opens a page: hooks.server.ts reads no session for these paths, or for /mcp.
  • Every response has werker-api-version. The CLI refuses another version, since an install and a CLI are updated apart.
  • werker-client is how a client names itself, for the audit log. It is not proof.
  • There is no rate limit.

CLI

apps/cli (citty) depends only on @werkerai/domain, which vp pack bundles. It prints nothing an agent wrote without removing control characters, writes downloads to the current folder by base name, and follows no redirect.

pnpm release:cli builds and publishes it, by hand. Versions come from changesets; every other package is private.

MCP

apps/app/src/routes/mcp/+server.ts answers MCP over HTTP with tmcp (apps/app/src/lib/server/mcp/), for an API key like the API.

  • Tools: docs gives the operations as TypeScript, read runs a script that may call read operations, and write one that may call every kind. write is left out of the list for a key that cannot use it, and refuses one that calls it anyway. Each operation still checks the key and the role.
  • Each call a script makes is done when it is made, so what it did before failing stays done.
  • Sessions: apps/app/src/lib/server/mcp/sessions.ts keeps nothing in a session; every request carries its key.
  • Browsers: a request from another origin is refused.
  • OAuth is not built, so a client that only signs in with OAuth cannot connect.

Scripts

packages/scripts runs each script in a process of its own, so a model writes code that never runs in the web app or the worker.

  • QuickJS (pi-codemode) is where the script runs: no network, files, modules or timers, and 64 MB of memory.
  • The process around it is started with no environment and Node's --permission: it reads the repository's node_modules, packages/scripts and packages/domain, and cannot write a file or start a process or thread.
  • The process's network is not limited by --permission.
  • Calls go to the web app as messages, which are checked as untrusted. The app does them with the key's own rights.
  • Limits (packages/scripts/src/limits.ts): 30 seconds, 50 calls, 50,000 characters of code, two scripts at once per person and four in all. The app kills the process at its deadline, or when the client goes.
This page as markdown apps/site/src/content/docs/engineering/api-and-cli.md