@dikolab/kbdb 0.1.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/LICENSE +15 -0
- package/README.md +270 -0
- package/dist/chunk-QCCN7OZH.mjs +82 -0
- package/dist/chunk-QCCN7OZH.mjs.map +7 -0
- package/dist/cli.cjs +3598 -0
- package/dist/cli.cjs.map +7 -0
- package/dist/cli.mjs +3537 -0
- package/dist/cli.mjs.map +7 -0
- package/dist/kbdb-worker.cjs +1659 -0
- package/dist/kbdb-worker.cjs.map +7 -0
- package/dist/mod.cjs +538 -0
- package/dist/mod.cjs.map +7 -0
- package/dist/mod.d.ts +3 -0
- package/dist/mod.mjs +507 -0
- package/dist/mod.mjs.map +7 -0
- package/dist/src/cli.d.ts +1 -0
- package/dist/src/shared/cli/constants/defaults.constant.d.ts +11 -0
- package/dist/src/shared/cli/constants/help-text.constant.d.ts +2 -0
- package/dist/src/shared/cli/functions/dispatch-command.function.d.ts +37 -0
- package/dist/src/shared/cli/functions/ensure-db.function.d.ts +11 -0
- package/dist/src/shared/cli/functions/error-to-message.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/find-db.function.d.ts +13 -0
- package/dist/src/shared/cli/functions/format-output.function.d.ts +15 -0
- package/dist/src/shared/cli/functions/generate-help.function.d.ts +31 -0
- package/dist/src/shared/cli/functions/is-stdin-tty.function.d.ts +7 -0
- package/dist/src/shared/cli/functions/parse-args.function.d.ts +25 -0
- package/dist/src/shared/cli/functions/prompt-user.function.d.ts +13 -0
- package/dist/src/shared/cli/functions/run-agent-create.function.d.ts +58 -0
- package/dist/src/shared/cli/functions/run-agent-delete.function.d.ts +32 -0
- package/dist/src/shared/cli/functions/run-agent-get.function.d.ts +46 -0
- package/dist/src/shared/cli/functions/run-agent-list.function.d.ts +45 -0
- package/dist/src/shared/cli/functions/run-check.function.d.ts +64 -0
- package/dist/src/shared/cli/functions/run-cli.function.d.ts +39 -0
- package/dist/src/shared/cli/functions/run-content.function.d.ts +40 -0
- package/dist/src/shared/cli/functions/run-db-init.function.d.ts +23 -0
- package/dist/src/shared/cli/functions/run-db-migrate.function.d.ts +32 -0
- package/dist/src/shared/cli/functions/run-gc.function.d.ts +38 -0
- package/dist/src/shared/cli/functions/run-init.function.d.ts +27 -0
- package/dist/src/shared/cli/functions/run-learn.function.d.ts +46 -0
- package/dist/src/shared/cli/functions/run-migrate.function.d.ts +57 -0
- package/dist/src/shared/cli/functions/run-rebuild.function.d.ts +40 -0
- package/dist/src/shared/cli/functions/run-search.function.d.ts +39 -0
- package/dist/src/shared/cli/functions/run-skill-delete.function.d.ts +30 -0
- package/dist/src/shared/cli/functions/run-skill-get.function.d.ts +49 -0
- package/dist/src/shared/cli/functions/run-skill-learn.function.d.ts +36 -0
- package/dist/src/shared/cli/functions/run-skill-list.function.d.ts +43 -0
- package/dist/src/shared/cli/functions/run-status.function.d.ts +22 -0
- package/dist/src/shared/cli/functions/run-unlearn.function.d.ts +45 -0
- package/dist/src/shared/cli/index.d.ts +35 -0
- package/dist/src/shared/cli/typings/cli-options.interface.d.ts +53 -0
- package/dist/src/shared/cli/typings/command-result.model.d.ts +15 -0
- package/dist/src/shared/cli/typings/learn-result.model.d.ts +11 -0
- package/dist/src/shared/cli/typings/search-display.model.d.ts +17 -0
- package/dist/src/shared/dir-resolver/functions/resolve-base-dir.function.d.ts +3 -0
- package/dist/src/shared/dir-resolver/functions/resolve-wasm-dir.function.d.ts +1 -0
- package/dist/src/shared/dir-resolver/functions/resolve-worker-script.function.d.ts +2 -0
- package/dist/src/shared/dir-resolver/index.d.ts +4 -0
- package/dist/src/shared/dir-resolver/typings/base-dir.interface.d.ts +4 -0
- package/dist/src/shared/hash/functions/compute-sha256.d.ts +10 -0
- package/dist/src/shared/hash/index.d.ts +1 -0
- package/dist/src/shared/mcp/classes/mcp-server.class.d.ts +55 -0
- package/dist/src/shared/mcp/constants/mcp-error-codes.constant.d.ts +26 -0
- package/dist/src/shared/mcp/functions/create-mcp-server.function.d.ts +11 -0
- package/dist/src/shared/mcp/functions/create-prompt-definitions.function.d.ts +41 -0
- package/dist/src/shared/mcp/functions/create-resource-templates.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/create-tool-definitions.function.d.ts +7 -0
- package/dist/src/shared/mcp/functions/extract-skill-arguments.function.d.ts +13 -0
- package/dist/src/shared/mcp/functions/handle-agent-create.function.d.ts +29 -0
- package/dist/src/shared/mcp/functions/handle-agent-delete.function.d.ts +28 -0
- package/dist/src/shared/mcp/functions/handle-agent-get.function.d.ts +29 -0
- package/dist/src/shared/mcp/functions/handle-agent-list.function.d.ts +31 -0
- package/dist/src/shared/mcp/functions/handle-completion.function.d.ts +58 -0
- package/dist/src/shared/mcp/functions/handle-prompt-get.function.d.ts +23 -0
- package/dist/src/shared/mcp/functions/handle-resource-read.function.d.ts +26 -0
- package/dist/src/shared/mcp/functions/handle-roots-list.function.d.ts +21 -0
- package/dist/src/shared/mcp/functions/handle-tool-call.function.d.ts +26 -0
- package/dist/src/shared/mcp/functions/parse-skill-content.function.d.ts +15 -0
- package/dist/src/shared/mcp/functions/serialize-skill-content.function.d.ts +9 -0
- package/dist/src/shared/mcp/functions/should-emit-log.function.d.ts +20 -0
- package/dist/src/shared/mcp/index.d.ts +9 -0
- package/dist/src/shared/mcp/typings/agent-types.interface.d.ts +38 -0
- package/dist/src/shared/mcp/typings/log-types.interface.d.ts +17 -0
- package/dist/src/shared/mcp/typings/mcp-client.interface.d.ts +217 -0
- package/dist/src/shared/mcp/typings/mcp-types.interface.d.ts +149 -0
- package/dist/src/shared/mcp/typings/prompt-types.interface.d.ts +37 -0
- package/dist/src/shared/mcp/typings/remove-section-result.model.d.ts +10 -0
- package/dist/src/shared/mcp/typings/sampling-types.interface.d.ts +46 -0
- package/dist/src/shared/mcp/typings/skill-types.interface.d.ts +28 -0
- package/dist/src/shared/mod.d.ts +1 -0
- package/dist/src/shared/platform/functions/get-ipc-path.function.d.ts +11 -0
- package/dist/src/shared/platform/functions/get-tmpdir.function.d.ts +4 -0
- package/dist/src/shared/platform/functions/is-process-alive.function.d.ts +10 -0
- package/dist/src/shared/platform/index.d.ts +3 -0
- package/dist/src/shared/runtime/functions/detect-runtime.d.ts +8 -0
- package/dist/src/shared/runtime/functions/get-args.d.ts +7 -0
- package/dist/src/shared/runtime/index.d.ts +3 -0
- package/dist/src/shared/runtime/typings/runtime.d.ts +2 -0
- package/dist/src/shared/version/constants/version.constant.d.ts +2 -0
- package/dist/src/shared/version/index.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-compose-output.function.d.ts +5 -0
- package/dist/src/shared/wasm-codec/functions/decode-document-manifest-list.function.d.ts +14 -0
- package/dist/src/shared/wasm-codec/functions/decode-document-manifest.function.d.ts +40 -0
- package/dist/src/shared/wasm-codec/functions/decode-f32.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/decode-key-value-text.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-remove-flag.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/decode-scored-results.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-record-list.function.d.ts +13 -0
- package/dist/src/shared/wasm-codec/functions/decode-section-records.function.d.ts +50 -0
- package/dist/src/shared/wasm-codec/functions/decode-string.function.d.ts +5 -0
- package/dist/src/shared/wasm-codec/functions/decode-u32.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/decode-u64.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/functions/encode-add-section-params.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/encode-group-params.function.d.ts +10 -0
- package/dist/src/shared/wasm-codec/functions/encode-identifier-list.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-kbid-list.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-option-string.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-search-params.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-section-type.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-string.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-type-filter-param.function.d.ts +11 -0
- package/dist/src/shared/wasm-codec/functions/encode-u32.function.d.ts +1 -0
- package/dist/src/shared/wasm-codec/functions/encode-update-section-params.function.d.ts +2 -0
- package/dist/src/shared/wasm-codec/index.d.ts +29 -0
- package/dist/src/shared/worker-client/classes/worker-client.class.d.ts +230 -0
- package/dist/src/shared/worker-client/functions/compute-context-id.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/create-worker-client.function.d.ts +18 -0
- package/dist/src/shared/worker-client/functions/discover-daemon.function.d.ts +14 -0
- package/dist/src/shared/worker-client/functions/resolve-db-path.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/spawn-daemon.function.d.ts +11 -0
- package/dist/src/shared/worker-client/functions/wait-for-daemon.function.d.ts +13 -0
- package/dist/src/shared/worker-client/index.d.ts +22 -0
- package/dist/src/shared/worker-client/typings/add-section-result.model.d.ts +22 -0
- package/dist/src/shared/worker-client/typings/content-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/daemon-info.model.d.ts +7 -0
- package/dist/src/shared/worker-client/typings/gc-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/integrity-check-result.model.d.ts +36 -0
- package/dist/src/shared/worker-client/typings/migrate-result.model.d.ts +11 -0
- package/dist/src/shared/worker-client/typings/rebuild-result.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/remove-section-result.model.d.ts +7 -0
- package/dist/src/shared/worker-client/typings/search-params.model.d.ts +12 -0
- package/dist/src/shared/worker-client/typings/search-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/section.model.d.ts +26 -0
- package/dist/src/shared/worker-client/typings/status-result.model.d.ts +14 -0
- package/dist/src/shared/worker-client/typings/version-status.model.d.ts +24 -0
- package/dist/src/shared/worker-client/typings/worker-client-error.interface.d.ts +8 -0
- package/dist/src/shared/worker-client/typings/worker-client-options.interface.d.ts +30 -0
- package/dist/src/shared/worker-daemon/classes/worker-daemon.class.d.ts +147 -0
- package/dist/src/shared/worker-daemon/constants/daemon-defaults.constant.d.ts +24 -0
- package/dist/src/shared/worker-daemon/functions/create-host-imports.function.d.ts +68 -0
- package/dist/src/shared/worker-daemon/functions/create-ipc-server.function.d.ts +18 -0
- package/dist/src/shared/worker-daemon/functions/load-wasm-modules.function.d.ts +19 -0
- package/dist/src/shared/worker-daemon/functions/read-config.function.d.ts +12 -0
- package/dist/src/shared/worker-daemon/functions/run-worker.function.d.ts +26 -0
- package/dist/src/shared/worker-daemon/functions/start-daemon.function.d.ts +13 -0
- package/dist/src/shared/worker-daemon/index.d.ts +9 -0
- package/dist/src/shared/worker-daemon/typings/daemon-config.interface.d.ts +13 -0
- package/dist/src/shared/worker-daemon/typings/ipc-handler.interface.d.ts +36 -0
- package/dist/src/shared/worker-daemon/typings/wasm-modules.interface.d.ts +7 -0
- package/dist/src/worker.d.ts +1 -0
- package/dist/vitest.config.d.ts +2 -0
- package/dist/worker.mjs +1615 -0
- package/dist/worker.mjs.map +7 -0
- package/mod.ts +17 -0
- package/package.json +85 -0
- package/src/cli.ts +62 -0
- package/src/shared/cli/constants/defaults.constant.ts +19 -0
- package/src/shared/cli/constants/help-text.constant.ts +4 -0
- package/src/shared/cli/functions/dispatch-command.function.ts +338 -0
- package/src/shared/cli/functions/ensure-db.function.ts +21 -0
- package/src/shared/cli/functions/error-to-message.function.ts +9 -0
- package/src/shared/cli/functions/find-db.function.ts +20 -0
- package/src/shared/cli/functions/format-output.function.ts +64 -0
- package/src/shared/cli/functions/generate-help.function.ts +599 -0
- package/src/shared/cli/functions/is-stdin-tty.function.ts +12 -0
- package/src/shared/cli/functions/parse-args.function.ts +133 -0
- package/src/shared/cli/functions/prompt-user.function.ts +36 -0
- package/src/shared/cli/functions/run-agent-create.function.ts +114 -0
- package/src/shared/cli/functions/run-agent-delete.function.ts +47 -0
- package/src/shared/cli/functions/run-agent-get.function.ts +166 -0
- package/src/shared/cli/functions/run-agent-list.function.ts +58 -0
- package/src/shared/cli/functions/run-check.function.ts +78 -0
- package/src/shared/cli/functions/run-cli.function.ts +299 -0
- package/src/shared/cli/functions/run-content.function.ts +47 -0
- package/src/shared/cli/functions/run-db-init.function.ts +44 -0
- package/src/shared/cli/functions/run-db-migrate.function.ts +40 -0
- package/src/shared/cli/functions/run-gc.function.ts +45 -0
- package/src/shared/cli/functions/run-init.function.ts +91 -0
- package/src/shared/cli/functions/run-learn.function.ts +171 -0
- package/src/shared/cli/functions/run-migrate.function.ts +85 -0
- package/src/shared/cli/functions/run-rebuild.function.ts +47 -0
- package/src/shared/cli/functions/run-search.function.ts +62 -0
- package/src/shared/cli/functions/run-skill-delete.function.ts +47 -0
- package/src/shared/cli/functions/run-skill-get.function.ts +90 -0
- package/src/shared/cli/functions/run-skill-learn.function.ts +70 -0
- package/src/shared/cli/functions/run-skill-list.function.ts +74 -0
- package/src/shared/cli/functions/run-status.function.ts +29 -0
- package/src/shared/cli/functions/run-unlearn.function.ts +58 -0
- package/src/shared/cli/index.ts +48 -0
- package/src/shared/cli/typings/cli-options.interface.ts +55 -0
- package/src/shared/cli/typings/command-result.model.ts +15 -0
- package/src/shared/cli/typings/learn-result.model.ts +11 -0
- package/src/shared/cli/typings/search-display.model.ts +17 -0
- package/src/shared/dir-resolver/functions/resolve-base-dir.function.ts +25 -0
- package/src/shared/dir-resolver/functions/resolve-wasm-dir.function.ts +5 -0
- package/src/shared/dir-resolver/functions/resolve-worker-script.function.ts +13 -0
- package/src/shared/dir-resolver/index.ts +7 -0
- package/src/shared/dir-resolver/typings/base-dir.interface.ts +4 -0
- package/src/shared/hash/functions/compute-sha256.ts +17 -0
- package/src/shared/hash/index.ts +1 -0
- package/src/shared/mcp/classes/mcp-server.class.ts +448 -0
- package/src/shared/mcp/constants/mcp-error-codes.constant.ts +30 -0
- package/src/shared/mcp/functions/create-mcp-server.function.ts +14 -0
- package/src/shared/mcp/functions/create-prompt-definitions.function.ts +102 -0
- package/src/shared/mcp/functions/create-resource-templates.function.ts +23 -0
- package/src/shared/mcp/functions/create-tool-definitions.function.ts +401 -0
- package/src/shared/mcp/functions/extract-skill-arguments.function.ts +27 -0
- package/src/shared/mcp/functions/handle-agent-create.function.ts +116 -0
- package/src/shared/mcp/functions/handle-agent-delete.function.ts +50 -0
- package/src/shared/mcp/functions/handle-agent-get.function.ts +160 -0
- package/src/shared/mcp/functions/handle-agent-list.function.ts +50 -0
- package/src/shared/mcp/functions/handle-completion.function.ts +114 -0
- package/src/shared/mcp/functions/handle-prompt-get.function.ts +214 -0
- package/src/shared/mcp/functions/handle-resource-read.function.ts +56 -0
- package/src/shared/mcp/functions/handle-roots-list.function.ts +29 -0
- package/src/shared/mcp/functions/handle-tool-call.function.ts +464 -0
- package/src/shared/mcp/functions/parse-skill-content.function.ts +38 -0
- package/src/shared/mcp/functions/serialize-skill-content.function.ts +12 -0
- package/src/shared/mcp/functions/should-emit-log.function.ts +38 -0
- package/src/shared/mcp/index.ts +28 -0
- package/src/shared/mcp/typings/agent-types.interface.ts +39 -0
- package/src/shared/mcp/typings/log-types.interface.ts +26 -0
- package/src/shared/mcp/typings/mcp-client.interface.ts +252 -0
- package/src/shared/mcp/typings/mcp-types.interface.ts +158 -0
- package/src/shared/mcp/typings/prompt-types.interface.ts +39 -0
- package/src/shared/mcp/typings/remove-section-result.model.ts +10 -0
- package/src/shared/mcp/typings/sampling-types.interface.ts +48 -0
- package/src/shared/mcp/typings/skill-types.interface.ts +29 -0
- package/src/shared/mod.ts +1 -0
- package/src/shared/platform/functions/get-ipc-path.function.ts +19 -0
- package/src/shared/platform/functions/get-tmpdir.function.ts +8 -0
- package/src/shared/platform/functions/is-process-alive.function.ts +17 -0
- package/src/shared/platform/index.ts +3 -0
- package/src/shared/runtime/functions/detect-runtime.ts +14 -0
- package/src/shared/runtime/functions/get-args.ts +16 -0
- package/src/shared/runtime/index.ts +3 -0
- package/src/shared/runtime/typings/runtime.ts +2 -0
- package/src/shared/version/constants/version.constant.ts +2 -0
- package/src/shared/version/index.ts +1 -0
- package/src/shared/wasm-codec/functions/decode-compose-output.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-document-manifest-list.function.ts +70 -0
- package/src/shared/wasm-codec/functions/decode-document-manifest.function.ts +87 -0
- package/src/shared/wasm-codec/functions/decode-f32.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-key-value-text.function.ts +15 -0
- package/src/shared/wasm-codec/functions/decode-remove-flag.function.ts +3 -0
- package/src/shared/wasm-codec/functions/decode-scored-results.function.ts +54 -0
- package/src/shared/wasm-codec/functions/decode-section-record-list.function.ts +20 -0
- package/src/shared/wasm-codec/functions/decode-section-records.function.ts +162 -0
- package/src/shared/wasm-codec/functions/decode-string.function.ts +22 -0
- package/src/shared/wasm-codec/functions/decode-u32.function.ts +16 -0
- package/src/shared/wasm-codec/functions/decode-u64.function.ts +16 -0
- package/src/shared/wasm-codec/functions/encode-add-section-params.function.ts +34 -0
- package/src/shared/wasm-codec/functions/encode-group-params.function.ts +28 -0
- package/src/shared/wasm-codec/functions/encode-identifier-list.function.ts +17 -0
- package/src/shared/wasm-codec/functions/encode-kbid-list.function.ts +17 -0
- package/src/shared/wasm-codec/functions/encode-option-string.function.ts +14 -0
- package/src/shared/wasm-codec/functions/encode-search-params.function.ts +9 -0
- package/src/shared/wasm-codec/functions/encode-section-type.function.ts +18 -0
- package/src/shared/wasm-codec/functions/encode-string.function.ts +9 -0
- package/src/shared/wasm-codec/functions/encode-type-filter-param.function.ts +13 -0
- package/src/shared/wasm-codec/functions/encode-u32.function.ts +5 -0
- package/src/shared/wasm-codec/functions/encode-update-section-params.function.ts +16 -0
- package/src/shared/wasm-codec/index.ts +36 -0
- package/src/shared/worker-client/classes/worker-client.class.ts +427 -0
- package/src/shared/worker-client/functions/compute-context-id.function.ts +18 -0
- package/src/shared/worker-client/functions/create-worker-client.function.ts +70 -0
- package/src/shared/worker-client/functions/discover-daemon.function.ts +47 -0
- package/src/shared/worker-client/functions/resolve-db-path.function.ts +21 -0
- package/src/shared/worker-client/functions/spawn-daemon.function.ts +35 -0
- package/src/shared/worker-client/functions/wait-for-daemon.function.ts +34 -0
- package/src/shared/worker-client/index.ts +31 -0
- package/src/shared/worker-client/typings/add-section-result.model.ts +22 -0
- package/src/shared/worker-client/typings/content-result.model.ts +12 -0
- package/src/shared/worker-client/typings/daemon-info.model.ts +7 -0
- package/src/shared/worker-client/typings/gc-result.model.ts +12 -0
- package/src/shared/worker-client/typings/integrity-check-result.model.ts +43 -0
- package/src/shared/worker-client/typings/migrate-result.model.ts +11 -0
- package/src/shared/worker-client/typings/rebuild-result.model.ts +12 -0
- package/src/shared/worker-client/typings/remove-section-result.model.ts +7 -0
- package/src/shared/worker-client/typings/search-params.model.ts +12 -0
- package/src/shared/worker-client/typings/search-result.model.ts +14 -0
- package/src/shared/worker-client/typings/section.model.ts +27 -0
- package/src/shared/worker-client/typings/status-result.model.ts +14 -0
- package/src/shared/worker-client/typings/version-status.model.ts +28 -0
- package/src/shared/worker-client/typings/worker-client-error.interface.ts +8 -0
- package/src/shared/worker-client/typings/worker-client-options.interface.ts +30 -0
- package/src/shared/worker-daemon/classes/worker-daemon.class.ts +1001 -0
- package/src/shared/worker-daemon/constants/daemon-defaults.constant.ts +29 -0
- package/src/shared/worker-daemon/functions/create-host-imports.function.ts +312 -0
- package/src/shared/worker-daemon/functions/create-ipc-server.function.ts +83 -0
- package/src/shared/worker-daemon/functions/load-wasm-modules.function.ts +98 -0
- package/src/shared/worker-daemon/functions/read-config.function.ts +83 -0
- package/src/shared/worker-daemon/functions/run-worker.function.ts +57 -0
- package/src/shared/worker-daemon/functions/start-daemon.function.ts +74 -0
- package/src/shared/worker-daemon/index.ts +16 -0
- package/src/shared/worker-daemon/typings/daemon-config.interface.ts +13 -0
- package/src/shared/worker-daemon/typings/ipc-handler.interface.ts +39 -0
- package/src/shared/worker-daemon/typings/wasm-modules.interface.ts +7 -0
- package/src/worker.ts +34 -0
|
@@ -0,0 +1,448 @@
|
|
|
1
|
+
import { createInterface } from 'node:readline';
|
|
2
|
+
import { createToolDefinitions } from '../functions/create-tool-definitions.function.ts';
|
|
3
|
+
import { createResourceTemplates } from '../functions/create-resource-templates.function.ts';
|
|
4
|
+
import { handleToolCall } from '../functions/handle-tool-call.function.ts';
|
|
5
|
+
import { handleResourceRead } from '../functions/handle-resource-read.function.ts';
|
|
6
|
+
import { createPromptDefinitions } from '../functions/create-prompt-definitions.function.ts';
|
|
7
|
+
import { handlePromptGet } from '../functions/handle-prompt-get.function.ts';
|
|
8
|
+
import { handleCompletion } from '../functions/handle-completion.function.ts';
|
|
9
|
+
import { handleRootsList } from '../functions/handle-roots-list.function.ts';
|
|
10
|
+
import { shouldEmitLog } from '../functions/should-emit-log.function.ts';
|
|
11
|
+
import {
|
|
12
|
+
PARSE_ERROR,
|
|
13
|
+
METHOD_NOT_FOUND,
|
|
14
|
+
RESOURCE_NOT_FOUND,
|
|
15
|
+
} from '../constants/mcp-error-codes.constant.ts';
|
|
16
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
17
|
+
import type {
|
|
18
|
+
McpRequest,
|
|
19
|
+
McpResponse,
|
|
20
|
+
} from '../typings/mcp-types.interface.ts';
|
|
21
|
+
import type { McpLogLevel } from '../typings/log-types.interface.ts';
|
|
22
|
+
import type {
|
|
23
|
+
McpCompletionRef,
|
|
24
|
+
McpCompletionArgument,
|
|
25
|
+
} from '../functions/handle-completion.function.ts';
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* MCP server that speaks JSON-RPC 2.0 over stdio. Listens for
|
|
29
|
+
* newline-delimited requests on `process.stdin`, dispatches each
|
|
30
|
+
* to the appropriate knowledge-base operation via
|
|
31
|
+
* `McpWorkerClient`, and writes JSON-RPC responses to
|
|
32
|
+
* `process.stdout`.
|
|
33
|
+
*/
|
|
34
|
+
export class McpServer {
|
|
35
|
+
private readonly client: McpWorkerClient;
|
|
36
|
+
private readonly contextPath: string;
|
|
37
|
+
private initialized = false;
|
|
38
|
+
private hostCapabilities: Record<string, unknown> | null = null;
|
|
39
|
+
private logLevel: McpLogLevel | null = null;
|
|
40
|
+
private readonly subscriptions = new Set<string>();
|
|
41
|
+
private nextRequestId = 1;
|
|
42
|
+
private readonly pendingRequests = new Map<
|
|
43
|
+
number,
|
|
44
|
+
{
|
|
45
|
+
resolve: (value: unknown) => void;
|
|
46
|
+
reject: (reason: unknown) => void;
|
|
47
|
+
timer: ReturnType<typeof setTimeout>;
|
|
48
|
+
}
|
|
49
|
+
>();
|
|
50
|
+
|
|
51
|
+
constructor(client: McpWorkerClient, contextPath?: string) {
|
|
52
|
+
this.client = client;
|
|
53
|
+
this.contextPath = contextPath ?? '';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async listen(): Promise<void> {
|
|
57
|
+
const rl = createInterface({
|
|
58
|
+
input: process.stdin,
|
|
59
|
+
terminal: false,
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
await new Promise<void>((resolve) => {
|
|
63
|
+
rl.on('line', (line) => {
|
|
64
|
+
void this.dispatchLine(line);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
rl.on('close', () => {
|
|
68
|
+
this.client.disconnect();
|
|
69
|
+
resolve();
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
async handleLineForTest(line: string): Promise<McpResponse | null> {
|
|
75
|
+
return this.processLine(line);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Sends a JSON-RPC notification (no `id`, no response
|
|
80
|
+
* expected) to stdout.
|
|
81
|
+
*/
|
|
82
|
+
notify(method: string, params?: Record<string, unknown>): void {
|
|
83
|
+
const notification: Record<string, unknown> = {
|
|
84
|
+
jsonrpc: '2.0',
|
|
85
|
+
method,
|
|
86
|
+
};
|
|
87
|
+
if (params !== undefined) {
|
|
88
|
+
notification['params'] = params;
|
|
89
|
+
}
|
|
90
|
+
process.stdout.write(JSON.stringify(notification) + '\n');
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Emits a log notification if the message severity meets or
|
|
95
|
+
* exceeds the configured log level threshold.
|
|
96
|
+
*/
|
|
97
|
+
log(level: McpLogLevel, message: unknown, logger?: string): void {
|
|
98
|
+
if (this.logLevel === null) return;
|
|
99
|
+
if (!shouldEmitLog(level, this.logLevel)) return;
|
|
100
|
+
this.notify('notifications/message', {
|
|
101
|
+
level,
|
|
102
|
+
logger: logger ?? 'kbdb',
|
|
103
|
+
data: message,
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Sends a JSON-RPC request to the host (server-to-client)
|
|
109
|
+
* and returns a Promise that resolves with the response
|
|
110
|
+
* result. Times out after 30 seconds.
|
|
111
|
+
*/
|
|
112
|
+
sendRequest(
|
|
113
|
+
method: string,
|
|
114
|
+
params: Record<string, unknown>,
|
|
115
|
+
): Promise<unknown> {
|
|
116
|
+
const id = this.nextRequestId++;
|
|
117
|
+
const request = { jsonrpc: '2.0', id, method, params };
|
|
118
|
+
process.stdout.write(JSON.stringify(request) + '\n');
|
|
119
|
+
return new Promise((resolve, reject) => {
|
|
120
|
+
const timer = setTimeout(() => {
|
|
121
|
+
this.pendingRequests.delete(id);
|
|
122
|
+
reject(new Error(`Request ${method} timed out`));
|
|
123
|
+
}, 30000);
|
|
124
|
+
this.pendingRequests.set(id, {
|
|
125
|
+
resolve,
|
|
126
|
+
reject,
|
|
127
|
+
timer,
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* Requests the host to generate text via the sampling
|
|
134
|
+
* capability. Throws if the host did not advertise sampling
|
|
135
|
+
* support during initialization.
|
|
136
|
+
*/
|
|
137
|
+
async requestSampling(
|
|
138
|
+
messages: {
|
|
139
|
+
role: string;
|
|
140
|
+
content: { type: string; text: string };
|
|
141
|
+
}[],
|
|
142
|
+
maxTokens: number,
|
|
143
|
+
): Promise<unknown> {
|
|
144
|
+
if (!this.hostCapabilities?.['sampling']) {
|
|
145
|
+
throw new Error('Host does not support sampling');
|
|
146
|
+
}
|
|
147
|
+
return this.sendRequest('sampling/createMessage', {
|
|
148
|
+
messages,
|
|
149
|
+
maxTokens,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
private async dispatchLine(line: string): Promise<void> {
|
|
154
|
+
const response = await this.processLine(line);
|
|
155
|
+
if (response !== null) {
|
|
156
|
+
this.send(response);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
private async processLine(
|
|
161
|
+
line: string,
|
|
162
|
+
): Promise<McpResponse | null> {
|
|
163
|
+
if (!line.trim()) return null;
|
|
164
|
+
|
|
165
|
+
let parsed: Record<string, unknown>;
|
|
166
|
+
try {
|
|
167
|
+
parsed = JSON.parse(line) as Record<string, unknown>;
|
|
168
|
+
} catch {
|
|
169
|
+
return {
|
|
170
|
+
jsonrpc: '2.0',
|
|
171
|
+
id: 0,
|
|
172
|
+
error: {
|
|
173
|
+
code: PARSE_ERROR,
|
|
174
|
+
message: 'Parse error',
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Incoming response to an outgoing request (sampling)
|
|
180
|
+
if (
|
|
181
|
+
parsed['id'] !== undefined &&
|
|
182
|
+
typeof parsed['method'] !== 'string'
|
|
183
|
+
) {
|
|
184
|
+
const responseId = parsed['id'] as number;
|
|
185
|
+
const pending = this.pendingRequests.get(responseId);
|
|
186
|
+
if (pending) {
|
|
187
|
+
this.pendingRequests.delete(responseId);
|
|
188
|
+
clearTimeout(pending.timer);
|
|
189
|
+
if (parsed['error']) {
|
|
190
|
+
const err = parsed['error'] as {
|
|
191
|
+
message?: string;
|
|
192
|
+
};
|
|
193
|
+
pending.reject(
|
|
194
|
+
new Error(err.message ?? 'Request failed'),
|
|
195
|
+
);
|
|
196
|
+
} else {
|
|
197
|
+
pending.resolve(parsed['result']);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const request = parsed as unknown as McpRequest;
|
|
204
|
+
|
|
205
|
+
if (request.id === undefined) {
|
|
206
|
+
if (
|
|
207
|
+
request.method === 'notifications/initialized' ||
|
|
208
|
+
request.method === 'notifications/cancelled'
|
|
209
|
+
) {
|
|
210
|
+
if (request.method === 'notifications/initialized') {
|
|
211
|
+
this.initialized = true;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const id = request.id;
|
|
218
|
+
|
|
219
|
+
if (
|
|
220
|
+
!this.initialized &&
|
|
221
|
+
request.method !== 'initialize' &&
|
|
222
|
+
request.method !== 'ping'
|
|
223
|
+
) {
|
|
224
|
+
return {
|
|
225
|
+
jsonrpc: '2.0',
|
|
226
|
+
id,
|
|
227
|
+
error: {
|
|
228
|
+
code: RESOURCE_NOT_FOUND,
|
|
229
|
+
message: 'Server not initialized',
|
|
230
|
+
},
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const response = await this.handleRequest(request);
|
|
235
|
+
return response;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private async handleRequest(
|
|
239
|
+
request: McpRequest,
|
|
240
|
+
): Promise<McpResponse> {
|
|
241
|
+
const id = request.id as number | string;
|
|
242
|
+
|
|
243
|
+
switch (request.method) {
|
|
244
|
+
case 'initialize': {
|
|
245
|
+
const params = request.params ?? {};
|
|
246
|
+
const caps = params['capabilities'];
|
|
247
|
+
this.hostCapabilities = caps
|
|
248
|
+
? (caps as Record<string, unknown>)
|
|
249
|
+
: null;
|
|
250
|
+
return {
|
|
251
|
+
jsonrpc: '2.0',
|
|
252
|
+
id,
|
|
253
|
+
result: {
|
|
254
|
+
protocolVersion: '2025-11-25',
|
|
255
|
+
serverInfo: {
|
|
256
|
+
name: 'kbdb',
|
|
257
|
+
version: '0.1.0',
|
|
258
|
+
},
|
|
259
|
+
capabilities: {
|
|
260
|
+
tools: {},
|
|
261
|
+
resources: { subscribe: true },
|
|
262
|
+
prompts: {},
|
|
263
|
+
logging: {},
|
|
264
|
+
completions: {},
|
|
265
|
+
},
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
case 'ping':
|
|
271
|
+
return { jsonrpc: '2.0', id, result: {} };
|
|
272
|
+
|
|
273
|
+
case 'tools/list':
|
|
274
|
+
return {
|
|
275
|
+
jsonrpc: '2.0',
|
|
276
|
+
id,
|
|
277
|
+
result: {
|
|
278
|
+
tools: createToolDefinitions(),
|
|
279
|
+
},
|
|
280
|
+
};
|
|
281
|
+
|
|
282
|
+
case 'resources/list':
|
|
283
|
+
return {
|
|
284
|
+
jsonrpc: '2.0',
|
|
285
|
+
id,
|
|
286
|
+
result: { resources: [] },
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
case 'resources/templates/list':
|
|
290
|
+
return {
|
|
291
|
+
jsonrpc: '2.0',
|
|
292
|
+
id,
|
|
293
|
+
result: {
|
|
294
|
+
resourceTemplates: createResourceTemplates(),
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
|
|
298
|
+
case 'tools/call': {
|
|
299
|
+
const params = request.params ?? {};
|
|
300
|
+
const rawName = params['name'];
|
|
301
|
+
const name = typeof rawName === 'string' ? rawName : '';
|
|
302
|
+
const args = (params['arguments'] ?? {}) as Record<
|
|
303
|
+
string,
|
|
304
|
+
unknown
|
|
305
|
+
>;
|
|
306
|
+
const result = await handleToolCall(
|
|
307
|
+
this.client,
|
|
308
|
+
name,
|
|
309
|
+
args,
|
|
310
|
+
);
|
|
311
|
+
return { jsonrpc: '2.0', id, result };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
case 'resources/read': {
|
|
315
|
+
const params = request.params ?? {};
|
|
316
|
+
const rawUri = params['uri'];
|
|
317
|
+
const uri = typeof rawUri === 'string' ? rawUri : '';
|
|
318
|
+
try {
|
|
319
|
+
const result = await handleResourceRead(
|
|
320
|
+
this.client,
|
|
321
|
+
uri,
|
|
322
|
+
);
|
|
323
|
+
return { jsonrpc: '2.0', id, result };
|
|
324
|
+
} catch (err) {
|
|
325
|
+
return {
|
|
326
|
+
jsonrpc: '2.0',
|
|
327
|
+
id,
|
|
328
|
+
error: {
|
|
329
|
+
code: RESOURCE_NOT_FOUND,
|
|
330
|
+
message:
|
|
331
|
+
err instanceof Error
|
|
332
|
+
? err.message
|
|
333
|
+
: String(err),
|
|
334
|
+
},
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
case 'prompts/list': {
|
|
340
|
+
const skills = await this.client.listByType('skill');
|
|
341
|
+
const agents =
|
|
342
|
+
await this.client.listDocumentsByType('agent');
|
|
343
|
+
const prompts = createPromptDefinitions(skills, agents);
|
|
344
|
+
return {
|
|
345
|
+
jsonrpc: '2.0',
|
|
346
|
+
id,
|
|
347
|
+
result: { prompts },
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
case 'prompts/get': {
|
|
352
|
+
const params = request.params ?? {};
|
|
353
|
+
const name =
|
|
354
|
+
typeof params['name'] === 'string' ? params['name'] : '';
|
|
355
|
+
const promptArgs = (params['arguments'] ?? {}) as Record<
|
|
356
|
+
string,
|
|
357
|
+
string
|
|
358
|
+
>;
|
|
359
|
+
try {
|
|
360
|
+
const messages = await handlePromptGet(
|
|
361
|
+
name,
|
|
362
|
+
promptArgs,
|
|
363
|
+
this.client,
|
|
364
|
+
);
|
|
365
|
+
return {
|
|
366
|
+
jsonrpc: '2.0',
|
|
367
|
+
id,
|
|
368
|
+
result: { messages },
|
|
369
|
+
};
|
|
370
|
+
} catch (err) {
|
|
371
|
+
return {
|
|
372
|
+
jsonrpc: '2.0',
|
|
373
|
+
id,
|
|
374
|
+
error: {
|
|
375
|
+
code: RESOURCE_NOT_FOUND,
|
|
376
|
+
message:
|
|
377
|
+
err instanceof Error
|
|
378
|
+
? err.message
|
|
379
|
+
: String(err),
|
|
380
|
+
},
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
case 'completion/complete': {
|
|
386
|
+
const params = request.params ?? {};
|
|
387
|
+
const ref = params['ref'] as McpCompletionRef;
|
|
388
|
+
const argument = (params['argument'] ?? {
|
|
389
|
+
name: '',
|
|
390
|
+
value: '',
|
|
391
|
+
}) as McpCompletionArgument;
|
|
392
|
+
const result = await handleCompletion(
|
|
393
|
+
ref,
|
|
394
|
+
argument,
|
|
395
|
+
this.client,
|
|
396
|
+
);
|
|
397
|
+
return { jsonrpc: '2.0', id, result };
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
case 'roots/list': {
|
|
401
|
+
const roots = handleRootsList(this.contextPath);
|
|
402
|
+
return {
|
|
403
|
+
jsonrpc: '2.0',
|
|
404
|
+
id,
|
|
405
|
+
result: { roots },
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
case 'logging/setLevel': {
|
|
410
|
+
const params = request.params ?? {};
|
|
411
|
+
const level = params['level'] as McpLogLevel | undefined;
|
|
412
|
+
this.logLevel = level ?? null;
|
|
413
|
+
return { jsonrpc: '2.0', id, result: {} };
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
case 'resources/subscribe': {
|
|
417
|
+
const params = request.params ?? {};
|
|
418
|
+
const uri =
|
|
419
|
+
typeof params['uri'] === 'string' ? params['uri'] : '';
|
|
420
|
+
this.subscriptions.add(uri);
|
|
421
|
+
return { jsonrpc: '2.0', id, result: {} };
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
case 'resources/unsubscribe': {
|
|
425
|
+
const params = request.params ?? {};
|
|
426
|
+
const uri =
|
|
427
|
+
typeof params['uri'] === 'string' ? params['uri'] : '';
|
|
428
|
+
this.subscriptions.delete(uri);
|
|
429
|
+
return { jsonrpc: '2.0', id, result: {} };
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
default:
|
|
433
|
+
return {
|
|
434
|
+
jsonrpc: '2.0',
|
|
435
|
+
id,
|
|
436
|
+
error: {
|
|
437
|
+
code: METHOD_NOT_FOUND,
|
|
438
|
+
message: `Method not found: ` + request.method,
|
|
439
|
+
},
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private send(response: McpResponse): void {
|
|
445
|
+
const json = JSON.stringify(response);
|
|
446
|
+
process.stdout.write(json + '\n');
|
|
447
|
+
}
|
|
448
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JSON-RPC 2.0 parse error code. Returned when the
|
|
3
|
+
* server receives malformed JSON.
|
|
4
|
+
*/
|
|
5
|
+
export const PARSE_ERROR = -32700;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* JSON-RPC 2.0 method not found error code. Returned
|
|
9
|
+
* when the requested method does not exist.
|
|
10
|
+
*/
|
|
11
|
+
export const METHOD_NOT_FOUND = -32601;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* JSON-RPC 2.0 invalid params error code. Returned
|
|
15
|
+
* when method parameters are invalid or missing.
|
|
16
|
+
*/
|
|
17
|
+
export const INVALID_PARAMS = -32602;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* JSON-RPC 2.0 internal error code. Returned when an
|
|
21
|
+
* unexpected server-side error occurs.
|
|
22
|
+
*/
|
|
23
|
+
export const INTERNAL_ERROR = -32603;
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* MCP-specific resource not found error code. Returned
|
|
27
|
+
* when a well-formed URI does not match any resource
|
|
28
|
+
* in the knowledge base.
|
|
29
|
+
*/
|
|
30
|
+
export const RESOURCE_NOT_FOUND = -32002;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { McpServer } from '../classes/mcp-server.class.ts';
|
|
2
|
+
import type { McpWorkerClient } from '../typings/mcp-client.interface.ts';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Factory that constructs a new `McpServer` bound to the given
|
|
6
|
+
* worker client. Call `server.listen()` on the returned instance
|
|
7
|
+
* to start processing stdio input.
|
|
8
|
+
*
|
|
9
|
+
* @param client - worker client providing knowledge-base operations
|
|
10
|
+
* @returns a configured `McpServer` ready to listen
|
|
11
|
+
*/
|
|
12
|
+
export function createMcpServer(client: McpWorkerClient): McpServer {
|
|
13
|
+
return new McpServer(client);
|
|
14
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import type { McpPrompt } from '../typings/prompt-types.interface.ts';
|
|
2
|
+
import type { McpPromptArgument } from '../typings/prompt-types.interface.ts';
|
|
3
|
+
|
|
4
|
+
/** Minimal skill section record shape required by this function. */
|
|
5
|
+
interface SkillSectionRecord {
|
|
6
|
+
/** Knowledge-base identifier of the section. */
|
|
7
|
+
readonly kbid: string;
|
|
8
|
+
/** Human-readable section title used as the prompt name. */
|
|
9
|
+
readonly title: string | null;
|
|
10
|
+
/** JSON-encoded skill definition content. */
|
|
11
|
+
readonly content: string;
|
|
12
|
+
/** Optional human-readable section description. */
|
|
13
|
+
readonly description?: string | null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Minimal document manifest shape required by this function. */
|
|
17
|
+
interface AgentDocumentRecord {
|
|
18
|
+
/** Unique document identifier. */
|
|
19
|
+
readonly docid: string;
|
|
20
|
+
/** Human-readable document title used in the prompt name. */
|
|
21
|
+
readonly title: string;
|
|
22
|
+
/** Ordered section references belonging to the document. */
|
|
23
|
+
readonly sections: readonly {
|
|
24
|
+
readonly kbid: string;
|
|
25
|
+
readonly position: number;
|
|
26
|
+
}[];
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Parses the `arguments` field from a skill's JSON content string.
|
|
31
|
+
*
|
|
32
|
+
* Returns the array of prompt argument definitions when the content
|
|
33
|
+
* is valid JSON with an `arguments` array, or `undefined` when JSON
|
|
34
|
+
* parsing fails or the field is absent.
|
|
35
|
+
*/
|
|
36
|
+
function parseSkillArguments(
|
|
37
|
+
content: string,
|
|
38
|
+
): readonly McpPromptArgument[] | undefined {
|
|
39
|
+
try {
|
|
40
|
+
const parsed = JSON.parse(content) as Record<string, unknown>;
|
|
41
|
+
if (!Array.isArray(parsed['arguments'])) {
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return (parsed['arguments'] as Record<string, unknown>[]).map(
|
|
45
|
+
(arg) => ({
|
|
46
|
+
name: typeof arg['name'] === 'string' ? arg['name'] : '',
|
|
47
|
+
description:
|
|
48
|
+
typeof arg['description'] === 'string'
|
|
49
|
+
? arg['description']
|
|
50
|
+
: undefined,
|
|
51
|
+
required:
|
|
52
|
+
typeof arg['required'] === 'boolean'
|
|
53
|
+
? arg['required']
|
|
54
|
+
: undefined,
|
|
55
|
+
}),
|
|
56
|
+
);
|
|
57
|
+
} catch {
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Builds the list of MCP prompt definitions from skill sections and
|
|
64
|
+
* agent document manifests stored in the knowledge base.
|
|
65
|
+
*
|
|
66
|
+
* Skills are mapped first (in input order), followed by agents.
|
|
67
|
+
* Each skill becomes a prompt whose name is the section title and
|
|
68
|
+
* whose arguments are extracted from the JSON content. Each agent
|
|
69
|
+
* becomes a prompt prefixed with `"agent:"` and carries an empty
|
|
70
|
+
* arguments array.
|
|
71
|
+
*
|
|
72
|
+
* @param skills - skill section records from `listByType('skill')`
|
|
73
|
+
* @param agents - agent document manifests from
|
|
74
|
+
* `listDocumentsByType('agent')`
|
|
75
|
+
* @returns ordered list of MCP prompt definitions
|
|
76
|
+
*/
|
|
77
|
+
export function createPromptDefinitions(
|
|
78
|
+
skills: readonly SkillSectionRecord[],
|
|
79
|
+
agents: readonly AgentDocumentRecord[],
|
|
80
|
+
): McpPrompt[] {
|
|
81
|
+
const skillPrompts: McpPrompt[] = skills
|
|
82
|
+
.filter(
|
|
83
|
+
(r): r is SkillSectionRecord & { title: string } =>
|
|
84
|
+
r.title !== null,
|
|
85
|
+
)
|
|
86
|
+
.map((record) => {
|
|
87
|
+
const args = parseSkillArguments(record.content);
|
|
88
|
+
const prompt: McpPrompt = {
|
|
89
|
+
name: record.title,
|
|
90
|
+
description: record.description ?? undefined,
|
|
91
|
+
arguments: args,
|
|
92
|
+
};
|
|
93
|
+
return prompt;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
const agentPrompts: McpPrompt[] = agents.map((doc) => ({
|
|
97
|
+
name: `agent:${doc.title}`,
|
|
98
|
+
arguments: [],
|
|
99
|
+
}));
|
|
100
|
+
|
|
101
|
+
return [...skillPrompts, ...agentPrompts];
|
|
102
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { McpResourceTemplate } from '../typings/mcp-types.interface.ts';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns the list of MCP resource URI templates served by the
|
|
5
|
+
* knowledge-base server. Each template describes the URI pattern,
|
|
6
|
+
* human-readable metadata, and the MIME type of the resource body.
|
|
7
|
+
*/
|
|
8
|
+
export function createResourceTemplates(): McpResourceTemplate[] {
|
|
9
|
+
return [
|
|
10
|
+
{
|
|
11
|
+
uriTemplate: 'kbdb://section/{kb_id}',
|
|
12
|
+
name: 'Section',
|
|
13
|
+
description: 'A knowledge base section by its kb-id.',
|
|
14
|
+
mimeType: 'text/plain',
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
uriTemplate: 'kbdb://document/{doc_id}',
|
|
18
|
+
name: 'Document',
|
|
19
|
+
description: 'A document with its ordered sections.',
|
|
20
|
+
mimeType: 'application/json',
|
|
21
|
+
},
|
|
22
|
+
];
|
|
23
|
+
}
|