@dikolab/kbdb 0.4.3 → 0.6.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.
- package/CLA.md +68 -0
- package/LICENSE +676 -12
- package/LICENSING.md +58 -0
- package/README.md +50 -27
- package/README.md.bak +320 -0
- package/dist/README.md +320 -0
- package/dist/{chunk-BJXEVALU.mjs → chunk-QLJ33C74.mjs} +44 -44
- package/dist/chunk-QLJ33C74.mjs.map +7 -0
- package/dist/cli.cjs +550 -232
- package/dist/cli.cjs.map +4 -4
- package/dist/cli.d.ts +0 -8
- package/dist/cli.mjs +483 -154
- package/dist/cli.mjs.map +4 -4
- package/dist/kbdb-worker.cjs +36 -5
- package/dist/kbdb-worker.cjs.map +3 -3
- package/dist/mod.cjs +89 -30
- package/dist/mod.cjs.map +4 -4
- package/dist/mod.mjs +88 -30
- package/dist/mod.mjs.map +4 -4
- package/dist/src/cli.d.ts +0 -8
- package/dist/src/shared/cli/constants/defaults.constant.d.ts +1 -1
- package/dist/src/shared/cli/constants/recfile-command-field-map.constant.d.ts +8 -0
- package/dist/src/shared/cli/constants/recfile-field-maps.constant.d.ts +21 -0
- package/dist/src/shared/cli/functions/compute-directory-level.function.d.ts +14 -0
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +2 -28
- package/dist/src/shared/cli/functions/format-command-output.function.d.ts +14 -0
- package/dist/src/shared/cli/functions/format-db-not-found.function.d.ts +20 -0
- package/dist/src/shared/cli/functions/format-output.function.d.ts +1 -0
- package/dist/src/shared/cli/functions/format-recfile-output.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/render-recfile-value.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/resolve-db-dir.function.d.ts +24 -0
- package/dist/src/shared/cli/functions/resolve-recfile-key.function.d.ts +9 -0
- package/dist/src/shared/cli/functions/run-db-path.function.d.ts +10 -0
- package/dist/src/shared/cli/functions/run-export.function.d.ts +8 -4
- package/dist/src/shared/cli/functions/run-import.function.d.ts +4 -0
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +12 -0
- package/dist/src/shared/cli/index.d.ts +4 -1
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +9 -2
- package/dist/src/shared/cli/typings/db-resolution.interface.d.ts +9 -0
- package/dist/src/shared/cli/typings/recfile-field-map.type.d.ts +10 -0
- package/dist/src/shared/version/constants/version.constant.d.ts +1 -1
- package/dist/src/shared/wasm-codec/functions/decode-option-u8.function.d.ts +9 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +4 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +2 -45
- package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +10 -1
- package/dist/src/shared/wasm-codec/index.d.ts +1 -1
- package/dist/src/shared/wasm-codec/typings/add-section-input.model.d.ts +6 -0
- package/dist/src/shared/wasm-codec/typings/section-record-trailing.model.d.ts +5 -0
- package/dist/src/shared/wasm-codec/typings/section-record.model.d.ts +5 -0
- package/dist/src/shared/worker-client/functions/build-deno-permissions.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/read-crash-reason.function.d.ts +9 -0
- package/dist/src/shared/worker-client/functions/resolve-spawn-script.function.d.ts +6 -0
- package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +1 -1
- package/dist/src/shared/worker-client/typings/section.model.d.ts +5 -0
- package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +0 -6
- package/dist/src/shared/worker-daemon/functions/count-files.function.d.ts +12 -0
- package/dist/src/shared/worker-daemon/functions/handle-import.function.d.ts +2 -0
- package/dist/src/shared/worker-daemon/functions/handle-read-ops.function.d.ts +8 -0
- package/dist/src/shared/worker-daemon/functions/validate-daemon-path.function.d.ts +15 -0
- package/dist/src/worker.d.ts +0 -7
- package/dist/wasm/default-embedding/kbdb_default_embedding_bg.wasm +0 -0
- package/dist/wasm/default-embedding/package.json +1 -1
- package/dist/wasm/fs-database/kbdb_fs_database_bg.wasm +0 -0
- package/dist/wasm/fs-database/package.json +1 -1
- package/dist/wasm/fs-migration/kbdb_fs_migration_bg.wasm +0 -0
- package/dist/wasm/fs-migration/package.json +1 -1
- package/dist/wasm/kb-worker/kbdb_worker_bg.wasm +0 -0
- package/dist/wasm/kb-worker/package.json +1 -1
- package/dist/wasm/query-parser/kbdb_query_parser_bg.wasm +0 -0
- package/dist/wasm/query-parser/package.json +1 -1
- package/dist/worker.d.ts +0 -7
- package/dist/worker.mjs +37 -6
- package/dist/worker.mjs.map +3 -3
- package/package.json +13 -12
- package/dist/chunk-BJXEVALU.mjs.map +0 -7
- package/dist/src/shared/cli/functions/resolve-raw-db-path.function.d.ts +0 -10
- package/docs/details/README.md +0 -30
- package/docs/details/agent-tooling.md +0 -132
- package/docs/details/cli.md +0 -777
- package/docs/details/knowledge-base.md +0 -180
- package/docs/details/library-api.md +0 -495
- package/docs/details/mcp-server.md +0 -482
- package/docs/details/search-and-ranking.md +0 -575
- package/docs/details/storage.md +0 -531
- package/docs/goals/agents.md +0 -751
- package/docs/goals/architecture.svg +0 -198
- package/docs/goals/auto-capture.md +0 -378
- package/docs/goals/benchmarking.md +0 -296
- package/docs/goals/cli.md +0 -2654
- package/docs/goals/concurrency.md +0 -259
- package/docs/goals/content-composer.md +0 -609
- package/docs/goals/content-parser.md +0 -279
- package/docs/goals/database.md +0 -1679
- package/docs/goals/document.md +0 -368
- package/docs/goals/hybrid-search.md +0 -465
- package/docs/goals/mcp.md +0 -1541
- package/docs/goals/overview.md +0 -124
- package/docs/goals/query-parser.md +0 -373
- package/docs/goals/query-result.md +0 -860
- package/docs/goals/semantic-dedup.md +0 -233
- package/docs/goals/skills.md +0 -810
- package/docs/goals/sync.md +0 -217
- package/docs/goals/worker-client.md +0 -1005
- package/docs/goals/worker-daemon.md +0 -1547
- package/docs/modules/overview.md +0 -319
- package/docs/modules/rust/embedding/module.md +0 -91
- package/docs/modules/rust/fs-database/functions/document.md +0 -48
- package/docs/modules/rust/fs-database/functions/integrity.md +0 -79
- package/docs/modules/rust/fs-database/functions/io.md +0 -87
- package/docs/modules/rust/fs-database/functions/module.md +0 -22
- package/docs/modules/rust/fs-database/functions/query-exec.md +0 -44
- package/docs/modules/rust/fs-database/functions/section.md +0 -76
- package/docs/modules/rust/fs-database/indexes/btree.md +0 -35
- package/docs/modules/rust/fs-database/indexes/corpus.md +0 -61
- package/docs/modules/rust/fs-database/indexes/inverted.md +0 -60
- package/docs/modules/rust/fs-database/indexes/module.md +0 -64
- package/docs/modules/rust/fs-database/indexes/positional.md +0 -39
- package/docs/modules/rust/fs-database/indexes/vectors.md +0 -110
- package/docs/modules/rust/fs-database/module.md +0 -150
- package/docs/modules/rust/fs-database/types/catalog.md +0 -53
- package/docs/modules/rust/fs-database/types/module.md +0 -12
- package/docs/modules/rust/fs-database/types/section.md +0 -127
- package/docs/modules/rust/kb-worker/functions/compose.md +0 -57
- package/docs/modules/rust/kb-worker/functions/module.md +0 -20
- package/docs/modules/rust/kb-worker/functions/retrieve.md +0 -194
- package/docs/modules/rust/kb-worker/functions/search.md +0 -173
- package/docs/modules/rust/kb-worker/functions/write.md +0 -172
- package/docs/modules/rust/kb-worker/module.md +0 -171
- package/docs/modules/rust/kb-worker/types/cache.md +0 -90
- package/docs/modules/rust/kb-worker/types/context.md +0 -26
- package/docs/modules/rust/kb-worker/types/module.md +0 -16
- package/docs/modules/rust/kb-worker/types/status.md +0 -29
- package/docs/modules/rust/kb-worker/types/token.md +0 -50
- package/docs/modules/rust/overview.md +0 -531
- package/docs/modules/rust/query-parser/functions/extract.md +0 -56
- package/docs/modules/rust/query-parser/functions/module.md +0 -18
- package/docs/modules/rust/query-parser/functions/parse.md +0 -33
- package/docs/modules/rust/query-parser/functions/pipeline.md +0 -9
- package/docs/modules/rust/query-parser/functions/rank.md +0 -85
- package/docs/modules/rust/query-parser/module.md +0 -131
- package/docs/modules/rust/query-parser/types/cache.md +0 -39
- package/docs/modules/rust/query-parser/types/keyphrase.md +0 -71
- package/docs/modules/rust/query-parser/types/module.md +0 -18
- package/docs/modules/rust/query-parser/types/token.md +0 -46
- package/docs/modules/rust/shared/content-composer/functions.md +0 -114
- package/docs/modules/rust/shared/content-composer/module.md +0 -147
- package/docs/modules/rust/shared/content-composer/types.md +0 -93
- package/docs/modules/rust/shared/content-parser/functions.md +0 -72
- package/docs/modules/rust/shared/content-parser/module.md +0 -99
- package/docs/modules/rust/shared/content-parser/types.md +0 -71
- package/docs/modules/rust/shared/corpus/module.md +0 -24
- package/docs/modules/rust/shared/corpus/types.md +0 -141
- package/docs/modules/rust/shared/document/module.md +0 -25
- package/docs/modules/rust/shared/document/types.md +0 -154
- package/docs/modules/rust/shared/encode/module.md +0 -22
- package/docs/modules/rust/shared/encode/traits.md +0 -304
- package/docs/modules/rust/shared/error/module.md +0 -28
- package/docs/modules/rust/shared/error/types.md +0 -302
- package/docs/modules/rust/shared/kbid/module.md +0 -24
- package/docs/modules/rust/shared/kbid/types.md +0 -147
- package/docs/modules/rust/shared/memory/functions.md +0 -209
- package/docs/modules/rust/shared/memory/module.md +0 -24
- package/docs/modules/rust/shared/module.md +0 -196
- package/docs/modules/rust/shared/pipeline/functions.md +0 -141
- package/docs/modules/rust/shared/pipeline/module.md +0 -62
- package/docs/modules/rust/shared/pipeline/types.md +0 -43
- package/docs/modules/rust/shared/query/module.md +0 -27
- package/docs/modules/rust/shared/query/types.md +0 -236
- package/docs/modules/rust/shared/section/module.md +0 -25
- package/docs/modules/rust/shared/section/types.md +0 -294
- package/docs/modules/rust/shared/term/module.md +0 -25
- package/docs/modules/rust/shared/term/types.md +0 -139
- package/docs/modules/typescript/cli.md +0 -131
- package/docs/modules/typescript/kbdb-worker.md +0 -150
- package/docs/modules/typescript/overview.md +0 -400
- package/docs/modules/typescript/shared/auto-capture/module.md +0 -73
- package/docs/modules/typescript/shared/cli/constants.md +0 -23
- package/docs/modules/typescript/shared/cli/functions.md +0 -809
- package/docs/modules/typescript/shared/cli/module.md +0 -138
- package/docs/modules/typescript/shared/cli/typings.md +0 -197
- package/docs/modules/typescript/shared/embedding/functions.md +0 -200
- package/docs/modules/typescript/shared/embedding/module.md +0 -77
- package/docs/modules/typescript/shared/embedding/typings.md +0 -124
- package/docs/modules/typescript/shared/hash/functions.md +0 -20
- package/docs/modules/typescript/shared/hash/module.md +0 -21
- package/docs/modules/typescript/shared/log/constants.md +0 -82
- package/docs/modules/typescript/shared/log/functions.md +0 -131
- package/docs/modules/typescript/shared/log/module.md +0 -153
- package/docs/modules/typescript/shared/log/typings.md +0 -82
- package/docs/modules/typescript/shared/mcp/classes.md +0 -179
- package/docs/modules/typescript/shared/mcp/functions.md +0 -386
- package/docs/modules/typescript/shared/mcp/module.md +0 -160
- package/docs/modules/typescript/shared/mcp/typings.md +0 -529
- package/docs/modules/typescript/shared/module.md +0 -110
- package/docs/modules/typescript/shared/platform/functions.md +0 -42
- package/docs/modules/typescript/shared/platform/module.md +0 -25
- package/docs/modules/typescript/shared/runtime/functions.md +0 -26
- package/docs/modules/typescript/shared/runtime/module.md +0 -27
- package/docs/modules/typescript/shared/runtime/typings.md +0 -13
- package/docs/modules/typescript/shared/version/module.md +0 -27
- package/docs/modules/typescript/shared/wasm-codec/functions.md +0 -391
- package/docs/modules/typescript/shared/wasm-codec/module.md +0 -98
- package/docs/modules/typescript/shared/worker-client/classes.md +0 -264
- package/docs/modules/typescript/shared/worker-client/functions.md +0 -175
- package/docs/modules/typescript/shared/worker-client/module.md +0 -92
- package/docs/modules/typescript/shared/worker-client/typings.md +0 -511
- package/docs/modules/typescript/shared/worker-daemon/classes.md +0 -239
- package/docs/modules/typescript/shared/worker-daemon/constants.md +0 -37
- package/docs/modules/typescript/shared/worker-daemon/functions.md +0 -234
- package/docs/modules/typescript/shared/worker-daemon/module.md +0 -118
- package/docs/modules/typescript/shared/worker-daemon/typings.md +0 -132
- package/docs/overview.md +0 -191
- package/docs/release-notes/0.1.0.md +0 -189
- package/docs/release-notes/0.1.1.md +0 -46
- package/docs/release-notes/0.1.2.md +0 -38
- package/docs/release-notes/0.1.3.md +0 -42
- package/docs/release-notes/0.2.0.md +0 -147
- package/docs/release-notes/0.3.0.md +0 -89
- package/docs/release-notes/0.3.1.md +0 -121
- package/docs/release-notes/0.3.2.md +0 -64
- package/docs/release-notes/0.4.0.md +0 -80
- package/docs/release-notes/0.4.1.md +0 -149
- package/docs/release-notes/0.4.3.md +0 -60
- package/docs/release-notes/README.md +0 -13
|
@@ -1,179 +0,0 @@
|
|
|
1
|
-
# mcp/classes -- MCP Server Class
|
|
2
|
-
|
|
3
|
-
*Wraps the MCP protocol layer and routes incoming
|
|
4
|
-
tool calls and resource reads to handler functions.*
|
|
5
|
-
|
|
6
|
-
## Source
|
|
7
|
-
|
|
8
|
-
`src/shared/mcp/classes/`
|
|
9
|
-
|
|
10
|
-
## Classes
|
|
11
|
-
|
|
12
|
-
### `McpServer`
|
|
13
|
-
|
|
14
|
-
**File:** `mcp-server.class.ts`
|
|
15
|
-
|
|
16
|
-
Long-lived MCP server that communicates over stdio.
|
|
17
|
-
Hand-rolled JSON-RPC 2.0 protocol handling over
|
|
18
|
-
stdio using `node:readline`. Implements protocol
|
|
19
|
-
version **2025-11-25**.
|
|
20
|
-
|
|
21
|
-
```ts
|
|
22
|
-
class McpServer {
|
|
23
|
-
constructor(client: McpWorkerClient);
|
|
24
|
-
listen(): Promise<void>;
|
|
25
|
-
handleLineForTest(line: string): Promise<McpResponse | null>;
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
#### Constructor
|
|
30
|
-
|
|
31
|
-
Takes a `McpWorkerClient` instance. Routing happens
|
|
32
|
-
at request dispatch time -- each incoming method
|
|
33
|
-
name is matched to the appropriate handler.
|
|
34
|
-
|
|
35
|
-
**Properties:**
|
|
36
|
-
|
|
37
|
-
| Property | Type | Description |
|
|
38
|
-
|--------------------|-----------------------|------------------------------|
|
|
39
|
-
| `logLevel` | `McpLogLevel \| null` | Current log level; `null` |
|
|
40
|
-
| | | until `logging/setLevel` is |
|
|
41
|
-
| | | received |
|
|
42
|
-
| `subscriptions` | `Set<string>` | Set of URIs the client has |
|
|
43
|
-
| | | subscribed to via |
|
|
44
|
-
| | | `resources/subscribe` |
|
|
45
|
-
| `hostCapabilities` | `object \| null` | Host capabilities received |
|
|
46
|
-
| | | in the `initialize` params; |
|
|
47
|
-
| | | `null` until initialized |
|
|
48
|
-
|
|
49
|
-
**Protocol methods handled:**
|
|
50
|
-
|
|
51
|
-
| Method | Behavior |
|
|
52
|
-
|-------------------------------|----------------------------------|
|
|
53
|
-
| `initialize` | Returns protocol version and capabilities |
|
|
54
|
-
| `ping` | Returns `{}` (liveness check) |
|
|
55
|
-
| `notifications/initialized` | Sets initialized flag |
|
|
56
|
-
| `notifications/cancelled` | Silently ignored |
|
|
57
|
-
| `tools/list` | Returns tool definitions |
|
|
58
|
-
| `tools/call` | Dispatches to `handleToolCall` |
|
|
59
|
-
| `prompts/list` | Returns prompt definitions |
|
|
60
|
-
| `prompts/get` | Renders and returns prompt |
|
|
61
|
-
| `completion/complete` | Returns completion suggestions |
|
|
62
|
-
| `logging/setLevel` | Stores requested log level |
|
|
63
|
-
| `roots/list` | Returns `.kbdb` directory root |
|
|
64
|
-
| `resources/list` | Returns `{ resources: [] }` |
|
|
65
|
-
| `resources/templates/list` | Returns URI templates |
|
|
66
|
-
| `resources/read` | Dispatches to `handleResourceRead` |
|
|
67
|
-
| `resources/subscribe` | Adds URI to subscriptions set |
|
|
68
|
-
| `resources/unsubscribe` | Removes URI from subscriptions |
|
|
69
|
-
|
|
70
|
-
**Pre-initialization guard**: all methods except
|
|
71
|
-
`initialize` and `ping` return error `-32002`
|
|
72
|
-
("Server not initialized") until
|
|
73
|
-
`notifications/initialized` is received.
|
|
74
|
-
|
|
75
|
-
**Tools (via `handleToolCall`):**
|
|
76
|
-
|
|
77
|
-
| Tool | Client Method / Handler |
|
|
78
|
-
|----------------|-------------------------------------|
|
|
79
|
-
| `search` | `client.search()` |
|
|
80
|
-
| `learn` | `client.addSection()` |
|
|
81
|
-
| `unlearn` | `client.removeSection()` |
|
|
82
|
-
| `retrieve` | `client.readSections()` or |
|
|
83
|
-
| | `client.retrieveDocument()` |
|
|
84
|
-
| `recall` | `handleRecall(params, client)` |
|
|
85
|
-
| `status` | `client.dbStatus()` |
|
|
86
|
-
| `skill-learn` | `handleSkillLearn(params, client)` |
|
|
87
|
-
| `skill-list` | `handleSkillList(client)` |
|
|
88
|
-
| `skill-get` | `handleSkillGet(params, client)` |
|
|
89
|
-
| `skill-delete` | `handleSkillDelete(params, client)` |
|
|
90
|
-
| `agent-create` | `handleAgentCreate(params, client)` |
|
|
91
|
-
| `agent-list` | `handleAgentList(client)` |
|
|
92
|
-
| `agent-get` | `handleAgentGet(params, client)` |
|
|
93
|
-
| `agent-delete` | `handleAgentDelete(params, client)` |
|
|
94
|
-
|
|
95
|
-
**Resource URI templates:**
|
|
96
|
-
|
|
97
|
-
| URI Template | MIME Type |
|
|
98
|
-
|-------------------------------|------------------|
|
|
99
|
-
| `kbdb://section/{kbid}` | `text/plain` |
|
|
100
|
-
| `kbdb://document/{docid}` | `application/json` |
|
|
101
|
-
|
|
102
|
-
#### `listen()`
|
|
103
|
-
|
|
104
|
-
Returns a `Promise<void>` that resolves when stdin
|
|
105
|
-
closes. Reads JSON-RPC 2.0 requests from stdin,
|
|
106
|
-
dispatches to the appropriate handler, and writes
|
|
107
|
-
JSON-RPC responses to stdout. Disconnects the
|
|
108
|
-
`McpWorkerClient` when the promise resolves.
|
|
109
|
-
|
|
110
|
-
#### `handleLineForTest(line)`
|
|
111
|
-
|
|
112
|
-
Processes a single raw input line and returns the
|
|
113
|
-
JSON-RPC response, or `null` for notifications
|
|
114
|
-
(which have no id and expect no response). Used
|
|
115
|
-
for unit testing protocol handling without stdio.
|
|
116
|
-
|
|
117
|
-
#### `prompts/list` handler
|
|
118
|
-
|
|
119
|
-
Calls `client.listByType('skill')` and
|
|
120
|
-
`client.listDocumentsByType('agent')`, then maps
|
|
121
|
-
results to `McpPrompt[]` via
|
|
122
|
-
`createPromptDefinitions(sections)`. Agent prompts
|
|
123
|
-
use the `agent:` name prefix.
|
|
124
|
-
|
|
125
|
-
#### `prompts/get` handler
|
|
126
|
-
|
|
127
|
-
Parses the prompt name to determine whether it is
|
|
128
|
-
a skill (no prefix) or agent (`agent:` prefix),
|
|
129
|
-
then calls `handlePromptGet(name, args, client)` to
|
|
130
|
-
render the template and return `McpPromptMessage[]`.
|
|
131
|
-
|
|
132
|
-
#### `completion/complete` handler
|
|
133
|
-
|
|
134
|
-
Dispatches to `handleCompletion(ref, argument, client)`
|
|
135
|
-
based on the ref type (`ref/prompt` or `ref/resource`)
|
|
136
|
-
and returns a `McpCompletionResult` with matching
|
|
137
|
-
name or URI suggestions.
|
|
138
|
-
|
|
139
|
-
#### `logging/setLevel` handler
|
|
140
|
-
|
|
141
|
-
Stores the requested `McpLogLevel` in `this.logLevel`.
|
|
142
|
-
Subsequent log events emitted at or above this level
|
|
143
|
-
are sent to the client as `notifications/message`
|
|
144
|
-
using the `notify` method.
|
|
145
|
-
|
|
146
|
-
#### `roots/list` handler
|
|
147
|
-
|
|
148
|
-
Returns the `.kbdb` directory as a single root entry:
|
|
149
|
-
`{ uri: "file:///path/to/.kbdb", name: "kbdb database" }`.
|
|
150
|
-
|
|
151
|
-
#### `resources/subscribe` handler
|
|
152
|
-
|
|
153
|
-
Adds the requested URI to `this.subscriptions`. When
|
|
154
|
-
a subscribed resource is updated (section added,
|
|
155
|
-
modified, or deleted), the server calls `notify` with
|
|
156
|
-
method `notifications/resources/updated`.
|
|
157
|
-
|
|
158
|
-
#### `resources/unsubscribe` handler
|
|
159
|
-
|
|
160
|
-
Removes the requested URI from `this.subscriptions`.
|
|
161
|
-
|
|
162
|
-
#### `notify(method, params)`
|
|
163
|
-
|
|
164
|
-
Sends a server-initiated JSON-RPC 2.0 notification
|
|
165
|
-
to the client over stdout. Used for log messages
|
|
166
|
-
(`notifications/message`) and resource update events
|
|
167
|
-
(`notifications/resources/updated`).
|
|
168
|
-
|
|
169
|
-
```ts
|
|
170
|
-
notify(method: string, params: unknown): void;
|
|
171
|
-
```
|
|
172
|
-
|
|
173
|
-
## Testing
|
|
174
|
-
|
|
175
|
-
```
|
|
176
|
-
src/shared/mcp/
|
|
177
|
-
├── classes/
|
|
178
|
-
│ └── mcp-server.spec.ts
|
|
179
|
-
```
|
|
@@ -1,386 +0,0 @@
|
|
|
1
|
-
# mcp/functions -- MCP Server Functions
|
|
2
|
-
|
|
3
|
-
*Factory, tool dispatch, resource dispatch, and
|
|
4
|
-
definition builders.*
|
|
5
|
-
|
|
6
|
-
## Source
|
|
7
|
-
|
|
8
|
-
`src/shared/mcp/functions/`
|
|
9
|
-
|
|
10
|
-
## Functions
|
|
11
|
-
|
|
12
|
-
### `createMcpServer`
|
|
13
|
-
|
|
14
|
-
**File:** `create-mcp-server.function.ts`
|
|
15
|
-
|
|
16
|
-
Factory function. Creates and returns a configured
|
|
17
|
-
`McpServer` bound to the given `McpWorkerClient`.
|
|
18
|
-
|
|
19
|
-
```ts
|
|
20
|
-
function createMcpServer(
|
|
21
|
-
client: McpWorkerClient,
|
|
22
|
-
): McpServer;
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
### `createToolDefinitions`
|
|
26
|
-
|
|
27
|
-
**File:** `create-tool-definitions.function.ts`
|
|
28
|
-
|
|
29
|
-
Returns an array of `McpToolDefinition` objects
|
|
30
|
-
describing the MCP tools the server exposes. Each
|
|
31
|
-
definition includes `name`, `description`,
|
|
32
|
-
`inputSchema` (JSON Schema), and `annotations`
|
|
33
|
-
(`McpToolAnnotations`).
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
function createToolDefinitions(): McpToolDefinition[];
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
**Tools defined (18 total):**
|
|
40
|
-
|
|
41
|
-
| Name | Required Params | Optional Params |
|
|
42
|
-
|----------------|----------------------------|--------------------------------------|
|
|
43
|
-
| `search` | `query` | `mode`, `limit`, `content`, `offset` |
|
|
44
|
-
| `learn` | `content` | `type`, `docid`, `title`, `description` |
|
|
45
|
-
| `unlearn` | `kbid` | -- |
|
|
46
|
-
| `retrieve` | `kbid` or `docid` | -- |
|
|
47
|
-
| `recall` | `kbid` or `kbids` | `depth` |
|
|
48
|
-
| `status` | -- | -- |
|
|
49
|
-
| `content` | `ids` | -- |
|
|
50
|
-
| `check` | -- | -- |
|
|
51
|
-
| `gc` | -- | -- |
|
|
52
|
-
| `rebuild` | -- | -- |
|
|
53
|
-
| `skill-learn` | `name`, `description`, `body` | `arguments` |
|
|
54
|
-
| `skill-list` | -- | -- |
|
|
55
|
-
| `skill-get` | `name` or `kbid` | -- |
|
|
56
|
-
| `skill-delete` | `kbid` | -- |
|
|
57
|
-
| `agent-create` | `name`, `description`, `persona`, `skills` | -- |
|
|
58
|
-
| `agent-list` | -- | -- |
|
|
59
|
-
| `agent-get` | `docid` | -- |
|
|
60
|
-
| `agent-delete` | `docid` | -- |
|
|
61
|
-
|
|
62
|
-
### `createResourceTemplates`
|
|
63
|
-
|
|
64
|
-
**File:** `create-resource-templates.function.ts`
|
|
65
|
-
|
|
66
|
-
Returns an array of `McpResourceTemplate` objects
|
|
67
|
-
describing the URI templates for MCP resources. These
|
|
68
|
-
are returned by `resources/templates/list`.
|
|
69
|
-
|
|
70
|
-
```ts
|
|
71
|
-
function createResourceTemplates(): McpResourceTemplate[];
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
**Templates defined:**
|
|
75
|
-
|
|
76
|
-
| URI Template | MIME Type |
|
|
77
|
-
|-------------------------------|---------------------|
|
|
78
|
-
| `kbdb://section/{kb_id}` | `text/plain` |
|
|
79
|
-
| `kbdb://document/{doc_id}` | `application/json` |
|
|
80
|
-
|
|
81
|
-
### `handleToolCall`
|
|
82
|
-
|
|
83
|
-
**File:** `handle-tool-call.function.ts`
|
|
84
|
-
|
|
85
|
-
Single dispatcher for all MCP `tools/call` requests.
|
|
86
|
-
Routes by tool name to the appropriate
|
|
87
|
-
`McpWorkerClient` method.
|
|
88
|
-
|
|
89
|
-
```ts
|
|
90
|
-
async function handleToolCall(
|
|
91
|
-
client: McpWorkerClient,
|
|
92
|
-
name: string,
|
|
93
|
-
args: Record<string, unknown>,
|
|
94
|
-
): Promise<McpToolResult>;
|
|
95
|
-
```
|
|
96
|
-
|
|
97
|
-
Routing:
|
|
98
|
-
|
|
99
|
-
| Tool Name | Client Method / Handler |
|
|
100
|
-
|----------------|--------------------------------------|
|
|
101
|
-
| `search` | `client.search(params)` |
|
|
102
|
-
| `learn` | `client.addSection(params)` |
|
|
103
|
-
| `unlearn` | `client.removeSection(kbid)` |
|
|
104
|
-
| `retrieve` | `client.readSections(kbids)` or |
|
|
105
|
-
| | `client.retrieveDocument(docid)` |
|
|
106
|
-
| `recall` | `handleRecall(params, client)` |
|
|
107
|
-
| `status` | `client.dbStatus()` |
|
|
108
|
-
| `content` | `client.content(ids)` |
|
|
109
|
-
| `check` | `client.integrityCheck()` |
|
|
110
|
-
| `gc` | `client.gc()` |
|
|
111
|
-
| `rebuild` | `client.rebuildIndexes()` |
|
|
112
|
-
| `skill-learn` | `handleSkillLearn(args, client)` |
|
|
113
|
-
| `skill-list` | `handleSkillList(client)` |
|
|
114
|
-
| `skill-get` | `handleSkillGet(args, client)` |
|
|
115
|
-
| `skill-delete` | `handleSkillDelete(args, client)` |
|
|
116
|
-
| `agent-create` | `handleAgentCreate(args, client)` |
|
|
117
|
-
| `agent-list` | `handleAgentList(client)` |
|
|
118
|
-
| `agent-get` | `handleAgentGet(args, client)` |
|
|
119
|
-
| `agent-delete` | `handleAgentDelete(args, client)` |
|
|
120
|
-
|
|
121
|
-
Tool execution errors (client throws) are caught and
|
|
122
|
-
returned as `{ content: [...], isError: true }`. They
|
|
123
|
-
are **not** returned as JSON-RPC error responses.
|
|
124
|
-
Unknown tool names also return `isError: true`.
|
|
125
|
-
|
|
126
|
-
### `handleResourceRead`
|
|
127
|
-
|
|
128
|
-
**File:** `handle-resource-read.function.ts`
|
|
129
|
-
|
|
130
|
-
Handles MCP `resources/read` requests. Parses the
|
|
131
|
-
URI to determine whether it is a section or document
|
|
132
|
-
request, then calls the appropriate client method.
|
|
133
|
-
|
|
134
|
-
```ts
|
|
135
|
-
async function handleResourceRead(
|
|
136
|
-
client: McpWorkerClient,
|
|
137
|
-
uri: string,
|
|
138
|
-
): Promise<McpResourceResult>;
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
Throws on invalid or unrecognised URIs. The caller
|
|
142
|
-
(`McpServer`) catches the error and returns a
|
|
143
|
-
`RESOURCE_NOT_FOUND` (-32002) JSON-RPC error
|
|
144
|
-
response.
|
|
145
|
-
|
|
146
|
-
### `createPromptDefinitions`
|
|
147
|
-
|
|
148
|
-
**File:** `create-prompt-definitions.function.ts`
|
|
149
|
-
|
|
150
|
-
Maps an array of skill sections and agent documents
|
|
151
|
-
to `McpPrompt[]` for the `prompts/list` response.
|
|
152
|
-
Skill prompts use the skill name directly; agent
|
|
153
|
-
prompts use `agent:<name>` as the prompt name.
|
|
154
|
-
|
|
155
|
-
```ts
|
|
156
|
-
function createPromptDefinitions(
|
|
157
|
-
sections: Section[],
|
|
158
|
-
): McpPrompt[];
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
### `handlePromptGet`
|
|
162
|
-
|
|
163
|
-
**File:** `handle-prompt-get.function.ts`
|
|
164
|
-
|
|
165
|
-
Fetches a skill or agent by prompt name and renders
|
|
166
|
-
it as `McpPromptMessage[]`. For skills: substitutes
|
|
167
|
-
argument values into the template body and returns
|
|
168
|
-
a single user message. For agents: returns an
|
|
169
|
-
assistant message (persona) followed by a user
|
|
170
|
-
message listing available skills.
|
|
171
|
-
|
|
172
|
-
```ts
|
|
173
|
-
async function handlePromptGet(
|
|
174
|
-
name: string,
|
|
175
|
-
args: Record<string, string>,
|
|
176
|
-
client: McpWorkerClient,
|
|
177
|
-
): Promise<McpPromptMessage[]>;
|
|
178
|
-
```
|
|
179
|
-
|
|
180
|
-
### `handleCompletion`
|
|
181
|
-
|
|
182
|
-
**File:** `handle-completion.function.ts`
|
|
183
|
-
|
|
184
|
-
Provides autocomplete suggestions for prompt names
|
|
185
|
-
and resource URIs. Dispatches based on `ref.type`:
|
|
186
|
-
`ref/prompt` returns matching skill or agent names;
|
|
187
|
-
`ref/resource` returns matching kbid or docid values
|
|
188
|
-
from known URI patterns.
|
|
189
|
-
|
|
190
|
-
```ts
|
|
191
|
-
async function handleCompletion(
|
|
192
|
-
ref: McpCompletionRef,
|
|
193
|
-
argument: Record<string, string> | undefined,
|
|
194
|
-
client: McpWorkerClient,
|
|
195
|
-
): Promise<McpCompletionResult>;
|
|
196
|
-
```
|
|
197
|
-
|
|
198
|
-
### `parseSkillContent`
|
|
199
|
-
|
|
200
|
-
**File:** `parse-skill-content.function.ts`
|
|
201
|
-
|
|
202
|
-
Parses a JSON string stored as a skill section's
|
|
203
|
-
content into a typed `SkillDefinition`. Throws when
|
|
204
|
-
the JSON is malformed or missing required fields.
|
|
205
|
-
|
|
206
|
-
```ts
|
|
207
|
-
function parseSkillContent(
|
|
208
|
-
json: string,
|
|
209
|
-
): SkillDefinition;
|
|
210
|
-
```
|
|
211
|
-
|
|
212
|
-
### `serializeSkillContent`
|
|
213
|
-
|
|
214
|
-
**File:** `serialize-skill-content.function.ts`
|
|
215
|
-
|
|
216
|
-
Serializes a `SkillDefinition` to a JSON string for
|
|
217
|
-
storage as a section content body.
|
|
218
|
-
|
|
219
|
-
```ts
|
|
220
|
-
function serializeSkillContent(
|
|
221
|
-
skill: SkillDefinition,
|
|
222
|
-
): string;
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
### `handleSkillLearn`
|
|
226
|
-
|
|
227
|
-
**File:** `handle-skill-learn.function.ts`
|
|
228
|
-
|
|
229
|
-
Handles the `skill-learn` MCP tool call. Validates
|
|
230
|
-
parameters, serializes the skill definition to JSON,
|
|
231
|
-
and calls `client.addSection` with
|
|
232
|
-
`sectionType: 'skill'`.
|
|
233
|
-
|
|
234
|
-
```ts
|
|
235
|
-
async function handleSkillLearn(
|
|
236
|
-
params: Record<string, unknown>,
|
|
237
|
-
client: McpWorkerClient,
|
|
238
|
-
): Promise<McpToolResult>;
|
|
239
|
-
```
|
|
240
|
-
|
|
241
|
-
### `handleSkillList`
|
|
242
|
-
|
|
243
|
-
**File:** `handle-skill-list.function.ts`
|
|
244
|
-
|
|
245
|
-
Handles the `skill-list` MCP tool call. Calls
|
|
246
|
-
`client.listByType('skill')` and formats the results.
|
|
247
|
-
|
|
248
|
-
```ts
|
|
249
|
-
async function handleSkillList(
|
|
250
|
-
client: McpWorkerClient,
|
|
251
|
-
): Promise<McpToolResult>;
|
|
252
|
-
```
|
|
253
|
-
|
|
254
|
-
### `handleSkillGet`
|
|
255
|
-
|
|
256
|
-
**File:** `handle-skill-get.function.ts`
|
|
257
|
-
|
|
258
|
-
Handles the `skill-get` MCP tool call. Looks up the
|
|
259
|
-
skill by `name` (via search) or by `kbid` (via
|
|
260
|
-
`client.readSections`), parses the content, and
|
|
261
|
-
returns the full `SkillDefinition`.
|
|
262
|
-
|
|
263
|
-
```ts
|
|
264
|
-
async function handleSkillGet(
|
|
265
|
-
params: Record<string, unknown>,
|
|
266
|
-
client: McpWorkerClient,
|
|
267
|
-
): Promise<McpToolResult>;
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
### `handleSkillDelete`
|
|
271
|
-
|
|
272
|
-
**File:** `handle-skill-delete.function.ts`
|
|
273
|
-
|
|
274
|
-
Handles the `skill-delete` MCP tool call. Calls
|
|
275
|
-
`client.removeSection(kbid)`.
|
|
276
|
-
|
|
277
|
-
```ts
|
|
278
|
-
async function handleSkillDelete(
|
|
279
|
-
params: Record<string, unknown>,
|
|
280
|
-
client: McpWorkerClient,
|
|
281
|
-
): Promise<McpToolResult>;
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### `handleAgentCreate`
|
|
285
|
-
|
|
286
|
-
**File:** `handle-agent-create.function.ts`
|
|
287
|
-
|
|
288
|
-
Handles the `agent-create` MCP tool call. Validates
|
|
289
|
-
skill kbids, builds the agent document manifest, and
|
|
290
|
-
stores it.
|
|
291
|
-
|
|
292
|
-
```ts
|
|
293
|
-
async function handleAgentCreate(
|
|
294
|
-
params: Record<string, unknown>,
|
|
295
|
-
client: McpWorkerClient,
|
|
296
|
-
): Promise<McpToolResult>;
|
|
297
|
-
```
|
|
298
|
-
|
|
299
|
-
### `handleAgentList`
|
|
300
|
-
|
|
301
|
-
**File:** `handle-agent-list.function.ts`
|
|
302
|
-
|
|
303
|
-
Handles the `agent-list` MCP tool call. Calls
|
|
304
|
-
`client.listDocumentsByType('agent')` and formats
|
|
305
|
-
the results.
|
|
306
|
-
|
|
307
|
-
```ts
|
|
308
|
-
async function handleAgentList(
|
|
309
|
-
client: McpWorkerClient,
|
|
310
|
-
): Promise<McpToolResult>;
|
|
311
|
-
```
|
|
312
|
-
|
|
313
|
-
### `handleAgentGet`
|
|
314
|
-
|
|
315
|
-
**File:** `handle-agent-get.function.ts`
|
|
316
|
-
|
|
317
|
-
Handles the `agent-get` MCP tool call. Retrieves
|
|
318
|
-
the agent document by `docid` and resolves each
|
|
319
|
-
referenced skill kbid into a `SkillDefinition`.
|
|
320
|
-
Missing skills appear as `null` name entries.
|
|
321
|
-
|
|
322
|
-
```ts
|
|
323
|
-
async function handleAgentGet(
|
|
324
|
-
params: Record<string, unknown>,
|
|
325
|
-
client: McpWorkerClient,
|
|
326
|
-
): Promise<McpToolResult>;
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
### `handleAgentDelete`
|
|
330
|
-
|
|
331
|
-
**File:** `handle-agent-delete.function.ts`
|
|
332
|
-
|
|
333
|
-
Handles the `agent-delete` MCP tool call. Removes
|
|
334
|
-
the agent document manifest. Referenced skill
|
|
335
|
-
sections are not deleted.
|
|
336
|
-
|
|
337
|
-
```ts
|
|
338
|
-
async function handleAgentDelete(
|
|
339
|
-
params: Record<string, unknown>,
|
|
340
|
-
client: McpWorkerClient,
|
|
341
|
-
): Promise<McpToolResult>;
|
|
342
|
-
```
|
|
343
|
-
|
|
344
|
-
### `handleRecall`
|
|
345
|
-
|
|
346
|
-
**File:** `handle-recall.function.ts`
|
|
347
|
-
|
|
348
|
-
Handles the `recall` MCP tool call. Validates that
|
|
349
|
-
at least one of `kbid` or `kbids` is provided,
|
|
350
|
-
clamps `depth` to 0--3, calls
|
|
351
|
-
`client.recall(params)`, and formats the result
|
|
352
|
-
as a JSON text content item.
|
|
353
|
-
|
|
354
|
-
```ts
|
|
355
|
-
async function handleRecall(
|
|
356
|
-
params: Record<string, unknown>,
|
|
357
|
-
client: McpWorkerClient,
|
|
358
|
-
): Promise<McpToolResult>;
|
|
359
|
-
```
|
|
360
|
-
|
|
361
|
-
## Testing
|
|
362
|
-
|
|
363
|
-
Each function has a `.spec.ts` at the module root:
|
|
364
|
-
|
|
365
|
-
```
|
|
366
|
-
src/shared/mcp/
|
|
367
|
-
├── create-mcp-server.spec.ts
|
|
368
|
-
├── create-tool-definitions.spec.ts
|
|
369
|
-
├── create-prompt-definitions.spec.ts
|
|
370
|
-
├── create-resource-templates.spec.ts
|
|
371
|
-
├── handle-tool-call.spec.ts
|
|
372
|
-
├── handle-resource-read.spec.ts
|
|
373
|
-
├── handle-prompt-get.spec.ts
|
|
374
|
-
├── handle-completion.spec.ts
|
|
375
|
-
├── parse-skill-content.spec.ts
|
|
376
|
-
├── serialize-skill-content.spec.ts
|
|
377
|
-
├── handle-skill-learn.spec.ts
|
|
378
|
-
├── handle-skill-list.spec.ts
|
|
379
|
-
├── handle-skill-get.spec.ts
|
|
380
|
-
├── handle-skill-delete.spec.ts
|
|
381
|
-
├── handle-agent-create.spec.ts
|
|
382
|
-
├── handle-agent-list.spec.ts
|
|
383
|
-
├── handle-agent-get.spec.ts
|
|
384
|
-
├── handle-agent-delete.spec.ts
|
|
385
|
-
└── mcp-server.spec.ts
|
|
386
|
-
```
|