How sklad works
sklad is one binary, sklad. Its local commands (search, query, check, new, and the rest) read a knowledge base directly from disk. sklad serve runs a long-lived server over the same files that answers MCP clients and, when enabled, browsers.
Files and git are the source of truth
Section titled “Files and git are the source of truth”A knowledge base is a directory of Markdown files with YAML frontmatter, tracked by git, plus its definition in .kb/framework.toml. sklad keeps no other copy of your notes: no database of documents, nothing that has to be exported. You can edit the files in any editor, sync them with git, and sklad reads what is there. The only state of its own is the token database (auth_db_path), which holds bearer tokens and share links.
What the files mean comes from the definition: which kinds exist, where each lives, which fields it has. See the framework definition.
The index
Section titled “The index”Search, queries, links, and tasks are answered from an index of every document, held in memory. It is built whole on start and swapped in at once, so a request always sees one consistent snapshot, and a rebuild never blocks readers. The server rebuilds it:
- after each of its own writes;
- when the file watcher sees a change made behind its back, such as an edit in another editor or a
git pull, within about 250 ms (unlesswatchis off); - after an automatic pull that moved
HEAD.
The CLI builds the same index on every command; sklad stats shows its size and build time.
How the server writes
Section titled “How the server writes”Every write tool, such as kb_edit or inbox_capture, goes through one pipeline:
- Lock the file with an advisory lock file next to it (
.sklad.lock.<name>), so two writers cannot interleave. - Check for conflicts. A caller may pass the
expected_shaof the version it read. If the file changed since, the write fails with error-32002and returns the current SHA, and nothing is overwritten. - Scan the new content with the
[policy]rules for secrets and personal data. A blocking hit fails the write with-32003. - Write atomically: to a temporary file next to the target (
.sklad.tmp.*), then rename it into place. - Commit the change to git.
- Push the commit when
git.auto_pushis on, and rebuild the index.
sklad init adds the lock and temporary file patterns to .gitignore, and the server refuses to start without them, so these sidecar files never end up in a commit.
When other machines push to the same remote, git.auto_pull fetches and integrates their commits on a timer while holding off writes, see Keep the checkout in sync.
An MCP request
Section titled “An MCP request”- A client sends JSON-RPC to
POST /mcpover the Streamable HTTP transport, with a bearer token. - The authentication layer resolves the token:
kbsk_…tokens against the token database, anything else as an OAuth JWT. Failure is HTTP 401. - The handler checks the scope the tool needs (
kb:read,kb:write, orkb:admin) and refuses with-32001when it is missing. - The tool runs against the index snapshot, or through the write pipeline.
- The call is logged as one structured line and counted in the metrics.
The MCP server’s instructions, which every client receives on connecting, include the conventions generated from the definition, so an agent knows where each kind of note goes before it writes. See Authenticate MCP clients and Operate a running server for the details of steps 2 and 5.
Endpoints
Section titled “Endpoints”| Path | Purpose |
|---|---|
/mcp |
MCP over Streamable HTTP |
/healthz, /readyz |
Liveness and readiness |
/.well-known/oauth-protected-resource… |
OAuth metadata, only with OAuth enabled |
/, /<note path>, /search, /links |
The owner tier of the web view, only when enabled |
/s/<id> |
Shared pages, only when the web view is enabled |
Metrics are served on a separate listener, metrics_listen.
By default the server accepts only requests whose Host is localhost, 127.0.0.1, or ::1, plus the host of the OAuth resource URL when OAuth is on. Behind a proxy with a public name and no OAuth, set allowed_hosts, see the configuration reference.