okfsmith logo okfsmith Docs Website EN Open okfsmith
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

ToolWhat it does
indexReturn the bundle's root index.md — the map of the whole knowledge base. Read this first to orient.
listList 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.
searchBM25-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.
getRead 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.
neighborsShow 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.
traverseBreadth-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.
provenanceTrace 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.
diffDiff 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).
validateValidate 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

ToolWhat it does
preview_write_conceptSide-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_conceptCreate a new concept. Refuses if the id already exists (use update_concept); the write is atomic, so exactly one concurrent writer wins.
update_conceptPatch an existing concept's title, body, sources, or links; dry_run=true previews the diff without writing.
audit_logRead 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 unverified trust tier; any verified markers 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 the audit_log tool.
  • Human review is protected. A write never overwrites an existing concept (write_concept returns a structured error pointing at update_concept), and altering a human-reviewed concept requires an explicit downgrade_trust=true, which removes the verified marker 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:

  1. index — "what's in this bundle?"
  2. search with "billing retries" — ranked hits with excerpts
  3. get with billing/retries — the full concept
  4. neighbors with billing/retries — related concepts via links
  5. traverse with billing/retries, depth=2 — the wider neighborhood
  6. provenance with billing/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):

ParameterMeaning
max_chunksMax 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_tokensApproximate 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_tokenOpaque 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.

Advanced: other clients and transports - **Claude Code** and **Cursor** accept the same stdio command shape (`okfsmith mcp `); check their MCP server docs for the exact config file location. - For **SSE** or **streamable-http** transports, point your client at the server's URL — the bundle is loaded once at server startup, and every tool call afterwards reads from the in-memory bundle, so responses are fast. - The read tools back the interactive chat's `/search` and `/read` commands, so chat and MCP rank identically. Chat itself never writes to your bundle; only the MCP write-back tools can, under the governance above.

Next →

Troubleshooting →