API & SDK reference

TypeScript SDK, Go binaries, Molar API REST, admin API, MCP tools, and environment variables.

API & SDK reference

Molar Clones exposes three API layers: vendor-shaped APIs (what your app calls), admin APIs (clock, snapshots, chaos), and the Molar API (spawn, world snapshot, fleet). The TypeScript SDK wraps all three.


npm packages

PackagePurpose
@molar/clonesUmbrella — stripe, twilio, email, auth, s3, world
@molar/clones-coreCloneBase, refusal, binary install
@molar/clones-stripeStripe-only import
@molar/clones-twilioTwilio-only import
@molar/clones-emailEmail-only import
@molar/clones-authAuth-only import
@molar/clones-s3S3-only import
@molar/clones-playwrightPlaywright fixtures
@molar/clones-mcpMCP server tools
@molar/clinpm wrapper for molar native binary

TypeScript SDK — CloneBase

Every *.start() returns a CloneBase instance plus kind-specific helpers.

start(options?)

type StartOptions = {
  seed?: string;           // default "molar-sdk-seed" — drives deterministic IDs
  runId?: string;          // default random
  url?: string;            // BYOC — skips spawn
  adminUrl?: string;
  adminToken?: string;
  key?: string;
  testKey?: string;
  clockFreezeAt?: string;  // ISO timestamp
};

Instance properties

PropertyDescription
kindstripe | twilio | email | auth | s3
runIdTenant partition ID
urlVendor API base (TLS in library mode)
adminUrlAdmin API base
key / testKeyDerived vendor credential

Instance methods

MethodAdmin endpoint
advanceClock(duration)POST /_clone/clock/advance
injectError(rule)POST /_clone/inject/error
injectLatency(rule)POST /_clone/inject/latency
injectRateLimit(rule)POST /_clone/inject/ratelimit
snapshot()POST /_clone/snapshot/{runId}/saveUint8Array
restore(blob)POST /_clone/snapshot/{runId}/restore
expectWebhookFired(type, ms?)Poll webhook events
stop()SIGTERM child process
request(path, init)Vendor API via /t/{runId}{path}
adminGet(path) / adminPost(path, body)Admin API

Kind-specific helpers

Stripe: testKey, publishableKey, seedData(), createPaymentMethod(), createPaymentIntent(), listCustomers(), expectWebhookFired()

Twilio: createMessage(), createVerification(), checkVerification(), lastOTP()

Email: send(), inbox(), markBounce(), markSpamTrap()

Auth: seedUsers(), createUser(), signIn(), jwks()

S3: endpoint, accessKeyId, secretAccessKey, createBucket(), putObject(), getObject(), list(), putBucketLifecycle()

World API

import { world } from "@molar/clones";

const registry = world.localRegistry([stripeClone, emailClone]);
await world.snapshot(registry, runId, "checkpoint");
await world.restore(registry, runId, "checkpoint");

Environment variables

VariableDescription
MOLAR_CLONE_{KIND}_URLService-mode API URL (STRIPE, TWILIO, EMAIL, AUTH, S3)
MOLAR_CLONE_{KIND}_ADMIN_URLAdmin URL
MOLAR_CLONE_{KIND}_ADMIN_TOKENAdmin bearer token
MOLAR_CLONE_{KIND}_TLS_CA_FILEPEM for private TLS CA
MOLAR_CLONE_{KIND}_BINOverride Go binary path
MOLAR_CLONE_ADMIN_TOKENGlobal admin token
MOLAR_CLONE_BIN_DIRBinary search directory
MOLAR_CLONE_BINARY_CACHE_DIRCached release binaries
MOLAR_CLONES_CTRL_URLMolar API base URL
MOLAR_CLONES_API_TOKENMolar API API key
MOLAR_DESTRUCTIVE_ALLOW1 to disable live-vendor refusal (dangerous)

Kind env suffixes: STRIPE, TWILIO, EMAIL, AUTH, S3.


Go binaries

BinaryRole
clones-stripeStripe API + admin
clones-twilioTwilio API + admin
clones-emailEmail API + admin
clones-authClerk-shaped API + admin
clones-s3S3 API + admin
clones-controlSpawn, world snapshot, sessions
clones-fixtureAll fixture vendors
route-proxyHost-based routing + refusal
molarCLI (molar clones spawn, list, …)

Common env vars for binaries:

MOLAR_CLONE_ADDR=127.0.0.1:8000
MOLAR_CLONE_TLS_ADDR=127.0.0.1:8443
MOLAR_CLONE_ADMIN_ADDR=127.0.0.1:9000
MOLAR_CLONE_SEED=demo
MOLAR_CLONE_CLOCK_FREEZE_AT=2026-01-01T00:00:00Z
MOLAR_CLONE_ADMIN_TOKEN=

Molar API REST API

OpenAPI spec: molar-clones/docs/openapi/control-plane.json

Sessions & spawn

MethodPathDescription
POST/api/clones/{kind}/spawnSpawn clone → { runId, url, adminUrl, expiresAt }
DELETE/api/clones/{runId}Teardown session
POST/api/clones/startStart persistent session
GET/api/sessionsList active sessions

World operations

MethodPathDescription
POST/api/clones/world/snapshot{ runId, name }
POST/api/clones/world/restore{ runId, name }
GET/api/clones/world/restore/{restoreId}Async restore status
POST/api/clones/world/clock/advanceAdvance all registered clones

Observability & chaos

MethodPathDescription
GET/api/clones/{runId}/healthSession health
GET/api/clones/{runId}/logs?since=SSE request log tail
POST/api/clones/{runId}/injectFault injection
GET/api/traces/{runId}Ordered call + mutation trace

Fleet

MethodPathDescription
POST/api/clones/registerRegister BYOC backend
PUT/api/route/configRoute proxy host → session mapping
POST/api/seeds/applyApply named seed to session

Per-clone admin API (:9000)

MethodPathDescription
POST/_clone/seedSeed initial state
POST/_clone/reset/{runId}Reset tenant
POST/_clone/snapshot/{runId}/saveSave snapshot (gzip body)
POST/_clone/snapshot/{runId}/restoreRestore snapshot
POST/_clone/clock/advance{ duration: "30d" }
POST/_clone/clock/setSet absolute time
POST/_clone/clock/pausePause
POST/_clone/clock/resumeResume
POST/_clone/inject/errorChaos error rule
POST/_clone/inject/latencyChaos latency rule
GET/_clone/log/{runId}NDJSON request log
GET/_clone/healthHealth
GET/_clone/readyReadiness

Vendor-specific admin paths: /_clone/stripe/events/, /_clone/twilio/otp/, /_clone/email/inbox/, etc.


MCP tools

Canonical connector tools (org-scoped via API key):

ToolDescription
molar_clone_spawnSpawn session → id + endpoint
molar_clone_listList org sessions
molar_clone_seedApply named seed
molar_clone_snapshotSave snapshot (base64)
molar_clone_restoreRestore from base64
molar_clone_worldWorld snapshot or restore
molar_clone_routeRoute proxy config
molar_clone_traceSession call trace
molar_clone_stopTeardown session
molar_clone_advance_clockAdvance clock
molar_clone_inject_errorError injection
molar_clone_startLegacy spawn alias

Vendor helpers: stripe_advance_clock, stripe_expect_webhook, twilio_last_otp, email_inbox, email_mark_bounce, auth_seed_users, s3_create_bucket, s3_put, s3_list, world_snapshot, world_restore.

Full manifest: docs.molar.it/.well-known/molar-capabilities.json


Molar runtime (@molar/runtime)

import { molar } from "@molar/runtime";

await molar.clones.start([{ kind: "stripe", seed: "x" }]);
molar.clones.stripe;           // running instance
await molar.clones.fault.inject(pattern, opts);
await molar.clones.clock.advance(ms);
await molar.clones.stopAll();

Type generation

Stripe/Twilio types auto-regenerated from vendor OpenAPI:

cd molar-clones && npm run regen:types

Dashboard Settings → API drift shows regen status.


Errors

ErrorCause
MolarDestructiveCallErrorLive vendor URL + live key pattern
MolarUnknownTargetErrorMissing X-Molar-Clone response header
MOLAR_E020E023Molar runtime clone errors

See Troubleshooting and Error codes.