@dikolab/kbdb 0.1.5 → 0.2.0

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.
Files changed (193) hide show
  1. package/README.md +30 -9
  2. package/dist/cli.cjs +181 -50
  3. package/dist/cli.cjs.map +3 -3
  4. package/dist/cli.mjs +181 -50
  5. package/dist/cli.mjs.map +3 -3
  6. package/dist/kbdb-worker.cjs +283 -29
  7. package/dist/kbdb-worker.cjs.map +4 -4
  8. package/dist/mod.cjs +13 -2
  9. package/dist/mod.cjs.map +2 -2
  10. package/dist/mod.mjs +13 -2
  11. package/dist/mod.mjs.map +2 -2
  12. package/dist/src/shared/cli/functions/format-output.function.d.ts +7 -7
  13. package/dist/src/shared/cli/functions/run-search.function.d.ts +25 -16
  14. package/dist/src/shared/cli/index.d.ts +1 -1
  15. package/dist/src/shared/cli/typings/cli-options.interface.d.ts +2 -0
  16. package/dist/src/shared/cli/typings/search-display.model.d.ts +25 -7
  17. package/dist/src/shared/mcp/functions/handle-recall.function.d.ts +29 -0
  18. package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +30 -11
  19. package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
  20. package/dist/src/shared/wasm-codec/functions/decode-recall-result.function.d.ts +28 -0
  21. package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +14 -7
  22. package/dist/src/shared/wasm-codec/functions/encode-recall-params.function.d.ts +21 -0
  23. package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -1
  24. package/dist/src/shared/wasm-codec/index.d.ts +5 -2
  25. package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +13 -3
  26. package/dist/src/shared/worker-client/index.d.ts +2 -1
  27. package/dist/src/shared/worker-client/typings/recall-result.model.d.ts +94 -0
  28. package/dist/src/shared/worker-client/typings/search-params.model.d.ts +2 -0
  29. package/dist/src/shared/worker-client/typings/search-result.model.d.ts +23 -7
  30. package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +1 -0
  31. package/dist/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
  32. package/dist/wasm/fs-database/kbdb_fs_database.js +30 -0
  33. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  34. package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
  35. package/dist/wasm/kb-worker/kbdb_worker.d.ts +38 -0
  36. package/dist/wasm/kb-worker/kbdb_worker.js +56 -0
  37. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  38. package/dist/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
  39. package/dist/worker.mjs +283 -29
  40. package/dist/worker.mjs.map +4 -4
  41. package/docs/details/README.md +26 -0
  42. package/docs/details/cli.md +608 -0
  43. package/docs/details/library-api.md +406 -0
  44. package/docs/details/mcp-server.md +430 -0
  45. package/docs/details/search-and-ranking.md +457 -0
  46. package/docs/details/storage.md +529 -0
  47. package/docs/goals/agents.md +751 -0
  48. package/docs/goals/architecture.svg +198 -0
  49. package/docs/goals/cli.md +2308 -0
  50. package/docs/goals/content-composer.md +609 -0
  51. package/docs/goals/content-parser.md +279 -0
  52. package/docs/goals/database.md +1452 -0
  53. package/docs/goals/document.md +368 -0
  54. package/docs/goals/mcp.md +1467 -0
  55. package/docs/goals/overview.md +124 -0
  56. package/docs/goals/query-parser.md +271 -0
  57. package/docs/goals/query-result.md +693 -0
  58. package/docs/goals/skills.md +738 -0
  59. package/docs/goals/worker-client.md +944 -0
  60. package/docs/goals/worker-daemon.md +1447 -0
  61. package/docs/modules/overview.md +298 -0
  62. package/docs/modules/rust/fs-database/functions/document.md +48 -0
  63. package/docs/modules/rust/fs-database/functions/integrity.md +68 -0
  64. package/docs/modules/rust/fs-database/functions/io.md +87 -0
  65. package/docs/modules/rust/fs-database/functions/module.md +22 -0
  66. package/docs/modules/rust/fs-database/functions/query-exec.md +44 -0
  67. package/docs/modules/rust/fs-database/functions/section.md +59 -0
  68. package/docs/modules/rust/fs-database/indexes/btree.md +35 -0
  69. package/docs/modules/rust/fs-database/indexes/corpus.md +61 -0
  70. package/docs/modules/rust/fs-database/indexes/inverted.md +60 -0
  71. package/docs/modules/rust/fs-database/indexes/module.md +64 -0
  72. package/docs/modules/rust/fs-database/indexes/positional.md +39 -0
  73. package/docs/modules/rust/fs-database/module.md +149 -0
  74. package/docs/modules/rust/fs-database/types/catalog.md +53 -0
  75. package/docs/modules/rust/fs-database/types/module.md +12 -0
  76. package/docs/modules/rust/fs-database/types/section.md +101 -0
  77. package/docs/modules/rust/kb-worker/functions/compose.md +57 -0
  78. package/docs/modules/rust/kb-worker/functions/module.md +20 -0
  79. package/docs/modules/rust/kb-worker/functions/retrieve.md +194 -0
  80. package/docs/modules/rust/kb-worker/functions/search.md +173 -0
  81. package/docs/modules/rust/kb-worker/functions/write.md +172 -0
  82. package/docs/modules/rust/kb-worker/module.md +171 -0
  83. package/docs/modules/rust/kb-worker/types/cache.md +90 -0
  84. package/docs/modules/rust/kb-worker/types/context.md +26 -0
  85. package/docs/modules/rust/kb-worker/types/module.md +16 -0
  86. package/docs/modules/rust/kb-worker/types/status.md +29 -0
  87. package/docs/modules/rust/kb-worker/types/token.md +50 -0
  88. package/docs/modules/rust/overview.md +495 -0
  89. package/docs/modules/rust/query-parser/functions/extract.md +56 -0
  90. package/docs/modules/rust/query-parser/functions/module.md +16 -0
  91. package/docs/modules/rust/query-parser/functions/parse.md +33 -0
  92. package/docs/modules/rust/query-parser/functions/pipeline.md +103 -0
  93. package/docs/modules/rust/query-parser/functions/rank.md +85 -0
  94. package/docs/modules/rust/query-parser/module.md +136 -0
  95. package/docs/modules/rust/query-parser/types/cache.md +39 -0
  96. package/docs/modules/rust/query-parser/types/keyphrase.md +60 -0
  97. package/docs/modules/rust/query-parser/types/module.md +17 -0
  98. package/docs/modules/rust/query-parser/types/token.md +42 -0
  99. package/docs/modules/rust/shared/content-composer/functions.md +114 -0
  100. package/docs/modules/rust/shared/content-composer/module.md +147 -0
  101. package/docs/modules/rust/shared/content-composer/types.md +93 -0
  102. package/docs/modules/rust/shared/content-parser/functions.md +72 -0
  103. package/docs/modules/rust/shared/content-parser/module.md +99 -0
  104. package/docs/modules/rust/shared/content-parser/types.md +71 -0
  105. package/docs/modules/rust/shared/corpus/module.md +24 -0
  106. package/docs/modules/rust/shared/corpus/types.md +141 -0
  107. package/docs/modules/rust/shared/document/module.md +25 -0
  108. package/docs/modules/rust/shared/document/types.md +154 -0
  109. package/docs/modules/rust/shared/encode/module.md +22 -0
  110. package/docs/modules/rust/shared/encode/traits.md +304 -0
  111. package/docs/modules/rust/shared/error/module.md +28 -0
  112. package/docs/modules/rust/shared/error/types.md +302 -0
  113. package/docs/modules/rust/shared/kbid/module.md +24 -0
  114. package/docs/modules/rust/shared/kbid/types.md +147 -0
  115. package/docs/modules/rust/shared/memory/functions.md +209 -0
  116. package/docs/modules/rust/shared/memory/module.md +24 -0
  117. package/docs/modules/rust/shared/module.md +168 -0
  118. package/docs/modules/rust/shared/query/module.md +27 -0
  119. package/docs/modules/rust/shared/query/types.md +236 -0
  120. package/docs/modules/rust/shared/section/module.md +25 -0
  121. package/docs/modules/rust/shared/section/types.md +294 -0
  122. package/docs/modules/rust/shared/term/module.md +25 -0
  123. package/docs/modules/rust/shared/term/types.md +139 -0
  124. package/docs/modules/typescript/cli.md +129 -0
  125. package/docs/modules/typescript/kbdb-worker.md +135 -0
  126. package/docs/modules/typescript/overview.md +378 -0
  127. package/docs/modules/typescript/shared/cli/constants.md +23 -0
  128. package/docs/modules/typescript/shared/cli/functions.md +630 -0
  129. package/docs/modules/typescript/shared/cli/module.md +125 -0
  130. package/docs/modules/typescript/shared/cli/typings.md +172 -0
  131. package/docs/modules/typescript/shared/hash/functions.md +20 -0
  132. package/docs/modules/typescript/shared/hash/module.md +21 -0
  133. package/docs/modules/typescript/shared/mcp/classes.md +179 -0
  134. package/docs/modules/typescript/shared/mcp/functions.md +386 -0
  135. package/docs/modules/typescript/shared/mcp/module.md +160 -0
  136. package/docs/modules/typescript/shared/mcp/typings.md +522 -0
  137. package/docs/modules/typescript/shared/module.md +94 -0
  138. package/docs/modules/typescript/shared/platform/functions.md +42 -0
  139. package/docs/modules/typescript/shared/platform/module.md +25 -0
  140. package/docs/modules/typescript/shared/runtime/functions.md +26 -0
  141. package/docs/modules/typescript/shared/runtime/module.md +27 -0
  142. package/docs/modules/typescript/shared/runtime/typings.md +13 -0
  143. package/docs/modules/typescript/shared/version/module.md +27 -0
  144. package/docs/modules/typescript/shared/wasm-codec/functions.md +391 -0
  145. package/docs/modules/typescript/shared/wasm-codec/module.md +98 -0
  146. package/docs/modules/typescript/shared/worker-client/classes.md +264 -0
  147. package/docs/modules/typescript/shared/worker-client/functions.md +175 -0
  148. package/docs/modules/typescript/shared/worker-client/module.md +84 -0
  149. package/docs/modules/typescript/shared/worker-client/typings.md +508 -0
  150. package/docs/modules/typescript/shared/worker-daemon/classes.md +239 -0
  151. package/docs/modules/typescript/shared/worker-daemon/constants.md +37 -0
  152. package/docs/modules/typescript/shared/worker-daemon/functions.md +221 -0
  153. package/docs/modules/typescript/shared/worker-daemon/module.md +112 -0
  154. package/docs/modules/typescript/shared/worker-daemon/typings.md +126 -0
  155. package/docs/overview.md +188 -0
  156. package/docs/release-notes/0.1.0.md +189 -0
  157. package/docs/release-notes/0.1.1.md +46 -0
  158. package/docs/release-notes/0.1.2.md +38 -0
  159. package/docs/release-notes/0.1.3.md +42 -0
  160. package/docs/release-notes/0.2.0.md +147 -0
  161. package/docs/release-notes/README.md +9 -0
  162. package/package.json +8 -2
  163. package/src/shared/cli/functions/dispatch-command.function.ts +3 -3
  164. package/src/shared/cli/functions/format-output.function.ts +41 -34
  165. package/src/shared/cli/functions/parse-args.function.ts +7 -0
  166. package/src/shared/cli/functions/run-search.function.ts +53 -27
  167. package/src/shared/cli/index.ts +4 -1
  168. package/src/shared/cli/typings/cli-options.interface.ts +2 -0
  169. package/src/shared/cli/typings/search-display.model.ts +26 -7
  170. package/src/shared/mcp/functions/create-tool-definitions.function.ts +64 -4
  171. package/src/shared/mcp/functions/handle-recall.function.ts +66 -0
  172. package/src/shared/mcp/functions/handle-tool-call.function.ts +11 -1
  173. package/src/shared/mcp/typings/mcp-client.interface.ts +33 -15
  174. package/src/shared/version/constants/version.constant.ts +1 -1
  175. package/src/shared/wasm-codec/functions/decode-recall-result.function.ts +267 -0
  176. package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +81 -27
  177. package/src/shared/wasm-codec/functions/encode-recall-params.function.ts +68 -0
  178. package/src/shared/wasm-codec/functions/encode-search-params.function.ts +4 -1
  179. package/src/shared/wasm-codec/index.ts +11 -3
  180. package/src/shared/worker-client/classes/worker-client.class.ts +24 -4
  181. package/src/shared/worker-client/index.ts +11 -1
  182. package/src/shared/worker-client/typings/recall-result.model.ts +98 -0
  183. package/src/shared/worker-client/typings/search-params.model.ts +2 -0
  184. package/src/shared/worker-client/typings/search-result.model.ts +24 -7
  185. package/src/shared/worker-daemon/classes/worker-daemon.class.ts +25 -4
  186. package/src/wasm/fs-database/kbdb_fs_database.d.ts +18 -0
  187. package/src/wasm/fs-database/kbdb_fs_database.js +30 -0
  188. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
  189. package/src/wasm/fs-database/kbdb_fs_database_bg.wasm.d.ts +2 -0
  190. package/src/wasm/kb-worker/kbdb_worker.d.ts +38 -0
  191. package/src/wasm/kb-worker/kbdb_worker.js +56 -0
  192. package/src/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
  193. package/src/wasm/kb-worker/kbdb_worker_bg.wasm.d.ts +3 -0
@@ -0,0 +1,430 @@
1
+ # MCP Server Guide
2
+
3
+ The `kbdb mcp` command starts a long-lived MCP
4
+ server that exposes the knowledge base to AI
5
+ agents over stdio using JSON-RPC 2.0.
6
+
7
+ ## Setup
8
+
9
+ Configure kbdb as an MCP server for your AI agent
10
+ platform. The server requires a database path via
11
+ `--db` or the `KBDB_DIR` environment variable.
12
+
13
+ ### Claude Code (CLI)
14
+
15
+ Create `.mcp.json` in the project root:
16
+
17
+ ```json
18
+ {
19
+ "mcpServers": {
20
+ "kbdb": {
21
+ "command": "npx",
22
+ "args": [
23
+ "-y", "@dikolab/kbdb", "mcp",
24
+ "--db", "/path/to/.kbdb"
25
+ ]
26
+ }
27
+ }
28
+ }
29
+ ```
30
+
31
+ Deno variant:
32
+
33
+ ```json
34
+ {
35
+ "mcpServers": {
36
+ "kbdb": {
37
+ "command": "deno",
38
+ "args": [
39
+ "run", "-A",
40
+ "jsr:@dikolab/kbdb/cli", "mcp",
41
+ "--db", "/path/to/.kbdb"
42
+ ]
43
+ }
44
+ }
45
+ }
46
+ ```
47
+
48
+ ### Claude for VS Code
49
+
50
+ Create `.vscode/mcp.json`:
51
+
52
+ ```json
53
+ {
54
+ "servers": {
55
+ "kbdb": {
56
+ "command": "npx",
57
+ "args": [
58
+ "-y", "@dikolab/kbdb", "mcp",
59
+ "--db", "/path/to/.kbdb"
60
+ ]
61
+ }
62
+ }
63
+ }
64
+ ```
65
+
66
+ Deno variant:
67
+
68
+ ```json
69
+ {
70
+ "servers": {
71
+ "kbdb": {
72
+ "command": "deno",
73
+ "args": [
74
+ "run", "-A",
75
+ "jsr:@dikolab/kbdb/cli", "mcp",
76
+ "--db", "/path/to/.kbdb"
77
+ ]
78
+ }
79
+ }
80
+ }
81
+ ```
82
+
83
+ ### Claude Desktop
84
+
85
+ Add to `claude_desktop_config.json`:
86
+
87
+ ```json
88
+ {
89
+ "mcpServers": {
90
+ "kbdb": {
91
+ "command": "npx",
92
+ "args": [
93
+ "-y", "@dikolab/kbdb", "mcp",
94
+ "--db", "/path/to/.kbdb"
95
+ ]
96
+ }
97
+ }
98
+ }
99
+ ```
100
+
101
+ Deno variant:
102
+
103
+ ```json
104
+ {
105
+ "mcpServers": {
106
+ "kbdb": {
107
+ "command": "deno",
108
+ "args": [
109
+ "run", "-A",
110
+ "jsr:@dikolab/kbdb/cli", "mcp",
111
+ "--db", "/path/to/.kbdb"
112
+ ]
113
+ }
114
+ }
115
+ }
116
+ ```
117
+
118
+ ### Other AI Agents
119
+
120
+ Any MCP-compatible agent can connect via stdio
121
+ transport. Run the server directly:
122
+
123
+ ```sh
124
+ npx @dikolab/kbdb mcp --db /path/to/.kbdb
125
+ ```
126
+
127
+ Or with Deno:
128
+
129
+ ```sh
130
+ deno run -A jsr:@dikolab/kbdb/cli mcp \
131
+ --db /path/to/.kbdb
132
+ ```
133
+
134
+ ### Using `KBDB_DIR` Environment Variable
135
+
136
+ The `--db` flag can be replaced by the `KBDB_DIR`
137
+ environment variable in any configuration:
138
+
139
+ ```json
140
+ {
141
+ "mcpServers": {
142
+ "kbdb": {
143
+ "command": "npx",
144
+ "args": ["-y", "@dikolab/kbdb", "mcp"],
145
+ "env": {
146
+ "KBDB_DIR": "/path/to/.kbdb"
147
+ }
148
+ }
149
+ }
150
+ }
151
+ ```
152
+
153
+ Resolution order: `--db` flag, then `KBDB_DIR`
154
+ env var. If neither is set, the server exits with
155
+ an error. The server does not fall back to the
156
+ current working directory because the server's cwd
157
+ is determined by the host application, not the
158
+ user.
159
+
160
+ ### Multiple Knowledge Bases
161
+
162
+ Register multiple server instances pointing to
163
+ different databases:
164
+
165
+ ```json
166
+ {
167
+ "mcpServers": {
168
+ "kbdb-docs": {
169
+ "command": "npx",
170
+ "args": [
171
+ "-y", "@dikolab/kbdb", "mcp",
172
+ "--db", "/home/user/docs/.kbdb"
173
+ ]
174
+ },
175
+ "kbdb-project": {
176
+ "command": "npx",
177
+ "args": [
178
+ "-y", "@dikolab/kbdb", "mcp",
179
+ "--db", "/home/user/project/.kbdb"
180
+ ]
181
+ }
182
+ }
183
+ }
184
+ ```
185
+
186
+ Each instance runs as a separate process with its
187
+ own worker client connection.
188
+
189
+ ## Tools Reference
190
+
191
+ The MCP server exposes 17 tools grouped by
192
+ function. All tools communicate with the worker
193
+ daemon via JSON-RPC 2.0 over IPC.
194
+
195
+ ### Knowledge Base Tools
196
+
197
+ | Tool | Parameters | Description | Read-only | Destructive |
198
+ |------|-----------|-------------|-----------|-------------|
199
+ | `search` | `query` (string, required), `mode` (string), `limit` (number) | Query the knowledge base by keywords. Returns ranked results with kbid, score, and matched terms. | yes | no |
200
+ | `learn` | `content` (string, required), `type` (string), `title` (string), `description` (string), `docid` (string) | Import content into the knowledge base. Extracts keywords and builds indexes. | no | no |
201
+ | `unlearn` | `kbid` (string, required) | Remove a section by kb-id. Cascades deletion to index entries and ranking data. | no | yes |
202
+ | `retrieve` | `kbid` (string), `docid` (string) | Fetch a specific section or document by identifier. At least one of `kbid` or `docid` required. | yes | no |
203
+ | `content` | `ids` (string[], required) | Compose a rendered Markdown document from one or more kbid or docid identifiers. | yes | no |
204
+ | `status` | (none) | Return database status and cache statistics. | yes | no |
205
+ | `check` | (none) | Verify knowledge base integrity. Reports checksum mismatches, orphan sections, broken references. | yes | no |
206
+ | `gc` | (none) | Remove unreferenced sections (no document manifest references). | no | yes |
207
+ | `rebuild` | (none) | Reconstruct all index files from section files and document manifests on disk. | no | no |
208
+
209
+ ### Skills Tools
210
+
211
+ | Tool | Parameters | Description | Read-only | Destructive |
212
+ |------|-----------|-------------|-----------|-------------|
213
+ | `skill-learn` | `name` (string, required), `description` (string, required), `body` (string, required), `arguments` (array) | Create a new skill definition. Body supports `{{argName}}` template placeholders. | no | no |
214
+ | `skill-list` | (none) | List all skill definitions. Returns array of summaries with kbid, name, description, argumentCount. | yes | no |
215
+ | `skill-get` | `name` (string), `kbid` (string) | Retrieve a single skill by name or kb-id. At least one required; `kbid` takes precedence. | yes | no |
216
+ | `skill-delete` | `kbid` (string, required) | Remove a skill by kb-id. Agent documents referencing this skill will have dangling references. | no | yes |
217
+
218
+ ### Agents Tools
219
+
220
+ | Tool | Parameters | Description | Read-only | Destructive |
221
+ |------|-----------|-------------|-----------|-------------|
222
+ | `agent-create` | `name` (string, required), `description` (string, required), `persona` (string, required), `skills` (string[], required) | Create an agent document with a persona and ordered skill references. | no | no |
223
+ | `agent-list` | (none) | List all agent documents. Returns array of summaries with docid, name, description, skillCount. | yes | no |
224
+ | `agent-get` | `docid` (string, required) | Retrieve an agent with resolved skill definitions. Deleted skills appear with `name: null`. | yes | no |
225
+ | `agent-delete` | `docid` (string, required) | Remove an agent document. Referenced skill sections are preserved. | no | yes |
226
+
227
+ ### Tool Annotations Summary
228
+
229
+ | Tool | Idempotent |
230
+ |------|------------|
231
+ | `search` | yes |
232
+ | `learn` | yes |
233
+ | `unlearn` | yes |
234
+ | `retrieve` | yes |
235
+ | `content` | yes |
236
+ | `status` | yes |
237
+ | `check` | yes |
238
+ | `gc` | no |
239
+ | `rebuild` | no |
240
+ | `skill-learn` | yes |
241
+ | `skill-list` | yes |
242
+ | `skill-get` | yes |
243
+ | `skill-delete` | yes |
244
+ | `agent-create` | yes |
245
+ | `agent-list` | yes |
246
+ | `agent-get` | yes |
247
+ | `agent-delete` | yes |
248
+
249
+ ## Prompts
250
+
251
+ The MCP server exposes knowledge base content as
252
+ discoverable prompts via `prompts/list` and
253
+ `prompts/get`.
254
+
255
+ ### Skills as Prompts
256
+
257
+ Each skill stored in the database appears as an
258
+ MCP prompt. The skill's `{{argName}}` template
259
+ placeholders become prompt arguments. When an
260
+ agent calls `prompts/get` with argument values,
261
+ the server renders the template with substitutions
262
+ and returns it as a user message.
263
+
264
+ ```json
265
+ {
266
+ "name": "summarize-document",
267
+ "description": "Summarize a document into key points",
268
+ "arguments": [
269
+ {
270
+ "name": "docid",
271
+ "description": "Document identifier",
272
+ "required": true
273
+ },
274
+ {
275
+ "name": "max_points",
276
+ "description": "Max bullet points",
277
+ "required": false
278
+ }
279
+ ]
280
+ }
281
+ ```
282
+
283
+ ### Agents as Prompts
284
+
285
+ Each agent appears as a prompt with an `agent:`
286
+ name prefix. Agent prompts have no arguments.
287
+ When rendered, they produce two messages:
288
+
289
+ 1. An assistant message containing the agent's
290
+ persona text.
291
+ 2. A user message listing the agent's available
292
+ skills.
293
+
294
+ ```json
295
+ {
296
+ "name": "agent:code-reviewer",
297
+ "description": "Reviews code for bugs, style, and best practices",
298
+ "arguments": []
299
+ }
300
+ ```
301
+
302
+ ## Resources
303
+
304
+ Resources provide direct access to knowledge base
305
+ contents by URI, without going through search.
306
+
307
+ ### URI Templates
308
+
309
+ The server exposes parameterised URI templates
310
+ via `resources/templates/list`:
311
+
312
+ | URI Template | MIME Type | Description |
313
+ |-------------|----------|-------------|
314
+ | `kbdb://section/{kbid}` | `text/plain` | Raw content of a single section by kb-id. For image sections, returns base64-encoded content with the image MIME type. |
315
+ | `kbdb://document/{docid}` | `application/json` | Document manifest and all sections, ordered by position. |
316
+
317
+ ### Static Resources
318
+
319
+ The `resources/list` endpoint returns an empty
320
+ list. All resources are accessed through URI
321
+ templates.
322
+
323
+ ### Reading Resources
324
+
325
+ Use `resources/read` with an expanded URI:
326
+
327
+ - `kbdb://section/abcdef1234567890abcdef1234` --
328
+ returns the section content.
329
+ - `kbdb://document/agent-code-reviewer` --
330
+ returns the document with all sections.
331
+
332
+ ## Protocol Features
333
+
334
+ The kbdb MCP server implements Model Context
335
+ Protocol version **2025-11-25** and advertises the
336
+ following capabilities:
337
+
338
+ - **tools** -- `tools/list` and `tools/call` for
339
+ all 17 tools.
340
+ - **resources** -- `resources/list`,
341
+ `resources/read`, and
342
+ `resources/templates/list` for URI-based content
343
+ access.
344
+ - **prompts** -- `prompts/list` and `prompts/get`
345
+ for skill and agent prompt discovery.
346
+ - **completions** -- `completion/complete` for
347
+ autocomplete on prompt names and resource URIs.
348
+ - **logging** -- `logging/setLevel` to control
349
+ server-to-client log notification verbosity.
350
+ Levels: `debug`, `info`, `notice`, `warning`,
351
+ `error`, `critical`, `alert`, `emergency`.
352
+ - **roots** -- `roots/list` returns the `.kbdb`
353
+ database directory as the single filesystem root.
354
+ - **subscriptions** -- `resources/subscribe` and
355
+ `resources/unsubscribe` for change notifications
356
+ on individual resources.
357
+ - **sampling** -- `sampling/createMessage` allows
358
+ the server to request text generation from the
359
+ host's language model.
360
+
361
+ ## Error Handling
362
+
363
+ ### Protocol Errors
364
+
365
+ Standard JSON-RPC 2.0 error codes for protocol
366
+ violations:
367
+
368
+ | Code | Meaning |
369
+ |------|---------|
370
+ | `-32700` | Parse error (malformed JSON) |
371
+ | `-32601` | Method not found |
372
+ | `-32602` | Invalid params |
373
+ | `-32603` | Internal error |
374
+ | `-32002` | Resource not found (MCP-specific) |
375
+
376
+ ### Tool Execution Errors
377
+
378
+ Tool-level failures are returned as successful
379
+ JSON-RPC responses with `isError: true` in the
380
+ result:
381
+
382
+ ```json
383
+ {
384
+ "content": [
385
+ {
386
+ "type": "text",
387
+ "text": "Section not found: abc123"
388
+ }
389
+ ],
390
+ "isError": true
391
+ }
392
+ ```
393
+
394
+ Successful tool results are wrapped as:
395
+
396
+ ```json
397
+ {
398
+ "content": [
399
+ {
400
+ "type": "text",
401
+ "text": "<JSON result>"
402
+ }
403
+ ]
404
+ }
405
+ ```
406
+
407
+ ## Transport
408
+
409
+ The MCP server uses stdio transport:
410
+
411
+ - Reads JSON-RPC 2.0 requests from **stdin**.
412
+ - Writes JSON-RPC 2.0 responses to **stdout**.
413
+ - Diagnostic messages go to **stderr**.
414
+
415
+ The host application spawns `kbdb mcp` as a child
416
+ process and communicates over its stdin/stdout
417
+ streams. Each JSON-RPC message is serialised as a
418
+ single line of JSON terminated by `\n`.
419
+
420
+ ## Lifecycle
421
+
422
+ 1. Host sends `initialize` with its capabilities.
423
+ Server responds with its identity and supported
424
+ capability groups.
425
+ 2. Host sends `notifications/initialized` to
426
+ confirm the handshake. Server begins accepting
427
+ tool and resource requests.
428
+ 3. Either party can send `ping` to check liveness.
429
+ 4. When the host closes stdin, the server
430
+ disconnects from the worker daemon and exits.