Stack file (mdk.yaml)
The minimal `mdk.yaml` the CLI loads, and which page teaches each block under `spec`
Overview
mdk.yaml declares a stack: the Kernel, the Gateway, and the Workers, apps, and access policy that run with them. Every mdk
command that reads a project loads it from the project directory. This page shows the file the commands in
Run your Worker with the CLI generate, and each [n] in it has a note on what the CLI does with those lines
and the page that teaches them. A stack started from code with @tetherto/mdk-core doesn't need the file: the
MVP site example runs a full site under PM2 from its own config, and Start apps from code
shows the calls.
The generated file
In an empty directory, mdk onboard with every default, then
mdk add worker --path ../mdk/backend/workers/miners/avalon and mdk create app site, write this file. mdk rbac init
leaves it as it is. Only package differs between machines: it is the path from the project to the Worker package.
apiVersion: mdk/v1
kind: Stack
metadata:
name: my-stack
spec:
network:
dht: # [1]
host: 127.0.0.1
port: 31737
kernel:
port: 3848 # [2]
gateway: # [3]
port: 3847
config: {}
mcp: {} # [4]
workers:
- name: avalon
package: ../mdk/backend/workers/miners/avalon # [5]
config:
mock: true
devices: # [6]
- id: avalon-0
opts:
address: 127.0.0.1
port: 18080
password: root
type: miner-av-a1346
timeout: 2000
apps: # [7]
- name: site
package: site
config: {}
serviceAccount: app:site
permissionsDigest: 733dfe6a71754171
rbac:
enforcement: deny # [8]
roles:
- name: admin
rules:
- resources:
- "*"
verbs:
- "*"
- name: gateway
rules:
- resources:
- policy
verbs:
- read
- name: app-site
rules:
- resources:
- workers
verbs:
- list
bindings: # [9]
- role: admin
subjects:
- kind: ServiceAccount
name: mdk-cli
- role: gateway
subjects:
- kind: ServiceAccount
name: mdk-gateway
- kind: ServiceAccount
name: mdk-mcp
- role: app-site
subjects:
- kind: ServiceAccount
name: app:sitemetadata.name names the stack; the CLI uses mdk-stack when it is missing.
[1] network.dht: a private DHT on loopback
spec.network.dht puts the stack on a private HyperDHT: the process that runs the Kernel also runs a bootstrap node on
127.0.0.1:31737, and every other component joins it, so nothing reaches the public bootstrap nodes. mdk onboard writes it
(buildStackSpec). Without spec.network, the stack joins the public DHT, which needs
outbound UDP to its bootstrap nodes; where that is blocked, mdk run prints
! worker <name> not registered with the Kernel (ERR_WORKER_IDENTITY_UNAVAILABLE). A port another stack holds stops the boot
with Could not start the private DHT bootstrap on 127.0.0.1:31737 (runtime.ts). The
private DHT guide covers both and the multi-host setup.
[2] kernel.port: read by no command
loadStackSpec parses spec.kernel.port, and no command reads it: the Kernel is reached over HyperDHT, not on a
port. Deleting the block changes nothing.
[3] gateway: its port and settings
spec.gateway.port is the Gateway's HTTP port, and the MCP port is derived from it. mdk run refuses a port in use with
Gateway port 3847 is already in use. (runtime.ts). spec.gateway.config holds Gateway-wide settings, such as
host, allowedHosts, and trustProxy, and its strings resolve ${VAR} placeholders; an app's own settings go in its
spec.apps[].config. The loader refuses spec.gateway.config.authVerifier. Gateway-wide settings
lists each key.
[4] mcp: the MCP server defaults
An empty spec.mcp keeps the defaults for mdk run mcp: the server listens on the Gateway port plus 100
(3947), and each app route becomes a tool, except the operator agent app's. A tool that may write stays hidden unless
allowWrite is set or allowTools names it (_selectTools). Each agent signs in with its own service
account, so spec.rbac decides what it may call, and the loader refuses spec.mcp.token and spec.mcp.identity.
[5] workers: the Worker package and mock
mdk add worker --path stores the package as a path relative to the project and installs nothing
(addWorkerFromPath), so moving one without the other breaks the entry. The name is the package
name without its mdk-worker- prefix. mock: true starts the package's mock/server.js once per device
(resolveMockModule). The entry has no telemetryPollIntervalMs, because the package's contract sets one.
Declaring a Worker covers each key.
[6] devices: the seed device
The device id is the Worker name plus -0, and the loader refuses an id another Worker already uses. opts comes from the
package's own smoke.config.js (seedDeviceOpts): the CLI keeps its keys, and their values only when
the Worker runs on its mock with a numeric port; otherwise it leaves them null. On the mock, port becomes the first mock
port from 18080 that no other device in the file claims. The example's password: root is the mock's. For a real device,
write the password as a ${VAR} placeholder and put its value in .env; an unset one
stops the load with `spec.workers[0].config.devices[0].opts.password` references ${NAME}, which is not set.
mdk add worker documents the seeding flags.
[7] apps: the app entry
mdk create app site adds the entry, links the package into the project's package.json, and grants the app the Kernel
access its mdk-app.yaml requests. The Gateway serves it under /apps/site. serviceAccount is the identity the app calls
the Kernel as, and the loader accepts only app:<name>. permissionsDigest records the request last granted:
planAppGrant keeps the app's role as it stands while the request matches it. The loader refuses a value that isn't
16 lowercase hexadecimal digits with is written by `mdk add app`; remove it rather than editing it.
Declaring and mounting an app covers the entry.
[8] rbac: a default-deny policy and its roles
deny is the only accepted enforcement: a call no rule allows is refused. admin allows every verb on every resource,
gateway reads the policy, and app-site is what the app template's mdk-app.yaml requests, listing
Workers. mdk run refuses a policy nobody could administer, with a message containing
so the Kernel would boot with nobody able to administer it. (policyRefusal).
Writing the access policy covers roles and rules.
[9] bindings: who holds each role
The bindings give the CLI (mdk-cli) the admin role, the Gateway and the MCP server (mdk-gateway, mdk-mcp) the gateway
role, and the app (app:site) its own role. No User subject is bound yet: mdk user add --admin creates the
first operator and binds it to admin, as Create the first operator shows.
Keys the CLI doesn't write
| Key | What it does | Taught by |
|---|---|---|
spec.workers[].config.telemetryPollIntervalMs | Sets the Worker's telemetry sweep, over the contract's. null turns polling off, and with no interval anywhere snapshot and aggregate reads fail with ERR_TELEMETRY_STORE_DISABLED. mdk add worker leaves it out when the package's contract sets an interval, as the example's Avalon contract does, and writes 60000 when the contract sets none. | Telemetry collector |
spec.workers[].config.metadata, spec.workers[].config.devices[].metadata | Declares the label fields a Worker's devices carry and each device's values; the Kernel keeps them by device id, and aggregate reads can group by them | Device metadata |
${VAR} in spec.gateway.config, spec.workers[].env, spec.workers[].config, spec.apps[].config | Resolved from the environment, then the project's .env. An unset one stops the load, and $${VAR} is the literal text ${VAR}. | Variables in mdk.yaml, Write a value in .env |
spec.mcp.allowTools | Exposes only the listed tool ids, including a write tool, without allowWrite | mdk run mcp |
spec.apps[].mount | Serves the app at that path, such as /, instead of /apps/<name> | Declaring and mounting an app |
spec.network.dht.bootstrap | Joins a private bootstrap list already running elsewhere instead of starting one | Running on a private DHT |
spec.rbac.bindings[].subjects[].kind: Group | Binds a role to everyone whose token carries that group | Writing the access policy |
spec.rbac.roles[].rules[].resourceNames | Limits a rule to named instances, where * matches any run of characters, / included | Writing the access policy |
Next steps
- Run your Worker with the CLI: build a stack's
mdk.yamlone command at a time and run it - Look up a CLI command: every command that reads or writes
mdk.yaml, with its flags - Resolve variables in
mdk.yaml: keep secrets out of the file with${VAR}placeholders