Docs
API reference

For agents

How a coding agent reads these docs, installs the private packages and writes code on the SDK, and, separately, how an agent works on a scene running in Klorad One.

These docs are written to be read by people and by coding agents. Most of this page is for an agent that writes code on the SDK; the last section is for an agent that works on a scene running in Klorad One. If you are a coding agent:

  • Fetch /llms.txt for an index of every page, or /llms-full.txt for all of them as one Markdown file.
  • Every runnable code sample on this site is a file that compiles against the current packages. Copy from the samples rather than inventing calls.
  • The packages are private. Installing them needs an npm account that has been given access (Install); if npm view @klorad/api version says the package is not found, tell the developer you work for to request package access.

Rules the SDK holds you to

  • Change world state only through a Scene. A renderer or a component that needs to change the world calls back to app code, which calls the scene.
  • @klorad/api/world imports nothing but itself: no React, no three.js, no DOM, no Node APIs. Code that needs those belongs in a binding, a renderer or Integration.
  • Give every shadow and twin a binding, and give a binding only to a shadow or a twin.
  • Order comes from observedAt. Never use arrival time as the state of the world.
  • A Behaviour cannot request an Action. Model follow up work as a new request that the Entitlement checks again.
  • Validate outside data with a schema at the source boundary; keep vendor credentials on the server.

Reading a scene as an agent

An agent that works on a running twin reads it through the projection for agents, not through pixels: describeScene gives each object with its class, correspondence, position in metres, readings and their age, relations and, given an interaction and an actor, the Actions that actor may take; agentText turns that into compact text with a schematic plan; nearest and distanceBetween answer metric questions. The projection is read only.

agent-view.ts
import { agentText, createScene, describeScene, nearest } from "@klorad/api/world";

const scene = createScene({ name: "Station", coordinateSystem: { origin: { lat: 40.6264, lon: 22.9484 } } });
scene.add({ id: "house", name: "Pump house", position: { east: 0, north: 0 }, class: "building", geometry: { kind: "extrusion", footprint: [[-9, -5], [9, -5], [9, 5], [-9, 5]], height: 6 } });
scene.add({ id: "p1", name: "Pump 1", position: { east: -4, north: 0 }, class: "pump", correspondence: "twin", binding: { source: "scada", entity: "P1" }, relations: [{ kind: "inside", to: "house" }] });
scene.observe({ objectId: "p1", quantity: "pressure", value: 3.8, unit: "bar", observedAt: Date.now(), source: "scada" });

// What a model reads: one line per object, then a schematic plan, north up.
export const context = agentText(describeScene(scene));
// p1 "Pump 1" (pump, twin) at E -4 N 0 U 0 m | pressure 3.8 bar (0 s ago) | inside house

// Metric questions answered in metres, so the model never does geodesy.
export const closest = nearest(scene, "p1", { limit: 1 }); // [{ id: "house", distance: 4 }]

Writing code: the Claude Code skill

The skill klorad-sdk teaches Claude Code to write SDK code in your repository: the model, the rules above, and where the reference is. It reaches no running scene. It is not public: licensed developers get it from Klorad, as they get the packages. Put its folder in .claude/skills/klorad-sdk/ in your project, or in ~/.claude/skills/ for every project.

Where the truth is

The type declarations in node_modules/@klorad/<name>/dist/*.d.ts are the reference: they are complete, readable and match the installed version, while the JavaScript next to them is minified. When this site and the declarations disagree, the declarations win; report the page through the contact form so it is fixed.

Runtime MCP in Klorad One

This section is about the platform, not the SDK: it applies when your scene runs in Klorad One, and nothing in it is part of the packages. Klorad One has an MCP server at https://<your Klorad One>/api/mcp (Streamable HTTP). An owner or admin of a project makes an agent token for one scene on the scene's live page; it lasts at most a day, can be revoked, and works only on the server it was made for. With it an agent can:

  • describe_scene: the scene through the projection for agents, only what the person who made the token may see now;
  • list_operations: the operations that could be proposed for an object;
  • propose_change: a draft that a person approves or rejects on the live page; it is made against the revision the agent read, so a change someone makes meanwhile wins;
  • draft_status: what became of a draft.

An agent changes nothing directly: no tool writes a scene, grants rights or makes tokens.

claude mcp add --transport http klorad https://<your Klorad One>/api/mcp --header "Authorization: Bearer <token>"

Something wrong or unclear? Tell us.