On this page
MCP
MCP server
MCP server
okfsmith mcp exposes your knowledge bundle as an MCP (Model Context Protocol) server so AI agents — Claude Code, Claude Desktop, Cursor, Copilot, Gemini — can search and read your bundle directly. Nine of the thirteen tools are read-only. The other four are governed write-back tools: an agent can propose and write concepts, but every write lands at the unverified trust tier, is stamped with provenance, must pass the bundle validator, and is recorded in an append-only audit log. Human-reviewed concepts are never silently overwritten (see Governed write-back).
Quick start
pip install "okfsmith[mcp]"
okfsmith mcp ./kb
The server starts on stdio (the standard transport: your MCP client launches it as a subprocess) and exposes thirteen tools. Pick one:
okfsmith mcp ./kb --transport stdio # default
okfsmith mcp ./kb --transport sse # Server-Sent Events
okfsmith mcp ./kb --transport streamable-http # streamable HTTP
The thirteen tools
Tool outputs are compact markdown (not giant JSON) — designed as an agent's reading UI. The intended flow is progressive disclosure: index → search → get.
Read tools
| Tool | What it does |
|---|---|
index | Return the bundle's root index.md — the map of the whole knowledge base. Read this first to orient. |
list | List every concept: id, type, trust tier, title. Optional filter_type narrows by concept type and tier_filter narrows by trust tier (unverified / machine-confirmed / human-reviewed, case-insensitive, blank ignored, unknown tier is a clean error); both filters apply before limit caps rows. Optional as_of (ISO-8601 date/datetime) replays validity and supersession at that instant — the MCP analogue of the CLI's --as-of flag — and the listing title reports the evaluated instant. A non-current concept carries its temporal status on its row — e.g. _(superseded by policy-v2)_ — evaluated at the replay instant when as_of is given, so history never reads as live knowledge; current concepts carry no note. |
search | BM25-ranked keyword search over concept id, title, description, tags, and body. Title matches rank highest, body lowest; results carry excerpts. Optional as_of (ISO-8601 date/datetime) replays validity and supersession at that instant — the MCP analogue of the CLI's --as-of flag. A non-current hit carries its temporal status on its row — e.g. _(superseded by policy-v2)_, evaluated at the replay instant when as_of is given — so a superseded concept revealed with include_superseded=True never reads as current; current hits carry no note. |
get | Read one concept in full: YAML frontmatter followed by its markdown body. A non-current concept carries a note line under the document — e.g. _Note: **policy-v1** is superseded by policy-v2._ — evaluated at the as_of replay instant when one is given. Optional as_of (ISO-8601 date/datetime) replays validity and supersession at that instant — the MCP analogue of the CLI's read --as-of flag — and the replay instant is labeled on the note (or on a _Replayed as of …._ line when the concept is current at that instant); current concepts read byte-identical to before. Unknown ids produce an error — never fabricated content. |
neighbors | Show a concept's link graph neighborhood: outgoing links and incoming backlinks, so agents can walk the knowledge graph. Optional as_of (ISO-8601 date/datetime) replays validity and supersession at that instant — each row carries the linked concept's temporal status at the replay instant (e.g. _(superseded by policy-v2)_), the center concept carries a note line when non-current, and the replay instant is labeled. |
traverse | Breadth-first neighborhood expansion over markdown links (depth ≤ 3, cycle-safe), with an optional relation_filter and currency-aware ordering — superseded concepts hidden by default. Optional as_of (ISO-8601 date/datetime) replays validity and supersession at that instant — the MCP analogue of the CLI's --as-of flag — and the replay instant is labeled in the output. |
provenance | Trace a concept's provenance chain: sources[] frontmatter → footnote references → the ingested-source manifest (sync-state.json) with source file and digest. The concept's temporal status line is evaluated at the optional as_of replay instant when one is given, and the replay instant is labeled. |
diff | Diff the bundle against another bundle directory (against=) or the sync-state.json snapshot: added / removed / changed concepts with body SHA-256. Optional as_of (ISO-8601 date/datetime) replays validity and supersession at that instant — a non-current concept carries its temporal status on its row (e.g. _(superseded by policy-v2)_), evaluated at the replay instant when as_of is given, and the replay instant is labeled; a removed concept in the sync-state mode carries no note (no frontmatter survives to evaluate). |
validate | Validate the bundle against OKF v0.2 (E001–E004 / W001–W020) — the MCP analogue of the okfsmith validate CLI command: conformance plus advisory warnings, with the concept count and the verdict up top. Optional strict treats warnings as failures, like the CLI's --strict flag. Optional as_of (ISO-8601 date/datetime) replays the two clock-dependent warnings — W006 (content stale) and W020 (last_verified in the future) — at that instant instead of now, and labels the replay instant (_Validated as of …._). |
Governed write-back tools
| Tool | What it does |
|---|---|
preview_write_concept | Side-effect-free dry run of a create: shows the exact id, file path, frontmatter (with provenance block), and serialized content that write_concept would write. |
write_concept | Create a new concept. Refuses if the id already exists (use update_concept); the write is atomic, so exactly one concurrent writer wins. |
update_concept | Patch an existing concept's title, body, sources, or links; dry_run=true previews the diff without writing. |
audit_log | Read the append-only write audit trail at <bundle>/.okfsmith/audit.jsonl. |
Governed write-back
The four write-back tools exist so an agent can contribute to a bundle without being able to quietly rewrite it:
- Unverified by construction. Every MCP write lands at the
unverifiedtrust tier; anyverifiedmarkers in the input are stripped. - Validator-gated. The bundle validator runs before a write commits; new validation errors refuse the write and roll it back. If the validator itself fails, the write fails closed.
- Provenance-stamped. Each write adds a frontmatter provenance entry (actor
mcp:<tool>, UTC timestamp, input sources) and appends to the append-only audit log, readable via theaudit_logtool. - Human review is protected. A write never overwrites an existing concept (
write_conceptreturns a structured error pointing atupdate_concept), and altering a human-reviewed concept requires an explicitdowngrade_trust=true, which removes theverifiedmarker and is recorded in provenance. - Atomic. Creates claim the destination atomically (exactly one concurrent writer wins); a refused duplicate writes no audit entry.
If you want a strictly read-only server today, do not hand the agent a writable bundle directory: serve a copy, or mount the bundle read-only at the filesystem level. A future --read-only server flag is not currently implemented.
A typical agent session looks like this:
index— "what's in this bundle?"searchwith"billing retries"— ranked hits with excerptsgetwithbilling/retries— the full conceptneighborswithbilling/retries— related concepts via linkstraversewithbilling/retries,depth=2— the wider neighborhoodprovenancewithbilling/retries— where each claim came from
Evidence budgets
The read tools accept three evidence-budget parameters so agents get bounded evidence instead of unbounded context (the write-back tools take their own arguments — see their docstrings via preview_write_concept):
| Parameter | Meaning |
|---|---|
max_chunks | Max items (or 50-line text chunks) per response — default 10 for search/traverse, 50 elsewhere; hard cap 50. Notes (e.g. hidden-superseded counts) and ## section headers sit outside the budget; …[truncated, N more] counts remaining items only. |
max_tokens | Approximate output budget (chars ÷ 4). None (default) = unbounded; 0 = no item content; negative or unparseable values are treated as unbounded. Truncation cuts at whole-item boundaries, never mid-item, and is marked …[truncated, N more]. |
continuation_token | Opaque paging cursor from a truncated response — pass it back for the next page. Tokens are result-offset cursors, not tied to a query. An invalid or out-of-range token returns a clean error, never a traceback. |
search and traverse are currency-aware: superseded concepts are hidden by default (reported as a count); pass include_superseded=True to reveal them. traverse depth is capped at 3.
Claude Desktop config
Add okfsmith as an MCP server in your Claude Desktop config file (claude_desktop_config.json):
{
"mcpServers": {
"okfsmith-kb": {
"command": "okfsmith",
"args": ["mcp", "/absolute/path/to/kb"]
}
}
}
Restart Claude Desktop and the thirteen tools (index, list, search, get, neighbors, traverse, provenance, diff, validate, preview_write_concept, write_concept, update_concept, audit_log) appear in its tool list.