Content protocol
How the site editor reads and writes saved blocks without running your code. Seven JSON-RPC methods over one endpoint, served by deco serve and by the site editor's GitHub backend.
The site editor never runs your site's code. It reads and writes content through a small protocol, the content protocol, so any storage that implements it can back the site editor. This page is for contributors and for anyone writing another backend.
What it reads and writes
- The schema,
<root>/.deco/schema.gen.json. It's read-only: no method writes it. - The saved blocks, one JSON file per block in
<root>/.deco/blocks. This is the only thing it writes.
There are no secrets to read or write: content holds none, and credentials live in your deploy platform's secrets.
The root is the app root, the folder that contains .deco/, such as apps/storefront in a monorepo. describe reports it.
Where edits go
Two implementations serve the protocol:
| Backend | Edits | The site editor checks for changes |
|---|---|---|
deco serve, from the Deco CLI | The files in your working tree. Your app hot-reloads after each save, and you commit when you're ready. | About every 2 seconds |
| The site editor's GitHub backend, part of the hosted Deco CMS | A draft in Deco's storage, laid over your repository's production branch on GitHub; publishing commits it there. | About every 30 seconds |
The portable protocol has no event stream. The site editor polls with one batched request, and when nothing changed the answer is a short "not modified". Saving is last-writer-wins unless the save says which version of a block it expects (ifMatch): then a save over a block someone else saved meanwhile writes nothing, and the site editor shows both versions so the editor can choose.
In brief
The content protocol is JSON-RPC 2.0 (a small standard for calling named methods with JSON) over one HTTP endpoint, and a request can batch several calls. Its current version is deco-content 1.2, and it has seven methods:
| Method | Does |
|---|---|
describe | What this endpoint is: a git source or a working tree, its app root, whether it writes an overlay, and how often to poll |
schema.get | Reads the schema |
blocks.list | Reads every saved block at once, with a revision for the whole set |
blocks.apply | Sets and deletes saved blocks together, all or nothing, optionally only if a block is still at a given version |
changes.list | Lists the saved blocks that differ from the base, without their content |
changes.get | Reads both sides of some saved blocks: as they are in the base, and as they are now |
changes.discard | Puts some saved blocks back as they are in the base, all or nothing |
A source's content is its base plus its changes. For deco serve, the base is the last commit of your local repository (HEAD), so the changes are what you haven't committed yet. For the site editor's GitHub backend, the base is your production branch, and the changes are the draft: an overlay, which holds only the blocks it changed. The three changes methods let the site editor show what changed, show each change's before and after, and drop a change (see Changes since the base).
blocks.list, schema.get and changes.list take the version they already have and answer "not modified" when it's current, which is what makes polling cheap.
The wire format
One HTTP endpoint takes JSON-RPC 2.0 requests: POST <endpoint> with Content-Type: application/json and a body that's one request object or a batch array. The local server's path is /rpc; the site editor mounts its own per project.
paramsis always an object. A method without parameters accepts{}or noparams.- Every request has an
id. A request without one is rejected rather than run silently, because a dropped write is worse than an error. - Unknown parameters are rejected, so a guard the server doesn't understand never turns into an unguarded write.
- Errors come back in the JSON-RPC
errorobject with HTTP 200, except a missing or invalid bearer token on an endpoint that requires one, such as the site editor's GitHub backend (401), and a body over the size limit (413), which apply to the whole batch. - A batch runs in order and returns results in order, up to 10 calls. It isn't atomic: atomicity exists only inside one
blocks.apply. - Responses are gzip-compressed when the request accepts it; schemas are often over a megabyte.
The methods
function describe(): {
protocol: "deco-content";
version: { major: 1; minor: number }; // 1.2 since @decocms/blocks 8.8.0; minors only add
server: { name: string; version: string }; // e.g. "deco-cli", "studio-github"
kind: "working-tree" | "git"; // The site editor hides publish and draft UI for a working tree
readOnly: boolean;
root: string; // the app root: the folder that contains .deco/, relative to the repository root
schemaFormat: "deco-meta@1";
pollIntervalMs: number; // local: 2000; git: 30000, plus on window focus
preview: null | { url: string }; // the app the Preview tab loads; deco serve: --preview
assets: null | { dir: string; urlPrefix: "/assets/"; maxBytes: number }; // dir relative to the repository root; null when read-only or uploads go to hosted storage
secrets: null; // always null since 1.2: content holds no secrets (a 1.0 or 1.1 server reported .deco/secrets.pub here)
overlay?: true; // since 1.2: writes go to an overlay over the base, such as a hosted draft; see Overlays
};
function schemaGet(params?: { ifNoneMatch?: string }):
| { notModified: true; version: string }
| { notModified: false; version: string; resolvedRef: string | null; schema: DecoMeta }
| { notModified: false; version: null; resolvedRef: string | null; schema: null }; // no schema yet
function blocksList(params?: { ifNoneMatch?: string }):
| { notModified: true; revision: string; resolvedRef: string | null }
| { notModified: false; revision: string; resolvedRef: string | null;
blocks: Record<string, object>; // every saved block, by name
versions: Record<string, string>; // one opaque version per entry
diagnostics: Diagnostic[] }; // files skipped or shadowed
function blocksApply(params: {
set?: Record<string, object>; // whole-entry replace (create or update)
delete?: string[]; // a missing name counts as deleted
ifMatch?: Record<string, string | null>; // a version the entry must have; null = must not exist (on an overlay: in the overlay)
}): { revision: string; versions: Record<string, string | null> }; // null for a deleted name (on an overlay: its deletion's version)
type Base = { revision: string; resolvedRef: string | null }; // deco serve: the HEAD commit and its branch (null when detached)
function changesList(params?: { ifNoneMatch?: string }):
| { notModified: true; revision: string; base: Base }
| { notModified: false; revision: string; base: Base;
changes: Record<string, { // only the entries that differ from the base, by name
kind: "set" | "delete"; // set: new or edited; delete: in the base, gone now (on an overlay: or a tombstone the overlay holds)
version: string | null; // as blocks.list reports it, usable in ifMatch; null for a delete (on an overlay: the deletion's version)
baseVersion: string | null }> }; // null when the base doesn't have the entry
function changesGet(params: { names: string[] }): { // at most 20 names
base: Base;
entries: Record<string, { // a name in neither the base nor the content is left out, unless an overlay holds a tombstone for it
kind: "set" | "delete" | null; // null: unchanged, and before equals after
before: object | null; // the entry in the base; null when the base doesn't have it or it can't be read
after: object | null; // the entry now; null when it's deleted or can't be read
version: string | null; baseVersion: string | null }>;
diagnostics: (Diagnostic & { side: "before" | "after" })[]; // why a side that exists is null
};
function changesDiscard(params: {
names: string[]; // at most 500; a name without a change is left as it is
ifMatch?: Record<string, string | null>; // as in blocks.apply
}): { revision: string; versions: Record<string, string | null> }; // as blocks.apply; null: not in the baseVersions and revisions are opaque strings defined by each storage (a git blob hash on disk, a content hash in a hosted draft), compared only for equality and never across servers. Everything else is fixed inside the root: blocks.list and blocks.apply read and write <root>/.deco/blocks, and schema.get reads <root>/.deco/schema.gen.json, falling back to <root>/.deco/meta.gen.json, and parses it before serving, so a file caught mid-write is never served torn.
No schema yet
A site whose schema isn't generated yet (deco schema hasn't run) is a normal state, not an error. schema.get returns schema: null with version: null, and blocks.list and blocks.apply work as usual: a write never reads the schema anyway. There's no version to poll with, so the client polls schema.get without ifNoneMatch until a schema appears; the answer is a few bytes. The site editor lists every saved block meanwhile, grouped by __resolveType, and opens each one as plain fields inferred from its JSON, with a banner that says how to generate the forms. A site with no .deco folder at all is still NotFound.
describe doesn't report whether a schema exists: answering would mean reading the whole schema on every describe, and schema.get already says so in a few bytes.
blocks.apply is the only write:
- All or nothing. Every name in
setanddeletelands together (one commit on git) or none does. - Durable when it returns. It resolves only after the commit or the file renames landed, which is what the site editor's autosave indicator relies on.
setwins when a name is in bothsetanddelete.- Validated first. Names, value shapes (each entry is a JSON object) and sizes are checked before anything is written, and every violation is reported at once. The schema isn't: a write never reads it, and checking content against it is
deco check's job, in your CI. - Preconditions are optional. A failed
ifMatchwrites nothing and returns a conflict with each entry's expected and actual version. WithoutifMatch, the last writer wins, as with the site editor's autosave.
Renaming, duplicating and moving entries are recipes over one blocks.apply (a set plus a delete, with ifMatch: { [newName]: null } for create-only), not methods of their own. Creating hosted drafts, publishing, rollback, discarding a draft and the draft pointer stay site editor routes outside the protocol. The hosted editor binds its endpoint to the editor's draft; an editor never supplies or understands a Git branch. See Keeping drafts current.
Overlays
A hosted draft isn't a copy of your content: it holds only the blocks the editor saved, and the names they deleted, laid over the production branch. Since 1.2, an endpoint like that says so with describe.overlay: true, and its rules change so that a save never has to read the base:
ifMatchcompares with the overlay alone.nullmeans "the overlay doesn't hold this block yet", whatever the base has; a version means "the overlay holds exactly this version", theversionthatchanges.listreports for it. A deletion counts as held too: the overlay records it with a version of its own (a tombstone), sonullfails on a block the overlay deletes, and the deletion's version passes. So a client that saves a block it loaded from the base sendsnull, and one that saves a block already in the draft, deleted or not, sends that block'sversionfromchanges.list, from the answer of its own last save, or from a Conflict'sactual.changes.listis the overlay's own entries, each one listed even when its content equals the base's, until it's discarded. Discarding drops the entry from the overlay, so the base shows through again. A deletion is adeletewhoseversionis the deletion's version, notnull;blocks.applyanswers the same version for the name it deleted.- An overlay may hold a tombstone for a name the base lacks. A hosted draft's save never reads the base, so it records every deletion it's sent, whether or not the base has the name. A client treats that tombstone the same as any tombstone:
changes.listlists it as adeletewith its version andbaseVersion: null,changes.getanswers both sidesnull,ifMatch: nullon it fails and its version passes, and discarding it drops it. An overlay may also drop such a deletion instead; thenblocks.applyanswersnullfor the name and nothing is listed. Publishing a tombstone the base doesn't have changes nothing.
Everything else is unchanged: blocks.list, changes.get and schema.get read the base with the overlay on top, a set still replaces the whole entry, and a write without ifMatch is last-writer-wins. Two writes of different entries that land together are both kept.
Changes since the base
The changes methods compare the content with the base entry by entry, never file by file: like blocks.list, they treat every spelling of a name as one entry (see File names).
changes.listreads no content, only versions, so it's cheap to poll besideblocks.list. It takes the sameifNoneMatchand answers "not modified" with the samerevision; its revision is its own and moves when either the content or the base moves, so it isn't comparable withblocks.list's. An entry is changed because it's listed:versionandbaseVersionare opaque, so don't compare them. A file that differs from the base but can't be read now, such as one with invalid JSON, is still listed, because discarding it is how a broken hand edit gets fixed.changes.getreturns the two sides, never a computed diff: the client renders the diff. An unchanged entry answerskind: nullwith equal sides. A side over the 1 MiB entry limit, or one that isn't valid JSON, comes backnullwith a diagnostic that says which side and why.changes.discardis a write. It restores the base's version of each named entry and deletes the entries the base doesn't have, all in one commit, or nothing.ifMatchworks exactly as inblocks.apply: a version that doesn't match writes nothing and answers Conflict. Send theversionyou showed fromchanges.list(for a deletion an overlay holds, its tombstone version), so a discard never drops an edit someone made after you looked. If the base moves while a discard runs, it's computed again against the new base, never written from the old one. A read-only endpoint answers ReadOnly;changes.listandchanges.getstill work there.
Publishing isn't a method: it moves the base (on your machine, you commit), and the next changes.list comes back empty.
Versions and older servers
describe reports the protocol version. Minors only add: 1.1, from @decocms/blocks 8.2.0, added the three changes methods, and 1.2, from 8.8.0, added overlays and stopped reading the schema on a write (describe.secrets is always null). There are no feature flags, the version decides:
- A client from 8.2.0 or newer needs 1.1. Connecting to an older server, such as
deco servefrom 8.1.x, fails with Unsupported (-32006);error.data.reasonis"outdated", and the message says to update@decocms/blocksin the site to 8.2.0 or newer and startdeco serveagain. Achangesmethod that an older server doesn't know (MethodNotFound, -32601) turns into the same error, in a single call and in a batch. The site editor shows it as "This deco serve is out of date". - A 1.1 server still works with a client from 8.8.0 or newer: the client needs 1.1, not 1.2. Such a server is never an overlay, and it may report a
secretskey from an older site; a client ignores it. - An older client keeps working with a newer server, because a minor only adds.
Whole entries
blocks.apply replaces whole entries; there is no property patch. A dropped HTTP response doesn't tell the client whether its save landed, so the client reads again (blocks.list, or changes.list on an overlay) and compares versions before it retries. A guarded save that already landed then conflicts with its own result, which the client recognizes by the content. Publishing a hosted draft uses the same granularity: an edited block wins in full over the production branch's (see Publish: the whole draft block wins). The protocol doesn't execute site code or claim that a write is compatible with deployed code: that's deco check's job.
Polling instead of events
There's no event stream in the portable protocol. Hosted Studio may invalidate reads through its existing events, but a client must also work by polling. A client polls with one batched request that carries the versions it has; when nothing changed, both answers are a few bytes:
→ [{"jsonrpc":"2.0","id":4,"method":"schema.get","params":{"ifNoneMatch":"9f2c…"}},
{"jsonrpc":"2.0","id":5,"method":"blocks.list","params":{"ifNoneMatch":"4be1…"}}]
← [{"jsonrpc":"2.0","id":4,"result":{"notModified":true,"version":"9f2c…"}},
{"jsonrpc":"2.0","id":5,"result":{"notModified":true,"revision":"4be1…","resolvedRef":null}}]After its own write, a client adopts the returned revision, so its next poll is "not modified" unless someone else wrote. When the map did change, the client replaces its copy except for entries it's still saving.
Errors and limits
| Code | Name | When |
|---|---|---|
| -32001 | NotFound | No .deco folder at all (the site editor's "not a Deco site"). No schema isn't an error: see No schema yet |
| -32002 | Conflict | An ifMatch precondition failed; data.entries has each entry's expected and actual version |
| -32003 | InvalidBlock | A name or value breaks the rules below: a bad name, a value that isn't a JSON object, or one over the size limit |
| -32005 | ReadOnly | A write to a read-only endpoint |
| -32006 | Unsupported | A feature the endpoint doesn't offer. The client also raises it, with data.reason: "outdated", for a server older than protocol 1.1 (see Versions and older servers) |
| -32007 | LimitExceeded | Too many operations, names, batch entries or bytes; data.limit names the limit, such as maxNamesPerGet or maxOpsPerDiscard |
| -32008 | Unavailable | The storage failed or is rate-limited, or retries ran out; carries retryAfterMs when known. Also the answer of the changes methods when the storage can't read its base right now |
| -32010 | Unauthorized | Missing or invalid bearer token on an endpoint that requires one (HTTP 401); deco serve never returns it |
| -32011 | Forbidden | Authenticated, but not allowed for this project |
Plus the standard JSON-RPC codes (-32700, -32600, -32601, -32602, -32603). The limits: at most 500 names per blocks.apply and per changes.discard, 20 names per changes.get, 10 calls per batch, 1 MiB per entry and 8 MiB per request; describe doesn't advertise them. Gzip doesn't bypass them: a compressed request body is measured after decompressing. An existing file over 1 MiB isn't an error: blocks.list leaves it out and reports it as a too-large diagnostic.
File names
The site editor, deco serve and deco content import one rule from the protocol subpath, so an entry the site editor edits is the entry your app renders:
- Name to file:
encodeURIComponent(name) + ".json", directly in.deco/blocks(no subfolders). A page namedpages-Home%20Page-6f1eis stored aspages-Home%2520Page-6f1e.json;collections/blog/posts/abcascollections%2Fblog%2Fposts%2Fabc.json. - File to name: decode the file name, without
.json, exactly once. If decoding fails, the raw name is the entry name. - Two spellings of one name (files that decode to the same name after repeated decoding): one wins, the file whose entry has a
path, then the one that took more decoding, then the lowest file name. The others are reported as diagnostics. A write overwrites the winning spelling and deletes the others in the same commit. - Names the site editor can't save: empty names; names containing
\,..or NUL; names whose encoded form is over 250 bytes, so the file fits a 255-byte file-name limit; a new name that differs from another entry's only in letter case; Windows device names such asCON;__proto__; and names ending in a source extension such as.tsor.tsx, which would shadow a module (those can still be deleted). - File content:
JSON.stringify(entry, null, 2)plus a newline, UTF-8.
The local server
deco serve knows nothing about accounts: it prints its local address, inside the site editor link, and the site editor connects to it.
deco serve runs inside your site's git repository, and its base is the repository's HEAD: the changes are your working tree compared with your last commit, whether or not you've staged them with git add. Only the working tree counts: a change you staged and then undid in the file, so the file matches the commit again, isn't listed. A repository with no commits yet (right after git init) has an empty base, so every entry is a change. It compares files the way git does, so a file git doesn't count as changed (for example a line-ending conversion) isn't listed, and files ignored by .gitignore in .deco/blocks are listed, because deco serve serves them. A discard writes the committed bytes back to the files, the way a checkout would, and regenerates the content module. It never commits. Since @decocms/blocks 8.2.1 it also puts the discarded entries back in git's index (the staging area) as they are in HEAD, so git status agrees with the site editor afterwards: a staged edit or deletion is unstaged, a staged new file is taken out of the index and deleted, and for a staged rename both the old and the new name are unstaged. Files you didn't discard keep their staging, and if any part fails, nothing is discarded. In 8.2.0, a discard wrote only the files and left the index as it was. Outside a git repository, or without the git command installed, deco serve doesn't start: see deco serve.
deco serve has no token or password, and it answers browser requests from any origin (CORS, with the request's Origin reflected), along with Chrome's local-network preflight. It listens on loopback only (127.0.0.1 and ::1, printed as localhost) unless you pass --host. Any website open in your browser can therefore read and write your content through it, so run it only while editing and stop it when you're done. The server rejects any Content-Type other than JSON on /rpc (uploads are the one exception, below). With --host set to an address other machines can reach, anyone on your network can read and write your content too, so the server prints a warning.
The site editor link is https://studio.decocms.com/site-editor#endpoint= followed by the encoded http://localhost:<port>/rpc. The site editor remembers the last endpoint in your browser, so opening /site-editor again reconnects to it; while the server is down or restarting, it shows that it's waiting for it and reconnects on its own. describe reports the app to preview as preview: { url }, the address given by --preview (by default your Vite config's port, else http://localhost:5173); the site editor's Preview tab loads only http or https URLs on a loopback host and shows no preview for anything else. To show one variant, it adds a ?__draft= pointer to this server's endpoint that forces that variant. The flow from the editor's side is in Edit on your machine.
Uploads aren't one of the methods. The site editor sends each file to PUT /assets/<name> on the same server; on that path the server accepts the file's own image, video, font or PDF content type instead of JSON. It writes the file to the asset folder (public/assets, or --assets), never overwrites an existing file (a taken name gets a short suffix), and answers with the path the site editor stores in the field. describe reports where uploads go and the largest file it accepts in its assets field; with --read-only, assets is null and uploads are refused. The site editor's GitHub backend stores uploads in Deco's asset storage instead, so they never become commits. How to serve local uploads is in Images and other uploads.
The package
The protocol ships inside @decocms/blocks, under the protocol subpath, with zod as its only runtime dependency. The CLI (the cli subpath) and the site editor import it; the SDK's runtime never does, so it never reaches an app bundle.
@decocms/blocks/protocol method types, errors, client, keys (browser-safe)
@decocms/blocks/protocol/keys the file-name rule above
@decocms/blocks/protocol/server createContentHandler(storage): (Request) => Response
@decocms/blocks/protocol/storage/fs the filesystem storage (Node only)
@decocms/blocks/protocol/conformance a black-box test suite over HTTPA storage implements a small interface: a snapshot of names and versions, reading file bodies, reading the schema, one atomic commit attempt, and three primitives for the base: base(), changes(base, snapshot) (the files that differ from the base, and the base's files) and readBaseFiles(). A custom storage written for 8.1.x must add those three to work with 8.2.0. An overlay storage also implements writeSnapshot(), its own files without the base, plus a tombstone (deleted: true, version TOMBSTONE_VERSION) for each base file it deletes: blocks.apply validates and checks ifMatch against it, and it makes describe report overlay: true. Its changes() reports the same tombstones, and a commit answers a tombstone's version for each deletion it records. Since 8.8.0 a storage no longer implements readSecretsPublicKey(), and a commit never carries a schema version to check. The core owns everything else: the JSON-RPC layer, validation, the file-name rule, limits and retries. The site editor's GitHub backend is one storage; the CLI's filesystem storage is another. The conformance suite runs against any endpoint, which is how both are kept to the same contract.
Conformance for hosted storage
The black-box suite covers atomic set and delete, set precedence, ifMatch guards, the file-name rule, the size limits, the three changes methods and uploads; its overlay/* cases run only against an endpoint that reports overlay: true, and check that ifMatch compares with the overlay, that changes.list lists the overlay's own entries, that deleting a block only the base has hides it, and that a deletion is held: ifMatch: null on it fails and its version passes. A hosted storage runs the same suite: give it a baseEntry on the production branch so the base cases run. A storage retry revalidates against what's stored now; a rate-limit response carries retry timing rather than triggering a burst of immediate retries. Versioned draft assets are served by the separate delivery contract, so a draft read is never mistaken for an immutable preview read.
Studio implementation
The Studio implementation handoff maps this design to existing Fast Preview modules and specifies persisted state, operation contracts, sequencing, initial limits, recovery scenarios and rollout phases.