Metadata-Version: 2.4
Name: okf-mcp
Version: 0.6.0
Summary: MCP server for Open Knowledge Format (OKF) bundles — expose okf-ingest's deterministic consume verbs (search, context, graph impact, diff, doctor) as agent tools.
Author-email: Travis Jakel <travis.s.jakel@gmail.com>
License: Apache-2.0
Project-URL: Homepage, https://github.com/travisjakel/okf-mcp
Keywords: okf,open-knowledge-format,mcp,model-context-protocol,knowledge-graph,duckdb
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: okf-ingest>=0.14.0
Requires-Dist: mcp<3,>=2
Dynamic: license-file

# okf-mcp

**MCP server for [Open Knowledge Format](https://github.com/open-knowledge-format/open-knowledge-format) bundles** (OKF v0.3) — expose [okf-ingest](https://github.com/travisjakel/okf-ingest)'s deterministic consume verbs as tools any MCP client (Claude Code, Cursor, custom agents) can call.

Existing OKF MCP servers hand agents the markdown *files*. This one hands them
the **queryable catalog and concept graph**: index-first context assembly,
impact/backlink analysis, SQL over frontmatter, drift diffs, and health checks —
all deterministic okf-ingest code, no model calls in the server.

There is another package named `okf-mcp` (Node, on npm, by a different author).
This is the Python one on PyPI.

## Tools

| Tool | What the agent gets |
|---|---|
| `okf_list_bundles` | which bundles this server exposes, with each bundle's own `title`, `description` and `license` (OKF SPEC 8.1). The description says what a bundle covers and when to use it, which is how an agent holding several bundles picks one |
| `okf_search` | concepts whose title/body match a term; `current_only` leaves out what is deprecated or has a status outside draft/stable |
| `okf_get_concept` | one concept's frontmatter + full body |
| `okf_context` | **the flagship** — index.md + a concept's most relevant neighborhood as one curated markdown blob, ranked by exact Personalized PageRank over the author's link graph (pass `rank='bfs'` for plain depth) — or pass `query` (a free-text question) instead of `start` for lexical-seeded multi-PPR retrieval. Each concept that is deprecated, draft, stale or unverified carries a one-line note; `current_only` leaves out what is not current and swaps a deprecated concept for the replacement its `superseded_by` names, listing what it replaced and excluded |
| `okf_related` | the k concepts most relevant to a topic — exact PPR, no embeddings |
| `okf_impact` | inbound / outbound / transitive links — "what breaks if X changes" |
| `okf_sql` | read-only SELECT over the DuckDB catalog (`okf_bundle`, `okf_concept`, `okf_link`, `okf_validation`, `okf_source`, `okf_computation`) |
| `okf_diff` | what changed since the server loaded the bundle — on disk for a directory, upstream for a remote bundle — an agent's memory-refresh between looks |
| `okf_refresh` | reload a bundle after `okf_diff` shows changes: re-read a directory, or re-fetch a remote bundle into the cache |
| `okf_doctor` | health score + per-rule findings before trusting a bundle |
| `okf_computations` | **OKF SPEC 10** — the bundle's Attested Computations: the sanctioned way to compute each value, its runtime, its typed parameters, the executor, the receipt fields a run must return, and the attester that checks it. `attestable` is false when there is no runtime, no attester that resolves, or no computation to be found. Call before computing a number the bundle already defines |
| `okf_trust` | **OKF SPEC 5** — trust tier (unverified / machine-confirmed / human-reviewed, counting only sign-offs made at or after the content last changed), lifecycle `status`, `is_current`, `superseded_by` and `stale_after` per concept: how much weight to give a concept, and what has gone stale |

## Install & run

Built on the official MCP Python SDK v2 (MCP spec 2026-07-28); v2 servers
still answer the legacy `initialize` handshake, so pre-2026 clients keep
working. For environments pinned to SDK v1, install `okf-mcp==0.3.1`.

```bash
pip install okf-mcp        # depends on okf-ingest >= 0.14.0 and mcp >= 2

# one or more bundles: directories, okf-ingest .duckdb catalogs and/or remote
# bundles, optionally named (first one is the default target)
okf-mcp ~/my-bundle
okf-mcp wiki=~/wiki notes=~/vault snapshot=./kb.duckdb
```

### Remote bundles

A bundle can be a git URL or an http(s) tar/zip. After `#`, say where the
bundle is inside it:

```bash
okf-mcp crossplane=https://github.com/jkroepke/okf-crossplane-v2.git#subdir=catalog
okf-mcp kb=https://github.com/org/repo.git#subdir=docs/okf&branch=main
okf-mcp https://example.com/bundle.tar.gz
```

The bundle is fetched once into a local cache (`~/.cache/okf-mcp`, or
`$OKF_MCP_CACHE`, or `--cache-dir <dir>`) and read from there, so later starts
need no network. `okf_diff` fetches the source again and reports what changed
upstream without replacing the loaded copy; `okf_refresh` fetches it again and
loads it; `--refresh` re-fetches every remote bundle at startup. A fetch that
fails leaves the previous copy in place. Only the sources named on the command
line are ever fetched: no tool lets an agent add one.

### A notes vault

Under OKF v0.3 a `.md` file with no `type` in its frontmatter is not a concept,
so a vault that was never written as OKF shows nothing. Start the server with
`--untyped keep` to read those files as concepts anyway:

```bash
okf-mcp --untyped keep notes=~/vault
```

Register with Claude Code:

```bash
claude mcp add okf -- okf-mcp ~/my-bundle
```

Or in any MCP client config:

```json
{ "mcpServers": { "okf": { "command": "okf-mcp", "args": ["wiki=/path/to/bundle"] } } }
```

## Design notes

- **Read-only.** Directory bundles are ingested into disposable in-memory
  DuckDB catalogs at startup; `.duckdb` sources open read-only; `okf_sql`
  accepts SELECT/WITH only. The server never writes to your bundle. The only
  thing it writes is its own cache of remote bundles.
- **Lifecycle is annotated by default, filtered on request.** A deprecated
  concept is still a real link target, and a bundle whose producer writes its
  own status words would lose every page to a filter, so `current_only` is
  off unless the agent asks for it.
- **Deterministic.** Every tool is plain okf-ingest code — same input, same
  answer; the only nondeterminism an agent sees is its own.
- **Concepts resolve by name.** `okf_get_concept` / `okf_context` / `okf_impact`
  accept a path *or* a wikilink-style name — id, alias, title, or filename stem,
  compared on alphanumerics ('agent memory architecture' finds
  `ops/agent_memory_architecture.md`). Ambiguous names return the candidate
  list instead of guessing.
- **`[[wikilinks]]` work.** Vault-style bundles (Obsidian/Logseq/Foam) resolve
  by id / alias / title / stem. This is an okf-ingest extension: the OKF spec
  says wikilinks are not links.

Apache-2.0. Sibling project: [okf-ingest](https://github.com/travisjakel/okf-ingest) (the R + Python ingestion tool this wraps).
