okf-cli 0.8.0__tar.gz → 0.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- okf_cli-0.9.0/.github/workflows/publish.yml +40 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/.github/workflows/test.yml +2 -1
- {okf_cli-0.8.0 → okf_cli-0.9.0}/AGENTS.md +2 -2
- okf_cli-0.9.0/PKG-INFO +166 -0
- okf_cli-0.9.0/README.md +132 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/pyproject.toml +1 -1
- {okf_cli-0.8.0 → okf_cli-0.9.0}/skills/okf-cli/SKILL.md +24 -0
- okf_cli-0.9.0/src/okf/api.py +1415 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/src/okf/cli.py +2 -0
- okf_cli-0.9.0/src/okf/commands/reindex.py +29 -0
- okf_cli-0.9.0/src/okf/commands/serve_mcp.py +213 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/src/okf/core.py +68 -29
- {okf_cli-0.8.0 → okf_cli-0.9.0}/tests/test_api.py +441 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/tests/test_cli.py +42 -0
- okf_cli-0.9.0/tests/test_mcp.py +297 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/uv.lock +1 -1
- {okf_cli-0.8.0 → okf_cli-0.9.0}/wiki/architecture.md +43 -25
- {okf_cli-0.8.0 → okf_cli-0.9.0}/wiki/domain-model.md +10 -4
- {okf_cli-0.8.0 → okf_cli-0.9.0}/wiki/operations.md +13 -10
- {okf_cli-0.8.0 → okf_cli-0.9.0}/wiki/quickstart.md +16 -4
- {okf_cli-0.8.0 → okf_cli-0.9.0}/wiki/testing.md +10 -3
- {okf_cli-0.8.0 → okf_cli-0.9.0}/wiki/workflows.md +41 -8
- okf_cli-0.8.0/PKG-INFO +0 -89
- okf_cli-0.8.0/README.md +0 -55
- okf_cli-0.8.0/src/okf/api.py +0 -780
- okf_cli-0.8.0/src/okf/commands/serve_mcp.py +0 -70
- okf_cli-0.8.0/tests/test_mcp.py +0 -109
- {okf_cli-0.8.0 → okf_cli-0.9.0}/.agents/skills/wiki/SKILL.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/.gitignore +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/.last-update.json +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/LICENSE +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/SPEC/OKF_SPEC_V0_1.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/SPEC/OKF_SPEC_V0_2.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/.okfignore +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/README.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/blank-line/no-blank.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/blank-line/with-blank.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/computations/revenue.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/datasets/sales.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/domain.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/loose/deep/no-heading.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/loose/no-desc.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/loose/no-title.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/metrics/income-statement.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/playbooks/incident-response.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/playbooks/oncall-guide.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/references/revenue-recognition.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/smoke-ignore.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/tables/customers.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/tables/orders.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/tables/partitions/2026/q1/jan/january.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/example/tables/partitions/daily.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/skills/writing-knowledge-base/SKILL.md +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/src/okf/__init__.py +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/src/okf/commands/__init__.py +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/src/okf/commands/bundle.py +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/src/okf/commands/list.py +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/src/okf/commands/read.py +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/src/okf/commands/validate.py +0 -0
- {okf_cli-0.8.0 → okf_cli-0.9.0}/tests/test_core.py +0 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- "v0.*.*"
|
|
7
|
+
|
|
8
|
+
permissions:
|
|
9
|
+
contents: read
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
publish:
|
|
13
|
+
runs-on: ubuntu-latest
|
|
14
|
+
permissions:
|
|
15
|
+
contents: read
|
|
16
|
+
id-token: write
|
|
17
|
+
steps:
|
|
18
|
+
- uses: actions/checkout@v4
|
|
19
|
+
- uses: actions/setup-python@v5
|
|
20
|
+
with:
|
|
21
|
+
python-version: "3.11"
|
|
22
|
+
- uses: astral-sh/setup-uv@v3
|
|
23
|
+
- name: Verify tag matches package version
|
|
24
|
+
run: |
|
|
25
|
+
tag="$GITHUB_REF_NAME"
|
|
26
|
+
if [[ ! "$tag" =~ ^v0\.[0-9]+\.[0-9]+$ ]]; then
|
|
27
|
+
echo "Tag $tag must have the form v0.x.x" >&2
|
|
28
|
+
exit 1
|
|
29
|
+
fi
|
|
30
|
+
|
|
31
|
+
tag_version="${tag#v}"
|
|
32
|
+
package_version="$(uv version --short)"
|
|
33
|
+
if [[ "$tag_version" != "$package_version" ]]; then
|
|
34
|
+
echo "Tag version $tag_version does not match pyproject.toml version $package_version" >&2
|
|
35
|
+
exit 1
|
|
36
|
+
fi
|
|
37
|
+
- name: Build distributions
|
|
38
|
+
run: uv build
|
|
39
|
+
- name: Publish distributions to PyPI
|
|
40
|
+
run: uv publish
|
|
@@ -10,9 +10,10 @@ jobs:
|
|
|
10
10
|
python-version: ["3.11"]
|
|
11
11
|
steps:
|
|
12
12
|
- uses: actions/checkout@v4
|
|
13
|
-
- uses:
|
|
13
|
+
- uses: actions/setup-python@v5
|
|
14
14
|
with:
|
|
15
15
|
python-version: ${{ matrix.python-version }}
|
|
16
|
+
- uses: astral-sh/setup-uv@v3
|
|
16
17
|
- run: uv sync
|
|
17
18
|
- run: uvx ruff check .
|
|
18
19
|
- run: uvx ruff format --check .
|
|
@@ -21,8 +21,8 @@ Python 3.11+, **uv**, **typer**, **pyyaml**, **rich**, **pytest**, **ruff**, **h
|
|
|
21
21
|
- `src/okf/cli.py` — Typer entrypoint and command registration
|
|
22
22
|
- `src/okf/api.py` — programmatic API; all business logic lives here
|
|
23
23
|
- `src/okf/core.py` — shared parsing, formatting, and conformance helpers
|
|
24
|
-
- `src/okf/commands/` — thin CLI wrappers (`bundle`, `list`, `read`, `validate`)
|
|
25
|
-
- `tests/` — `test_api.py`, `test_cli.py`, `test_core.py`
|
|
24
|
+
- `src/okf/commands/` — thin CLI wrappers (`bundle`, `list`, `read`, `reindex`, `validate`, `serve_mcp`)
|
|
25
|
+
- `tests/` — `test_api.py`, `test_cli.py`, `test_core.py`, `test_mcp.py`
|
|
26
26
|
- `wiki/` — architecture, workflows, domain model, operations, testing notes
|
|
27
27
|
- `.github/workflows/test.yml` — CI (pytest + ruff on Python 3.11)
|
|
28
28
|
|
okf_cli-0.9.0/PKG-INFO
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: okf-cli
|
|
3
|
+
Version: 0.9.0
|
|
4
|
+
Summary: Open Knowledge Format tooling
|
|
5
|
+
License: MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2026 Dheerapat Tookkane
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
10
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
11
|
+
in the Software without restriction, including without limitation the rights
|
|
12
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
13
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
14
|
+
furnished to do so, subject to the following conditions:
|
|
15
|
+
|
|
16
|
+
The above copyright notice and this permission notice shall be included in all
|
|
17
|
+
copies or substantial portions of the Software.
|
|
18
|
+
|
|
19
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
20
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
21
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
22
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
23
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
24
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
25
|
+
SOFTWARE.
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Python: >=3.11
|
|
28
|
+
Requires-Dist: pyyaml>=6
|
|
29
|
+
Requires-Dist: rich>=15.0.0
|
|
30
|
+
Requires-Dist: typer>=0.15
|
|
31
|
+
Provides-Extra: mcp
|
|
32
|
+
Requires-Dist: fastmcp<5,>=4.1.4; extra == 'mcp'
|
|
33
|
+
Description-Content-Type: text/markdown
|
|
34
|
+
|
|
35
|
+
# okf-cli — Open Knowledge Format tooling
|
|
36
|
+
|
|
37
|
+
Convert plain markdown directories into [OKF](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md)-conformant knowledge bundles. `okf bundle` generates YAML frontmatter, concept types, provenance, and per-directory `index.md` files; `okf validate`, `okf list`, and `okf read` consume the resulting bundle.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
uv tool install okf-cli
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
This installs the `okf` command. To include the optional MCP server support at the same time, install with the `mcp` extra instead:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
uv tool install 'okf-cli[mcp]'
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
(If you already installed without it, reinstall with `uv tool install --force 'okf-cli[mcp]'`.)
|
|
52
|
+
|
|
53
|
+
Check the installation:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
okf --help
|
|
57
|
+
okf --version
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## Quick example
|
|
61
|
+
|
|
62
|
+
Try it on a scratch directory:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
mkdir okf-demo
|
|
66
|
+
printf '# Customers\n\n> Master table of customers.\n\nOne row per customer.\n' > okf-demo/customers.md
|
|
67
|
+
|
|
68
|
+
okf bundle okf-demo
|
|
69
|
+
okf validate okf-demo_knowledge_base
|
|
70
|
+
okf list okf-demo_knowledge_base
|
|
71
|
+
okf read okf-demo_knowledge_base customers
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Your real usage will point at your own markdown directories instead:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
okf bundle my-notes
|
|
78
|
+
okf validate my-notes_knowledge_base
|
|
79
|
+
okf list my-notes_knowledge_base
|
|
80
|
+
okf read my-notes_knowledge_base <concept-id>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Run `okf <command> --help` for options such as `--default-type`, `--force`, `--strict`, and `--dry-run`. (Without an explicit output directory, `okf bundle <input-dir>` writes to `<input-dir>_knowledge_base` in the current directory.)
|
|
84
|
+
|
|
85
|
+
## Commands
|
|
86
|
+
|
|
87
|
+
| Command | Purpose |
|
|
88
|
+
| ------------------------------------- | -------------------------------------------- |
|
|
89
|
+
| `okf bundle <input-dir> [output-dir]` | Convert markdown into an OKF bundle |
|
|
90
|
+
| `okf validate <directory>` | Check OKF v0.2 §11 conformance |
|
|
91
|
+
| `okf list <directory>` | List concepts (ID, type, title, description) |
|
|
92
|
+
| `okf read <directory> <concept-id>` | Print a concept by ID |
|
|
93
|
+
| `okf reindex <directory>` | Rebuild every `index.md` from the concepts |
|
|
94
|
+
| `okf serve-mcp <directory>` | Serve a conformant bundle over MCP HTTP |
|
|
95
|
+
|
|
96
|
+
### MCP server
|
|
97
|
+
|
|
98
|
+
Install the optional MCP dependency (if you installed with `uv tool install okf-cli`, reinstall with `--force 'okf-cli[mcp]'` as shown above), then serve a conformant bundle over Streamable HTTP:
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
okf serve-mcp my-bundle
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
The server binds to `127.0.0.1:8000` by default and listens at `http://127.0.0.1:8000/mcp`. Use `--host` and `--port` to change the bind address; `--host 0.0.0.0` listens on all IPv4 interfaces. The server exposes read-only tools:
|
|
105
|
+
|
|
106
|
+
| Tool | Purpose |
|
|
107
|
+
| ------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
108
|
+
| `search(query, type, filters, limit)` | Find concepts by words in the ID, title, description, tags or any other frontmatter value |
|
|
109
|
+
| `browse(path)` | List a directory's concepts and subdirectories with bundle-relative IDs and paths |
|
|
110
|
+
| `read_concept(concept_id, section)` | Read a concept, or only one section; `links` resolves body links to concept IDs (`exists`) |
|
|
111
|
+
| `list_concepts()` | List every concept (prefer `search`/`browse` for large bundles) |
|
|
112
|
+
|
|
113
|
+
Every call re-reads files changed on disk since the previous call, so a bundle can be regenerated while it is served. The server instructions describe the tools and append the bundle's `AGENTS.md` when present. Add `--token <secret>` to require the matching `Authorization: Bearer <secret>` header on MCP requests; without it, requests are unauthenticated. For example:
|
|
114
|
+
|
|
115
|
+
```bash
|
|
116
|
+
okf serve-mcp my-bundle --token "$OKF_MCP_TOKEN"
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
Use HTTPS (typically through a TLS-terminating proxy) when serving beyond localhost. The token is a command-line argument and may be visible in shell history or process listings; use this option only on a trusted network, and do not treat it as a replacement for TLS.
|
|
120
|
+
|
|
121
|
+
#### HTTPS with Caddy
|
|
122
|
+
|
|
123
|
+
When Caddy runs on the same machine, leave the MCP server bound to its default `127.0.0.1` address and let Caddy handle public HTTPS:
|
|
124
|
+
|
|
125
|
+
```caddyfile
|
|
126
|
+
mcp.example.com {
|
|
127
|
+
reverse_proxy 127.0.0.1:8000
|
|
128
|
+
}
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Start the MCP server with authentication enabled:
|
|
132
|
+
|
|
133
|
+
```bash
|
|
134
|
+
okf serve-mcp my-bundle --token "$OKF_MCP_TOKEN"
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Clients connect to `https://mcp.example.com/mcp` and send `Authorization: Bearer <token>`. Keep port `8000` private; Caddy should be the public entry point. Caddy can provision HTTPS automatically when the domain points to the server and is reachable on the required ports.
|
|
138
|
+
|
|
139
|
+
## Python library
|
|
140
|
+
|
|
141
|
+
`src/okf/api.py` is usable directly as a library:
|
|
142
|
+
|
|
143
|
+
```python
|
|
144
|
+
from okf.api import Bundle, bundle, reindex, validate, write_concept
|
|
145
|
+
|
|
146
|
+
result = bundle("example", "out", default_type="reference", force=True)
|
|
147
|
+
assert validate("out").ok
|
|
148
|
+
|
|
149
|
+
# Programs that generate concepts themselves keep every frontmatter key as given.
|
|
150
|
+
write_concept(
|
|
151
|
+
"out", "tables/invoices", {"type": "tables", "title": "Invoices"}, "Body."
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
# Rebuild index.md files after concepts were added or removed directly.
|
|
155
|
+
reindex("out") # also: `okf reindex out`; stale indexes are emptied, never deleted
|
|
156
|
+
|
|
157
|
+
# Repeated reads: load once, then search and read from memory.
|
|
158
|
+
kb = Bundle.open("out")
|
|
159
|
+
kb.search("customer", type_="tables")
|
|
160
|
+
kb.read("tables/customers", section="Schema").body
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## Documentation
|
|
164
|
+
|
|
165
|
+
- OKF v0.2 specification: [SPEC/OKF_SPEC_V0_2.md](SPEC/OKF_SPEC_V0_2.md)
|
|
166
|
+
- Development and contributor docs: [wiki/quickstart.md](wiki/quickstart.md) and [AGENTS.md](AGENTS.md)
|
okf_cli-0.9.0/README.md
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
# okf-cli — Open Knowledge Format tooling
|
|
2
|
+
|
|
3
|
+
Convert plain markdown directories into [OKF](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md)-conformant knowledge bundles. `okf bundle` generates YAML frontmatter, concept types, provenance, and per-directory `index.md` files; `okf validate`, `okf list`, and `okf read` consume the resulting bundle.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
uv tool install okf-cli
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
This installs the `okf` command. To include the optional MCP server support at the same time, install with the `mcp` extra instead:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
uv tool install 'okf-cli[mcp]'
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
(If you already installed without it, reinstall with `uv tool install --force 'okf-cli[mcp]'`.)
|
|
18
|
+
|
|
19
|
+
Check the installation:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
okf --help
|
|
23
|
+
okf --version
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Quick example
|
|
27
|
+
|
|
28
|
+
Try it on a scratch directory:
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
mkdir okf-demo
|
|
32
|
+
printf '# Customers\n\n> Master table of customers.\n\nOne row per customer.\n' > okf-demo/customers.md
|
|
33
|
+
|
|
34
|
+
okf bundle okf-demo
|
|
35
|
+
okf validate okf-demo_knowledge_base
|
|
36
|
+
okf list okf-demo_knowledge_base
|
|
37
|
+
okf read okf-demo_knowledge_base customers
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Your real usage will point at your own markdown directories instead:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
okf bundle my-notes
|
|
44
|
+
okf validate my-notes_knowledge_base
|
|
45
|
+
okf list my-notes_knowledge_base
|
|
46
|
+
okf read my-notes_knowledge_base <concept-id>
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Run `okf <command> --help` for options such as `--default-type`, `--force`, `--strict`, and `--dry-run`. (Without an explicit output directory, `okf bundle <input-dir>` writes to `<input-dir>_knowledge_base` in the current directory.)
|
|
50
|
+
|
|
51
|
+
## Commands
|
|
52
|
+
|
|
53
|
+
| Command | Purpose |
|
|
54
|
+
| ------------------------------------- | -------------------------------------------- |
|
|
55
|
+
| `okf bundle <input-dir> [output-dir]` | Convert markdown into an OKF bundle |
|
|
56
|
+
| `okf validate <directory>` | Check OKF v0.2 §11 conformance |
|
|
57
|
+
| `okf list <directory>` | List concepts (ID, type, title, description) |
|
|
58
|
+
| `okf read <directory> <concept-id>` | Print a concept by ID |
|
|
59
|
+
| `okf reindex <directory>` | Rebuild every `index.md` from the concepts |
|
|
60
|
+
| `okf serve-mcp <directory>` | Serve a conformant bundle over MCP HTTP |
|
|
61
|
+
|
|
62
|
+
### MCP server
|
|
63
|
+
|
|
64
|
+
Install the optional MCP dependency (if you installed with `uv tool install okf-cli`, reinstall with `--force 'okf-cli[mcp]'` as shown above), then serve a conformant bundle over Streamable HTTP:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
okf serve-mcp my-bundle
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The server binds to `127.0.0.1:8000` by default and listens at `http://127.0.0.1:8000/mcp`. Use `--host` and `--port` to change the bind address; `--host 0.0.0.0` listens on all IPv4 interfaces. The server exposes read-only tools:
|
|
71
|
+
|
|
72
|
+
| Tool | Purpose |
|
|
73
|
+
| ------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
74
|
+
| `search(query, type, filters, limit)` | Find concepts by words in the ID, title, description, tags or any other frontmatter value |
|
|
75
|
+
| `browse(path)` | List a directory's concepts and subdirectories with bundle-relative IDs and paths |
|
|
76
|
+
| `read_concept(concept_id, section)` | Read a concept, or only one section; `links` resolves body links to concept IDs (`exists`) |
|
|
77
|
+
| `list_concepts()` | List every concept (prefer `search`/`browse` for large bundles) |
|
|
78
|
+
|
|
79
|
+
Every call re-reads files changed on disk since the previous call, so a bundle can be regenerated while it is served. The server instructions describe the tools and append the bundle's `AGENTS.md` when present. Add `--token <secret>` to require the matching `Authorization: Bearer <secret>` header on MCP requests; without it, requests are unauthenticated. For example:
|
|
80
|
+
|
|
81
|
+
```bash
|
|
82
|
+
okf serve-mcp my-bundle --token "$OKF_MCP_TOKEN"
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Use HTTPS (typically through a TLS-terminating proxy) when serving beyond localhost. The token is a command-line argument and may be visible in shell history or process listings; use this option only on a trusted network, and do not treat it as a replacement for TLS.
|
|
86
|
+
|
|
87
|
+
#### HTTPS with Caddy
|
|
88
|
+
|
|
89
|
+
When Caddy runs on the same machine, leave the MCP server bound to its default `127.0.0.1` address and let Caddy handle public HTTPS:
|
|
90
|
+
|
|
91
|
+
```caddyfile
|
|
92
|
+
mcp.example.com {
|
|
93
|
+
reverse_proxy 127.0.0.1:8000
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Start the MCP server with authentication enabled:
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
okf serve-mcp my-bundle --token "$OKF_MCP_TOKEN"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
Clients connect to `https://mcp.example.com/mcp` and send `Authorization: Bearer <token>`. Keep port `8000` private; Caddy should be the public entry point. Caddy can provision HTTPS automatically when the domain points to the server and is reachable on the required ports.
|
|
104
|
+
|
|
105
|
+
## Python library
|
|
106
|
+
|
|
107
|
+
`src/okf/api.py` is usable directly as a library:
|
|
108
|
+
|
|
109
|
+
```python
|
|
110
|
+
from okf.api import Bundle, bundle, reindex, validate, write_concept
|
|
111
|
+
|
|
112
|
+
result = bundle("example", "out", default_type="reference", force=True)
|
|
113
|
+
assert validate("out").ok
|
|
114
|
+
|
|
115
|
+
# Programs that generate concepts themselves keep every frontmatter key as given.
|
|
116
|
+
write_concept(
|
|
117
|
+
"out", "tables/invoices", {"type": "tables", "title": "Invoices"}, "Body."
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
# Rebuild index.md files after concepts were added or removed directly.
|
|
121
|
+
reindex("out") # also: `okf reindex out`; stale indexes are emptied, never deleted
|
|
122
|
+
|
|
123
|
+
# Repeated reads: load once, then search and read from memory.
|
|
124
|
+
kb = Bundle.open("out")
|
|
125
|
+
kb.search("customer", type_="tables")
|
|
126
|
+
kb.read("tables/customers", section="Schema").body
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Documentation
|
|
130
|
+
|
|
131
|
+
- OKF v0.2 specification: [SPEC/OKF_SPEC_V0_2.md](SPEC/OKF_SPEC_V0_2.md)
|
|
132
|
+
- Development and contributor docs: [wiki/quickstart.md](wiki/quickstart.md) and [AGENTS.md](AGENTS.md)
|
|
@@ -117,6 +117,30 @@ Example:
|
|
|
117
117
|
okf read my-docs_knowledge_base tables/orders
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
### `okf reindex`
|
|
121
|
+
|
|
122
|
+
Rebuild every `index.md` in a conformant bundle from the concept files on disk.
|
|
123
|
+
Use it after concepts were added, changed or removed directly (by hand or by a
|
|
124
|
+
program using `okf.api.write_concept`) instead of through `okf bundle`.
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
okf reindex <directory>
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Existing `index.md` files are rewritten from scratch; an index left with no
|
|
131
|
+
concepts is emptied (never deleted) and reported as a warning. The bundle-root
|
|
132
|
+
`okf_version` is kept.
|
|
133
|
+
|
|
134
|
+
### `okf serve-mcp`
|
|
135
|
+
|
|
136
|
+
Serve a conformant bundle to MCP clients over Streamable HTTP (needs the `mcp`
|
|
137
|
+
extra). Tools: `search`, `browse`, `read_concept` (optionally one section),
|
|
138
|
+
`list_concepts`. Files changed on disk are picked up on the next call.
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
okf serve-mcp <directory> [--host 127.0.0.1] [--port 8000] [--token <secret>]
|
|
142
|
+
```
|
|
143
|
+
|
|
120
144
|
## Plain markdown input format
|
|
121
145
|
|
|
122
146
|
Best-quality input uses strict shape:
|