kb CLI & Local Stores
Run standalone local Git+SQLite knowledge stores with built-in Gemma/Qwen embeddings, log in securely to remote servers, and aggregate multiple servers over stdio MCP.
The kb CLI (Apache-2.0, Rust) is both a standalone local knowledge-base runtime and a remote MCP stdio bridge + export tool. Both local and remote modes expose the exact same 34-tool kb/1 catalog and validated schemas; protocol output goes to stdout and diagnostics go to stderr.
Standalone local durable stores
A local store is a managed multi-KB directory holding state.sqlite (identities, principals, receipts, PRs, providers, and sealed metadata), bare Git repos under repos/kb_<id>.git, content-addressed assets, and rebuildable SQLite search indexes under indexes/<kbId>/<generationId>.sqlite.
[!WARNING]
state.sqliteis not disposable. Deleting it from a non-empty store puts the store inREPAIR_REQUIRED. Only files underindexes/are rebuildable derived search generations. Never manually delete lock files or edit managed Git refs inside a store.
Initialize configuration and point kb at an absolute store path:
kb config init
kb config set-root /srv/my-kb-store
kb config show
kb mcp # uses configured root
kb mcp --root /srv/my-kb-store # explicit override
- Git 2.45+ check:
kb mcp --rootchecks the installed Git version at startup and refuses initialization withSTORAGE_UNAVAILABLEif Git is older than 2.45. - Path & lock safety: Store roots and data/cache directories are resolved once at startup (refusing user-writable symlinks on Unix and all symlinks/junctions on Windows). Persistent store and KB locks are inherited by Git child processes with a 30-second PR deadline (and kill-on-close Job Objects on Windows 10+).
- Local rate limits: Generous per-store guardrails prevent runaway agent loops (600 searches/KB/min, 60 KB creates/hour, 30 index rebuilds/KB/hour, 600 writes/actor/KB/min, 1 GiB staged uploads/hour).
Local capability principals and scoping flags
By default, the local store owner holds every permission, so owner edits go straight to main. To give an agent propose-only or read-only access against a local store, mint a local capability principal:
kb principals create --kb <kbId> --access propose # prints <principalId>
kb mcp --principal <principalId> # agent edits become PRs
kb principals list
kb principals remove <principalId> # revokes on next call
Access levels are read, propose, write, review, and manage (with the same bit expansion as the server: manage → write + review; write → propose → read; review → read).
Additional stdio scoping flags work on local stores (--tools, --read-only, and --write-mode also narrow remote connections):
kb mcp --read-only
kb mcp --tools propose --kb <kbId1>,<kbId2>
kb mcp --write-mode dream
--tools <group|preset,...>accepts groups (read,edit,assets,export,pull_requests,index_admin,kb_admin,sealed) or presets (read,propose,direct).--write-mode dream|edit|both(defaultboth) restricts whether the connection can dream, edit directly, or both. All direct edits throughkb mcpare stampedprovenance: agent.
Built-in CPU embeddings (kb model)
Local stores support optional on-device CPU embeddings using Apache-2.0 GGUF models powered by vendored llama.cpp v0.9.0—no external API keys required. Both models start disabled and weights are downloaded on demand with SHA-256 verification (never bundled in the binary):
| Model ID | Quantized GGUF | Dimensions / Pooling |
|---|---|---|
embeddinggemma-2-q8_0 (default) |
~310 MB (embeddinggemma-2-Q8_0.gguf) |
768 / MEAN |
qwen3-embedding-0.6b-q8_0 |
~639 MB (Qwen3-Embedding-0.6B-Q8_0.gguf) |
1024 / LAST |
kb model list --json # shows 1K/2K/4K/8K memory estimates & recommendation
kb model enable # downloads, verifies & load-probes Gemma at 1024 context
kb model enable qwen3-embedding-0.6b-q8_0 --context 2048
kb model status
kb model verify
kb model disable # drains worker, keeps cached weights
kb model remove qwen3-embedding-0.6b-q8_0 --yes
kb providers attach --kb <kbId> --provider builtin
- Memory admission: Options below 70% of available RAM admit automatically; 70%–90% require
--acknowledge-memory-warning; ≥ 90% or unknown RAM fail closed. - Shared per-user cache & detached worker: Weights live in a single owner-only per-user cache (
~/.cache/kb/models/verified/on Linux, or read-only source viamodels_dirin config). Inference runs in one shared detachedkb embed-workerdaemon per user over an authenticated0700Unix socket (or protected Windows named pipe), serving allkb mcpsessions concurrently, prioritizing interactive queries ahead of background index builds, and exiting automatically after 15 minutes idle. - External providers: On low-RAM machines, register any OpenAI-compatible
/embeddingsendpoint instead:
kb providers register --idempotency-key reg-1 --key-stdin ...
kb providers probe --provider <id> --revision 1
kb providers attach --kb <kbId> --provider <id> --revision 1
kb providers list --json
Provider API keys and the local store’s sealed master key live exclusively in the native OS keystore (macOS Keychain, Windows Credential Manager, Linux Secret Service); headless environments without a keystore fail closed with no plaintext fallback.
Remote device login and exports
Connect kb to a remote Knowledge Base server without pasting tokens into shell history:
kb config set-server https://kb.example.com
kb login --name "Work Laptop" --write-mode edit
kb mcp --server https://kb.example.com
kb logout
- Device approval flow:
kb loginprints a verification URL and public user code to stderr. Open the link in your browser, compare the code, and select exact KB permissions, tool groups, write mode, and expiry (nothing is preselected). - PAT import: Import an existing PAT via
kb login --token-stdin(piped) orkb login --token-file /private/token(Unix requires an owner-only0600regular file with no symlinks or hard links; Windows requires a protected current-SID DACL). There is no--tokenflag or credential-print command. - Sealed values (
--recipient-key-file): Pass--recipient-key-file /private/recipient.json(an existing host-owned X25519 private key) tokb loginso only its public key is uploaded for approval. Enrolled 2FA and explicit exact-record approval are required. Plaintext decryption happens only in the host’skb-clientresolver, never in agent stdio output. - Logout:
kb logoutcalls the server’s bearer-onlyPOST /api/kb/token/revoke-selfendpoint before deleting local state. Usekb logout --localto delete only local state (leaving the remote PAT active).
Background ZIP exports (kb export)
kb export --kb <kbId> --output knowledge-base.zip
kb export --kb <kbId> --kind assets --rev <commit-sha> --output assets.zip --json
kb export --kb <kbId> --no-wait # returns <transfer-id>
kb export --kb <kbId> --transfer <transfer-id> --status
kb export --kb <kbId> --transfer <transfer-id> --output out.zip
kb export --kb <kbId> --transfer <transfer-id> --cancel
kb export starts a server-side background job (30-minute build cap), polls with bounded backoff (default --wait-timeout 2100 s), downloads chunked MCP frames, verifies total size and SHA-256, fsyncs to a new private destination, and acknowledges completion to release the server export slot.
Credential custody and transport security
- Origin-bound store: Credentials live in
<data-dir>/credentials(override<data-dir>withKB_DATA_DIR, unrelated to the server’sKB_DATA_ROOT), separate fromconfig.toml, keyed by canonical server origin + exact/mcpresource. Changing servers never leaks another server’s token. - OS-native protection:
- Unix/macOS: Mode
0700directories and0600files published via atomic rename with file and directory fsync under a shared directory lock. - Windows: Encrypted with DPAPI
CurrentUserand protected current-SID-only DACLs; unavailable protection fails closed. - All platforms refuse symlinks and Windows reparse points/junctions.
- Unix/macOS: Mode
- HTTPS-only & no silent proxies: Plain HTTP is rejected unless
--allow-loopback-httpis passed explicitly for loopback development (or saved for that single server viakb config set-server <url> --allow-loopback-http). Redirects are rejected, and ambient proxy environment variables are ignored—opt into a proxy explicitly withproxy = "http://127.0.0.1:8080"inconfig.toml(no URL credentials allowed).
Multi-server stdio MCP aggregation
Forward up to 16 remote Knowledge Base servers through a single kb mcp stdio process so the agent pays the tool-schema token cost (~8k tokens) once instead of once per server:
kb config add-server work https://kb.work.example.com
kb config add-server personal https://kb.personal.example.com --read-only
kb config add-server private-lab https://kb.lab.example.com --no-search-all
kb login --server work
kb login --server personal
kb config set-mcp-servers work personal
kb mcp
Or pass servers inline in your MCP client config:
{
"mcpServers": {
"kb": {
"command": "kb",
"args": ["mcp", "--server", "work", "--server", "personal"]
}
}
}
How multi-server aggregation protects isolation:
- Explicit
serverrouting: Every tool is advertised once and adds a requiredserverargument (enumof servers that grant that tool).kbstripsserverbefore forwarding exclusively to that server with only its own credential and tags every response with_meta: {"kb/server": "<name>"}. (server, kbId)isolation: AkbIdobserved from one server is refused locally (FORBIDDEN) if sent to another server, preventing cross-server ID or ciphertext leakage.- Cross-server
knowledge_search_all:serveris optional onknowledge_search_all. Omittingserverfans the query out concurrently to every participating server that has not opted out (--no-search-all/search_all = false), validates untrusted replies against the pinned schema, rank-interleaves hits across(server, base)pairs (capped at 100 hits and a fair per-server JSON byte budget), and reports per-server statuses (ok,unavailable,logged_out,rate_limited,busy,deadline, etc.) without failing the whole call if one server is down. - Failure & concurrency isolation: Startup verifies all servers in parallel within 10 seconds (unreachable servers are omitted for the session and noted in instructions). Each upstream server is capped at 3 concurrent in-flight calls (4 total across the stdio connection), so one hung server cannot starve others. Note:
--root(local store) and--server(remote servers) cannot be combined on the samekb mcpprocess.