Python client for kb0 — the knowledge base layer for AI agents (MCP, markdown, git).
Project description
kb0 (Python client)
Native Python client for kb0 — the knowledge base layer for AI agents. Markdown-first, git-backed, MCP-native.
This package hides the MCP plumbing and gives you a clean async VaultClient.
pip install kb0-mcp
The PyPI package is
kb0-mcp; you stillimport kb0in code.Requires the kb0 server. This is a client — it spawns the
kb0binary as a subprocess. Install it once with Node:npm install -g kb0-mcp, thenkb0 init my-vault.
Quickstart
import asyncio
from kb0 import VaultClient
async def main():
async with VaultClient(vault="./my-vault", agent="my-bot") as kb:
# write a note (author, id, timestamps set by the server)
res = await kb.write(
"notes/auth.md",
title="Auth: we chose JWT",
content="Short-lived access + refresh tokens. See [[notes/security.md]].",
tags=["security"],
)
print("created", res["path"], "hash", res["hash"])
# search (hybrid by default)
hits = await kb.search("authentication design")
for r in hits["results"]:
print(r["score"], r["title"], r["path"])
# read + update with optimistic locking
note = await kb.read("notes/auth.md")
await kb.update(
"notes/auth.md",
content=note["content"] + "\n\nUpdate: rotating keys monthly.",
expected_hash=note["hash"],
)
asyncio.run(main())
Hosted vault (kb0 cloud)
Point the same client at a kb0:// address with your API key and the vault
lives on the kb0 cloud — no local files, no kb0 engine install, pure Python
over HTTPS. Same methods; every operation lands in your audit trail:
async with VaultClient(
vault="kb0://team-kb",
agent="my-bot",
api_key="kb0_live_...", # create one in the kb0 dashboard (or set KB0_API_KEY)
) as kb:
await kb.write("notes/idea.md", title="Idea", content="...")
hits = await kb.search("idea") # hosted keyword search
graph = await kb.backlinks("notes/idea.md")
On a local vault, passing api_key= (or setting KB0_API_KEY) enables
content-free audit forwarding to the same dashboard.
Configuration
VaultClient passes everything through to kb0 serve:
VaultClient(
vault="./my-vault", # vault directory
agent="my-bot", # agent identity (provenance + ACL)
openai_api_key="sk-...", # optional — enables semantic search
strict=False, # require .vault-policy.yaml if True
command="kb0", # override the binary path if needed
env={"KB0_EMBEDDING_MODEL": "text-embedding-3-large"},
api_key="kb0_live_...", # optional — audit forwarding / hosted vaults
cloud_url=None, # override the kb0 cloud base URL (kb0:// vaults)
)
API
All methods are async and return plain dicts (the tool's structured output).
| Method | kb0 tool |
|---|---|
await kb.write(path, *, title, content, status="draft", tags=None) |
vault.write |
await kb.read(path) |
vault.read |
await kb.update(path, *, content, expected_hash, title=None, status=None, tags=None) |
vault.update |
await kb.delete(path) |
vault.delete |
await kb.search(query, *, mode="hybrid", ranking="rrf", limit=10, filters=None) |
vault.search |
await kb.list(*, prefix=None, tag=None, status=None, limit=50) |
vault.list |
await kb.recent(limit=10) |
vault.recent |
await kb.backlinks(path) |
vault.backlinks |
await kb.links(path) |
vault.links |
await kb.status() |
vault.status |
Errors
Failures raise typed exceptions you can catch:
from kb0 import KbConflictError, KbACLDeniedError, KbNotFoundError
try:
await kb.update("notes/x.md", content="...", expected_hash=stale_hash)
except KbConflictError:
note = await kb.read("notes/x.md") # re-read, get the current hash, retry
KbError is the base class; KbNotFoundError, KbConflictError,
KbValidationError, and KbACLDeniedError are its subclasses.
Why a subprocess?
kb0 is an MCP server. The Python client launches kb0 serve over stdio and speaks
MCP to it — the same protocol Claude Desktop uses. Your vault stays a local folder
of markdown under git; this client is just an ergonomic way for Python agents to
talk to it. See the main repo for the
architecture.
Audit log
Every call you make through the client is recorded server-side to
<vault>/.vault-index/kb0.log as content-free JSON lines — the path read, the
query searched, and the paths a search returned, never the note bodies. Failed
and denied calls are logged too, so you can audit what an agent read and
searched, not just what it changed (git already covers writes).
License
Apache 2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kb0_mcp-0.2.0.tar.gz.
File metadata
- Download URL: kb0_mcp-0.2.0.tar.gz
- Upload date:
- Size: 14.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15d82ea05ea01ae5adb70c9792c3f8ee798dd933022ea48cae68a9a8a73d6ae0
|
|
| MD5 |
579c72e9b01999bb5a01f4c0f0ab50cb
|
|
| BLAKE2b-256 |
7b653a8a3bdc37edc208197938db0399b0efe24cfc22afa0acf7ab92c08b878c
|
File details
Details for the file kb0_mcp-0.2.0-py3-none-any.whl.
File metadata
- Download URL: kb0_mcp-0.2.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.13 {"installer":{"name":"uv","version":"0.9.13"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ada4fe49413774bbf114cc74d03b9c006295cbab143096c676096d100643663
|
|
| MD5 |
295dc1ded90ee32f40252eebca7477ba
|
|
| BLAKE2b-256 |
55e8e449657a6ad84c27aba1b8f28e5c03ff613cc6b8a557ccf9087f3b2302eb
|