@casys/mcp-server 0.26.0 → 0.27.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/CHANGELOG.md +1779 -0
- package/LICENSE +21 -0
- package/README.md +19 -5
- package/esm/_dnt.polyfills.d.ts +12 -0
- package/esm/_dnt.polyfills.d.ts.map +1 -0
- package/esm/_dnt.polyfills.js +15 -0
- package/esm/_dnt.shims.d.ts +2 -0
- package/esm/_dnt.shims.d.ts.map +1 -0
- package/esm/_dnt.shims.js +57 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts +33 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.js +48 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts +106 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.js +636 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts +67 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.js +1393 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts +44 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.js +117 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.js +103 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.js +32 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.js +96 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.js +159 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.js +14 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.js +10 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.js +22 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.js +29 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.js +19 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.js +30 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.js +10 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.js +14 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.js +9 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.js +81 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts +3 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.js +20 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts +32 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.js +6 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts +4 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.js +13 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts +51 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.js +53 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts +79 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.js +91 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts +100 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.js +33 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts +111 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts.map +1 -0
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.js +104 -0
- package/esm/mod.d.ts +102 -0
- package/esm/mod.d.ts.map +1 -0
- package/esm/mod.js +103 -0
- package/esm/package.json +3 -0
- package/esm/src/auth/as-metadata-proxy.d.ts +112 -0
- package/esm/src/auth/as-metadata-proxy.d.ts.map +1 -0
- package/esm/src/auth/as-metadata-proxy.js +171 -0
- package/esm/src/auth/config.d.ts +117 -0
- package/esm/src/auth/config.d.ts.map +1 -0
- package/esm/src/auth/config.js +219 -0
- package/esm/src/auth/jwt-provider.d.ts +157 -0
- package/esm/src/auth/jwt-provider.d.ts.map +1 -0
- package/esm/src/auth/jwt-provider.js +187 -0
- package/esm/src/auth/middleware.d.ts +61 -0
- package/esm/src/auth/middleware.d.ts.map +1 -0
- package/esm/src/auth/middleware.js +209 -0
- package/esm/src/auth/mod.d.ts +23 -0
- package/esm/src/auth/mod.d.ts.map +1 -0
- package/esm/src/auth/mod.js +27 -0
- package/esm/src/auth/multi-tenant-middleware.d.ts +131 -0
- package/esm/src/auth/multi-tenant-middleware.d.ts.map +1 -0
- package/esm/src/auth/multi-tenant-middleware.js +128 -0
- package/esm/src/auth/presets.d.ts +231 -0
- package/esm/src/auth/presets.d.ts.map +1 -0
- package/esm/src/auth/presets.js +223 -0
- package/{src/auth/provider.ts → esm/src/auth/provider.d.ts} +13 -15
- package/esm/src/auth/provider.d.ts.map +1 -0
- package/esm/src/auth/provider.js +34 -0
- package/esm/src/auth/scope-middleware.d.ts +30 -0
- package/esm/src/auth/scope-middleware.d.ts.map +1 -0
- package/esm/src/auth/scope-middleware.js +48 -0
- package/esm/src/auth/static-token-provider.d.ts +155 -0
- package/esm/src/auth/static-token-provider.d.ts.map +1 -0
- package/esm/src/auth/static-token-provider.js +256 -0
- package/esm/src/auth/types.d.ts +151 -0
- package/esm/src/auth/types.d.ts.map +1 -0
- package/esm/src/auth/types.js +64 -0
- package/esm/src/client-auth/callback-server.d.ts +34 -0
- package/esm/src/client-auth/callback-server.d.ts.map +1 -0
- package/esm/src/client-auth/callback-server.js +141 -0
- package/esm/src/client-auth/client-id-metadata.d.ts +29 -0
- package/esm/src/client-auth/client-id-metadata.d.ts.map +1 -0
- package/esm/src/client-auth/client-id-metadata.js +149 -0
- package/esm/src/client-auth/connect.d.ts +32 -0
- package/esm/src/client-auth/connect.d.ts.map +1 -0
- package/esm/src/client-auth/connect.js +47 -0
- package/esm/src/client-auth/mod.d.ts +19 -0
- package/esm/src/client-auth/mod.d.ts.map +1 -0
- package/{src/client-auth/mod.ts → esm/src/client-auth/mod.js} +1 -26
- package/esm/src/client-auth/provider.d.ts +78 -0
- package/esm/src/client-auth/provider.d.ts.map +1 -0
- package/esm/src/client-auth/provider.js +246 -0
- package/esm/src/client-auth/token-store/file-store.d.ts +20 -0
- package/esm/src/client-auth/token-store/file-store.d.ts.map +1 -0
- package/esm/src/client-auth/token-store/file-store.js +62 -0
- package/esm/src/client-auth/token-store/memory-store.d.ts +14 -0
- package/esm/src/client-auth/token-store/memory-store.d.ts.map +1 -0
- package/esm/src/client-auth/token-store/memory-store.js +25 -0
- package/esm/src/client-auth/types.d.ts +89 -0
- package/esm/src/client-auth/types.d.ts.map +1 -0
- package/esm/src/client-auth/types.js +10 -0
- package/esm/src/concurrency/rate-limiter.d.ts +87 -0
- package/esm/src/concurrency/rate-limiter.d.ts.map +1 -0
- package/esm/src/concurrency/rate-limiter.js +165 -0
- package/esm/src/concurrency/request-queue.d.ts +71 -0
- package/esm/src/concurrency/request-queue.d.ts.map +1 -0
- package/esm/src/concurrency/request-queue.js +128 -0
- package/esm/src/http/body.d.ts +20 -0
- package/esm/src/http/body.d.ts.map +1 -0
- package/esm/src/http/body.js +63 -0
- package/esm/src/http/request-guards.d.ts +54 -0
- package/esm/src/http/request-guards.d.ts.map +1 -0
- package/esm/src/http/request-guards.js +114 -0
- package/esm/src/http/wire.d.ts +26 -0
- package/esm/src/http/wire.d.ts.map +1 -0
- package/{src/http/wire.ts → esm/src/http/wire.js} +13 -19
- package/esm/src/inspector/launcher.d.ts +48 -0
- package/esm/src/inspector/launcher.d.ts.map +1 -0
- package/esm/src/inspector/launcher.js +100 -0
- package/esm/src/mcp-app.d.ts +728 -0
- package/esm/src/mcp-app.d.ts.map +1 -0
- package/esm/src/mcp-app.js +3530 -0
- package/{src/middleware/backpressure.ts → esm/src/middleware/backpressure.d.ts} +2 -14
- package/esm/src/middleware/backpressure.d.ts.map +1 -0
- package/esm/src/middleware/backpressure.js +31 -0
- package/esm/src/middleware/mod.d.ts +11 -0
- package/esm/src/middleware/mod.d.ts.map +1 -0
- package/{src/middleware/mod.ts → esm/src/middleware/mod.js} +0 -10
- package/{src/middleware/rate-limit.ts → esm/src/middleware/rate-limit.d.ts} +2 -25
- package/esm/src/middleware/rate-limit.d.ts.map +1 -0
- package/esm/src/middleware/rate-limit.js +33 -0
- package/esm/src/middleware/runner.d.ts +32 -0
- package/esm/src/middleware/runner.d.ts.map +1 -0
- package/esm/src/middleware/runner.js +49 -0
- package/esm/src/middleware/types.d.ts +76 -0
- package/esm/src/middleware/types.d.ts.map +1 -0
- package/esm/src/middleware/types.js +9 -0
- package/esm/src/middleware/validation.d.ts +24 -0
- package/esm/src/middleware/validation.d.ts.map +1 -0
- package/esm/src/middleware/validation.js +30 -0
- package/esm/src/mrtr/capability-check.d.ts +75 -0
- package/esm/src/mrtr/capability-check.d.ts.map +1 -0
- package/esm/src/mrtr/capability-check.js +233 -0
- package/esm/src/mrtr/mod.d.ts +18 -0
- package/esm/src/mrtr/mod.d.ts.map +1 -0
- package/esm/src/mrtr/mod.js +12 -0
- package/esm/src/mrtr/replay-store.d.ts +50 -0
- package/esm/src/mrtr/replay-store.d.ts.map +1 -0
- package/esm/src/mrtr/replay-store.js +61 -0
- package/esm/src/mrtr/request-state.d.ts +181 -0
- package/esm/src/mrtr/request-state.d.ts.map +1 -0
- package/esm/src/mrtr/request-state.js +313 -0
- package/esm/src/mrtr/retry-guard.d.ts +61 -0
- package/esm/src/mrtr/retry-guard.d.ts.map +1 -0
- package/esm/src/mrtr/retry-guard.js +53 -0
- package/esm/src/mrtr/types.d.ts +99 -0
- package/esm/src/mrtr/types.d.ts.map +1 -0
- package/esm/src/mrtr/types.js +14 -0
- package/esm/src/observability/metrics.d.ts +104 -0
- package/esm/src/observability/metrics.d.ts.map +1 -0
- package/esm/src/observability/metrics.js +207 -0
- package/{src/observability/mod.ts → esm/src/observability/mod.d.ts} +2 -11
- package/esm/src/observability/mod.d.ts.map +1 -0
- package/esm/src/observability/mod.js +11 -0
- package/esm/src/observability/otel.d.ts +73 -0
- package/esm/src/observability/otel.d.ts.map +1 -0
- package/esm/src/observability/otel.js +260 -0
- package/esm/src/runtime/runtime.d.ts +10 -0
- package/esm/src/runtime/runtime.d.ts.map +1 -0
- package/esm/src/runtime/runtime.deno.d.ts +50 -0
- package/esm/src/runtime/runtime.deno.d.ts.map +1 -0
- package/esm/src/runtime/runtime.deno.js +120 -0
- package/{src/runtime/runtime.ts → esm/src/runtime/runtime.js} +5 -14
- package/esm/src/runtime/runtime.node.d.ts +51 -0
- package/esm/src/runtime/runtime.node.d.ts.map +1 -0
- package/esm/src/runtime/runtime.node.js +268 -0
- package/{src/runtime/types.ts → esm/src/runtime/types.d.ts} +28 -51
- package/esm/src/runtime/types.d.ts.map +1 -0
- package/esm/src/runtime/types.js +12 -0
- package/esm/src/security/channel-hmac.d.ts +43 -0
- package/esm/src/security/channel-hmac.d.ts.map +1 -0
- package/{src/security/channel-hmac.ts → esm/src/security/channel-hmac.js} +12 -17
- package/esm/src/security/csp.d.ts +50 -0
- package/esm/src/security/csp.d.ts.map +1 -0
- package/esm/src/security/csp.js +63 -0
- package/esm/src/security/message-signer.d.ts +88 -0
- package/esm/src/security/message-signer.d.ts.map +1 -0
- package/esm/src/security/message-signer.js +166 -0
- package/esm/src/subscriptions/subscription-registry.d.ts +256 -0
- package/esm/src/subscriptions/subscription-registry.d.ts.map +1 -0
- package/esm/src/subscriptions/subscription-registry.js +406 -0
- package/{src/tasks/mod.ts → esm/src/tasks/mod.d.ts} +3 -23
- package/esm/src/tasks/mod.d.ts.map +1 -0
- package/esm/src/tasks/mod.js +11 -0
- package/esm/src/tasks/task-store.d.ts +342 -0
- package/esm/src/tasks/task-store.d.ts.map +1 -0
- package/esm/src/tasks/task-store.js +649 -0
- package/esm/src/transport/request-headers.d.ts +145 -0
- package/esm/src/transport/request-headers.d.ts.map +1 -0
- package/esm/src/transport/request-headers.js +525 -0
- package/esm/src/types.d.ts +776 -0
- package/esm/src/types.d.ts.map +1 -0
- package/esm/src/types.js +92 -0
- package/esm/src/ui/viewer-utils.d.ts +45 -0
- package/esm/src/ui/viewer-utils.d.ts.map +1 -0
- package/esm/src/ui/viewer-utils.js +97 -0
- package/esm/src/validation/schema-validator.d.ts +115 -0
- package/esm/src/validation/schema-validator.d.ts.map +1 -0
- package/esm/src/validation/schema-validator.js +249 -0
- package/package.json +35 -23
- package/mod.ts +0 -302
- package/src/auth/as-metadata-proxy.ts +0 -288
- package/src/auth/config.ts +0 -368
- package/src/auth/jwt-provider.ts +0 -327
- package/src/auth/middleware.ts +0 -257
- package/src/auth/mod.ts +0 -89
- package/src/auth/multi-tenant-middleware.ts +0 -236
- package/src/auth/presets.ts +0 -351
- package/src/auth/scope-middleware.ts +0 -59
- package/src/auth/static-token-provider.ts +0 -197
- package/src/auth/types.ts +0 -207
- package/src/client-auth/callback-server.ts +0 -166
- package/src/client-auth/client-id-metadata.ts +0 -260
- package/src/client-auth/connect.ts +0 -72
- package/src/client-auth/provider.ts +0 -300
- package/src/client-auth/token-store/file-store.ts +0 -73
- package/src/client-auth/token-store/memory-store.ts +0 -32
- package/src/client-auth/types.ts +0 -95
- package/src/concurrency/rate-limiter.ts +0 -190
- package/src/concurrency/request-queue.ts +0 -140
- package/src/http/body.ts +0 -72
- package/src/http/request-guards.ts +0 -137
- package/src/inspector/launcher.ts +0 -131
- package/src/mcp-app.ts +0 -4426
- package/src/middleware/runner.ts +0 -63
- package/src/middleware/types.ts +0 -104
- package/src/middleware/validation.ts +0 -28
- package/src/mrtr/capability-check.ts +0 -303
- package/src/mrtr/mod.ts +0 -46
- package/src/mrtr/replay-store.ts +0 -103
- package/src/mrtr/request-state.ts +0 -435
- package/src/mrtr/types.ts +0 -107
- package/src/observability/metrics.ts +0 -336
- package/src/observability/otel.ts +0 -330
- package/src/runtime/runtime.deno.ts +0 -149
- package/src/runtime/runtime.node.ts +0 -324
- package/src/security/csp.ts +0 -89
- package/src/security/message-signer.ts +0 -223
- package/src/subscriptions/subscription-registry.ts +0 -558
- package/src/tasks/task-store.ts +0 -1014
- package/src/testdata/stdio-e2e-server.ts +0 -110
- package/src/transport/request-headers.ts +0 -661
- package/src/types.ts +0 -907
- package/src/ui/viewer-utils.ts +0 -117
- package/src/validation/schema-validator.ts +0 -307
package/src/ui/viewer-utils.ts
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Apps Viewer Utilities
|
|
3
|
-
*
|
|
4
|
-
* Shared functions for resolving viewer dist paths and discovering
|
|
5
|
-
* viewer directories. Used by registerViewers() and the build pipeline.
|
|
6
|
-
*
|
|
7
|
-
* @module lib/server/src/ui/viewer-utils
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
/** Directories to skip during auto-discovery */
|
|
11
|
-
const SKIP_DIRS = new Set([
|
|
12
|
-
"shared",
|
|
13
|
-
"dist",
|
|
14
|
-
"node_modules",
|
|
15
|
-
".cache",
|
|
16
|
-
".vite",
|
|
17
|
-
]);
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Convert a file:// URL to a filesystem path.
|
|
21
|
-
* Handles Windows drive letters and UNC paths.
|
|
22
|
-
*/
|
|
23
|
-
function fileUrlToPath(url: URL): string {
|
|
24
|
-
const decoded = decodeURIComponent(url.pathname);
|
|
25
|
-
// Windows: /C:/path → C:/path
|
|
26
|
-
if (/^\/[A-Za-z]:\//.test(decoded)) return decoded.slice(1);
|
|
27
|
-
// UNC: //host/share
|
|
28
|
-
if (url.host.length > 0) return `//${url.host}${decoded}`;
|
|
29
|
-
return decoded;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Resolve the dist path for a viewer's built index.html.
|
|
34
|
-
*
|
|
35
|
-
* Checks two candidate locations relative to the module URL:
|
|
36
|
-
* 1. ./src/ui/dist/{viewerName}/index.html (Deno dev)
|
|
37
|
-
* 2. ./ui-dist/{viewerName}/index.html (npm package)
|
|
38
|
-
*
|
|
39
|
-
* @param moduleUrl - import.meta.url of the consumer's server.ts
|
|
40
|
-
* @param viewerName - Viewer directory name (e.g. "invoice-viewer")
|
|
41
|
-
* @param exists - Function to check if a path exists (injectable for tests)
|
|
42
|
-
* @returns Absolute path to index.html, or null if not found
|
|
43
|
-
*/
|
|
44
|
-
export function resolveViewerDistPath(
|
|
45
|
-
moduleUrl: string,
|
|
46
|
-
viewerName: string,
|
|
47
|
-
exists: (path: string) => boolean,
|
|
48
|
-
): string | null {
|
|
49
|
-
// When consumed from JSR or any remote registry, import.meta.url is an
|
|
50
|
-
// HTTPS URL. fileUrlToPath() only handles file:// — passing an HTTPS URL
|
|
51
|
-
// produces a broken UNC-like path ("//jsr.io/..."). Return the raw resolved
|
|
52
|
-
// URL string instead; the caller's exists/readFile callbacks are responsible
|
|
53
|
-
// for handling remote URLs (e.g., via fetch()).
|
|
54
|
-
if (moduleUrl.startsWith("https://") || moduleUrl.startsWith("http://")) {
|
|
55
|
-
const candidates = [
|
|
56
|
-
new URL(`./src/ui/dist/${viewerName}/index.html`, moduleUrl).href,
|
|
57
|
-
new URL(`./ui-dist/${viewerName}/index.html`, moduleUrl).href,
|
|
58
|
-
];
|
|
59
|
-
for (const candidate of candidates) {
|
|
60
|
-
if (exists(candidate)) return candidate;
|
|
61
|
-
}
|
|
62
|
-
return null;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const candidates = [
|
|
66
|
-
fileUrlToPath(new URL(`./src/ui/dist/${viewerName}/index.html`, moduleUrl)),
|
|
67
|
-
fileUrlToPath(new URL(`./ui-dist/${viewerName}/index.html`, moduleUrl)),
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
for (const candidate of candidates) {
|
|
71
|
-
if (exists(candidate)) return candidate;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
/** Minimal entry returned by a directory reader */
|
|
78
|
-
export interface DirEntry {
|
|
79
|
-
name: string;
|
|
80
|
-
isDirectory: boolean;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** Injectable filesystem operations for discoverViewers */
|
|
84
|
-
export interface DiscoverViewersFS {
|
|
85
|
-
readDir: (path: string) => DirEntry[];
|
|
86
|
-
hasIndexHtml: (uiDir: string, viewerName: string) => boolean;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Auto-discover viewer directories inside a UI root folder.
|
|
91
|
-
*
|
|
92
|
-
* A viewer is a directory that:
|
|
93
|
-
* - Is not in the skip list (shared, dist, node_modules, .cache, .vite)
|
|
94
|
-
* - Does not start with "."
|
|
95
|
-
* - Contains an index.html file
|
|
96
|
-
*
|
|
97
|
-
* @param uiDir - Absolute path to the UI root directory
|
|
98
|
-
* @param fs - Injectable filesystem operations
|
|
99
|
-
* @returns Sorted array of viewer names
|
|
100
|
-
*/
|
|
101
|
-
export function discoverViewers(
|
|
102
|
-
uiDir: string,
|
|
103
|
-
fs: DiscoverViewersFS,
|
|
104
|
-
): string[] {
|
|
105
|
-
const entries = fs.readDir(uiDir);
|
|
106
|
-
const viewers: string[] = [];
|
|
107
|
-
|
|
108
|
-
for (const entry of entries) {
|
|
109
|
-
if (!entry.isDirectory) continue;
|
|
110
|
-
if (entry.name.startsWith(".")) continue;
|
|
111
|
-
if (SKIP_DIRS.has(entry.name)) continue;
|
|
112
|
-
if (!fs.hasIndexHtml(uiDir, entry.name)) continue;
|
|
113
|
-
viewers.push(entry.name);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
return viewers.sort();
|
|
117
|
-
}
|
|
@@ -1,307 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Schema Validator
|
|
3
|
-
*
|
|
4
|
-
* JSON Schema validation using ajv for MCP tool arguments.
|
|
5
|
-
* Compiles schemas once for optimal performance.
|
|
6
|
-
*
|
|
7
|
-
* @module lib/server/schema-validator
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
// deno-lint-ignore-file no-explicit-any
|
|
11
|
-
// Draft 2020-12, not ajv's default export (draft-07). Spec 2026-07-28
|
|
12
|
-
// (SEP-2106) allows any JSON Schema 2020-12 keyword in `inputSchema` /
|
|
13
|
-
// `outputSchema`, and the draft-07 build treats the keywords added in 2020-12 —
|
|
14
|
-
// `prefixItems`, `unevaluatedProperties`, `unevaluatedItems`, `$dynamicRef` —
|
|
15
|
-
// as unknown. Combined with `strict: false` that failure is silent: the schema
|
|
16
|
-
// compiles, the constraint is never applied, and a violating payload validates
|
|
17
|
-
// clean. A tool author's declared boundary has to actually hold.
|
|
18
|
-
//
|
|
19
|
-
// Spelled as the full `dist/` path, not `ajv/2020`: `build-node.sh` copies
|
|
20
|
-
// import specifiers verbatim into the npm distribution, and ajv 8 ships no
|
|
21
|
-
// `exports` map and no root-level `2020.js`, so `ajv/2020` resolves under
|
|
22
|
-
// Deno's import map and then fails at runtime in Node with ERR_MODULE_NOT_FOUND.
|
|
23
|
-
// This path resolves under both.
|
|
24
|
-
import AjvDefault from "ajv/dist/2020.js";
|
|
25
|
-
|
|
26
|
-
// Get the Ajv constructor (handles ESM/CJS differences)
|
|
27
|
-
const Ajv = (AjvDefault as any).default ?? AjvDefault;
|
|
28
|
-
|
|
29
|
-
// Type definitions for ajv
|
|
30
|
-
interface AjvErrorObject {
|
|
31
|
-
keyword: string;
|
|
32
|
-
instancePath: string;
|
|
33
|
-
schemaPath: string;
|
|
34
|
-
params: Record<string, any>;
|
|
35
|
-
message?: string;
|
|
36
|
-
data?: unknown;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
interface AjvValidateFunction {
|
|
40
|
-
(data: unknown): boolean;
|
|
41
|
-
errors?: AjvErrorObject[] | null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Count with its noun, agreeing in number.
|
|
46
|
-
*
|
|
47
|
-
* A bound of 1 is a legitimate schema (`minItems: 1`), and "must have at least
|
|
48
|
-
* 1 items" reads as a bug in the server rather than a problem with the input.
|
|
49
|
-
*/
|
|
50
|
-
function plural(n: number, singular: string, plural = `${singular}s`): string {
|
|
51
|
-
return `${n} ${n === 1 ? singular : plural}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Validation error with formatted message
|
|
56
|
-
*/
|
|
57
|
-
export interface ValidationError {
|
|
58
|
-
/** Error message */
|
|
59
|
-
message: string;
|
|
60
|
-
/** Path to invalid property */
|
|
61
|
-
path: string;
|
|
62
|
-
/** Invalid value */
|
|
63
|
-
value?: unknown;
|
|
64
|
-
/** Expected type or constraint */
|
|
65
|
-
expected?: string;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Validation result
|
|
70
|
-
*/
|
|
71
|
-
export interface ValidationResult {
|
|
72
|
-
valid: boolean;
|
|
73
|
-
errors: ValidationError[];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Schema validator with compiled schema caching
|
|
78
|
-
*
|
|
79
|
-
* @example
|
|
80
|
-
* ```typescript
|
|
81
|
-
* const validator = new SchemaValidator();
|
|
82
|
-
*
|
|
83
|
-
* // Register tool schema
|
|
84
|
-
* validator.addSchema("my_tool", {
|
|
85
|
-
* type: "object",
|
|
86
|
-
* properties: { count: { type: "number" } },
|
|
87
|
-
* required: ["count"]
|
|
88
|
-
* });
|
|
89
|
-
*
|
|
90
|
-
* // Validate arguments
|
|
91
|
-
* const result = validator.validate("my_tool", { count: 5 });
|
|
92
|
-
* if (!result.valid) {
|
|
93
|
-
* console.error(result.errors);
|
|
94
|
-
* }
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
export class SchemaValidator {
|
|
98
|
-
private ajv: any;
|
|
99
|
-
private validators = new Map<string, AjvValidateFunction>();
|
|
100
|
-
|
|
101
|
-
constructor() {
|
|
102
|
-
this.ajv = new Ajv({
|
|
103
|
-
allErrors: true, // Report all errors, not just first
|
|
104
|
-
strict: false, // Allow additional keywords
|
|
105
|
-
useDefaults: true, // Apply default values
|
|
106
|
-
coerceTypes: false, // Don't coerce types (strict validation)
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Add a schema for a tool
|
|
112
|
-
*
|
|
113
|
-
* @param toolName - Name of the tool
|
|
114
|
-
* @param schema - JSON Schema for tool arguments
|
|
115
|
-
*/
|
|
116
|
-
addSchema(toolName: string, schema: Record<string, unknown>): void {
|
|
117
|
-
// Compile and cache the validator
|
|
118
|
-
const validate = this.ajv.compile(schema);
|
|
119
|
-
this.validators.set(toolName, validate);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* Remove a schema
|
|
124
|
-
*/
|
|
125
|
-
removeSchema(toolName: string): void {
|
|
126
|
-
this.validators.delete(toolName);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Check if a schema exists
|
|
131
|
-
*/
|
|
132
|
-
hasSchema(toolName: string): boolean {
|
|
133
|
-
return this.validators.has(toolName);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Validate arguments against a tool's schema
|
|
138
|
-
*
|
|
139
|
-
* @param toolName - Name of the tool
|
|
140
|
-
* @param args - Arguments to validate
|
|
141
|
-
* @returns Validation result with errors if invalid
|
|
142
|
-
*/
|
|
143
|
-
validate(toolName: string, args: Record<string, unknown>): ValidationResult {
|
|
144
|
-
const validate = this.validators.get(toolName);
|
|
145
|
-
|
|
146
|
-
if (!validate) {
|
|
147
|
-
// No schema registered - pass through
|
|
148
|
-
return { valid: true, errors: [] };
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const valid = validate(args);
|
|
152
|
-
|
|
153
|
-
if (valid) {
|
|
154
|
-
return { valid: true, errors: [] };
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
// Format errors
|
|
158
|
-
const errors = this.formatErrors(validate.errors || []);
|
|
159
|
-
return { valid: false, errors };
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Validate and throw if invalid
|
|
164
|
-
*
|
|
165
|
-
* @throws Error with formatted validation message
|
|
166
|
-
*/
|
|
167
|
-
validateOrThrow(toolName: string, args: Record<string, unknown>): void {
|
|
168
|
-
const result = this.validate(toolName, args);
|
|
169
|
-
|
|
170
|
-
if (!result.valid) {
|
|
171
|
-
const messages = result.errors.map((e) => e.message).join("; ");
|
|
172
|
-
throw new Error(`Invalid arguments for ${toolName}: ${messages}`);
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Format ajv errors into readable messages
|
|
178
|
-
*/
|
|
179
|
-
private formatErrors(errors: AjvErrorObject[]): ValidationError[] {
|
|
180
|
-
return errors.map((error) => {
|
|
181
|
-
const path = error.instancePath || "/";
|
|
182
|
-
const param = error.params;
|
|
183
|
-
|
|
184
|
-
let message: string;
|
|
185
|
-
let expected: string | undefined;
|
|
186
|
-
|
|
187
|
-
switch (error.keyword) {
|
|
188
|
-
case "required":
|
|
189
|
-
message = `Missing required property: ${param.missingProperty}`;
|
|
190
|
-
break;
|
|
191
|
-
|
|
192
|
-
case "type":
|
|
193
|
-
message = `Property ${path} must be ${param.type}`;
|
|
194
|
-
expected = param.type;
|
|
195
|
-
break;
|
|
196
|
-
|
|
197
|
-
case "enum":
|
|
198
|
-
message = `Property ${path} must be one of: ${
|
|
199
|
-
param.allowedValues?.join(", ")
|
|
200
|
-
}`;
|
|
201
|
-
expected = param.allowedValues?.join(" | ");
|
|
202
|
-
break;
|
|
203
|
-
|
|
204
|
-
case "minimum":
|
|
205
|
-
message = `Property ${path} must be >= ${param.limit}`;
|
|
206
|
-
expected = `>= ${param.limit}`;
|
|
207
|
-
break;
|
|
208
|
-
|
|
209
|
-
case "maximum":
|
|
210
|
-
message = `Property ${path} must be <= ${param.limit}`;
|
|
211
|
-
expected = `<= ${param.limit}`;
|
|
212
|
-
break;
|
|
213
|
-
|
|
214
|
-
case "minLength":
|
|
215
|
-
message =
|
|
216
|
-
`Property ${path} must have at least ${param.limit} characters`;
|
|
217
|
-
expected = `length >= ${param.limit}`;
|
|
218
|
-
break;
|
|
219
|
-
|
|
220
|
-
case "maxLength":
|
|
221
|
-
message =
|
|
222
|
-
`Property ${path} must have at most ${param.limit} characters`;
|
|
223
|
-
expected = `length <= ${param.limit}`;
|
|
224
|
-
break;
|
|
225
|
-
|
|
226
|
-
case "pattern":
|
|
227
|
-
message = `Property ${path} must match pattern: ${param.pattern}`;
|
|
228
|
-
expected = param.pattern;
|
|
229
|
-
break;
|
|
230
|
-
|
|
231
|
-
// Collection bounds. ajv enforces these already — what was missing is a
|
|
232
|
-
// message shaped like the others, with a structured `expected`. Without
|
|
233
|
-
// it these fell through to `default` and surfaced ajv's bare prose
|
|
234
|
-
// ("must NOT have more than 8 items"), which states the limit but names
|
|
235
|
-
// neither the property nor an `expected` a caller can act on.
|
|
236
|
-
//
|
|
237
|
-
// `expected` says "items"/"properties" rather than "length": it is read
|
|
238
|
-
// on its own as a recovery hint, where "length <= 8" is indistinguishable
|
|
239
|
-
// from the character bound that minLength/maxLength above produce.
|
|
240
|
-
case "minItems":
|
|
241
|
-
message = `Property ${path} must have at least ${
|
|
242
|
-
plural(param.limit, "item")
|
|
243
|
-
}`;
|
|
244
|
-
expected = `items >= ${param.limit}`;
|
|
245
|
-
break;
|
|
246
|
-
|
|
247
|
-
case "maxItems":
|
|
248
|
-
message = `Property ${path} must have at most ${
|
|
249
|
-
plural(param.limit, "item")
|
|
250
|
-
}`;
|
|
251
|
-
expected = `items <= ${param.limit}`;
|
|
252
|
-
break;
|
|
253
|
-
|
|
254
|
-
case "uniqueItems":
|
|
255
|
-
// ajv reports the two colliding array indices, zero-based, and in
|
|
256
|
-
// either order depending on how it optimised the comparison. The
|
|
257
|
-
// indices are not what is equal — the items at them are.
|
|
258
|
-
message =
|
|
259
|
-
`Property ${path} must not contain duplicate items (items at indices ${param.j} and ${param.i} are equal)`;
|
|
260
|
-
expected = "unique items";
|
|
261
|
-
break;
|
|
262
|
-
|
|
263
|
-
case "minProperties":
|
|
264
|
-
message = `Property ${path} must have at least ${
|
|
265
|
-
plural(param.limit, "property", "properties")
|
|
266
|
-
}`;
|
|
267
|
-
expected = `properties >= ${param.limit}`;
|
|
268
|
-
break;
|
|
269
|
-
|
|
270
|
-
case "maxProperties":
|
|
271
|
-
message = `Property ${path} must have at most ${
|
|
272
|
-
plural(param.limit, "property", "properties")
|
|
273
|
-
}`;
|
|
274
|
-
expected = `properties <= ${param.limit}`;
|
|
275
|
-
break;
|
|
276
|
-
|
|
277
|
-
case "additionalProperties":
|
|
278
|
-
message = `Unknown property: ${param.additionalProperty}`;
|
|
279
|
-
break;
|
|
280
|
-
|
|
281
|
-
default:
|
|
282
|
-
message = error.message || `Validation failed at ${path}`;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
return {
|
|
286
|
-
message,
|
|
287
|
-
path,
|
|
288
|
-
value: error.data,
|
|
289
|
-
expected,
|
|
290
|
-
};
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Get number of registered schemas
|
|
296
|
-
*/
|
|
297
|
-
get count(): number {
|
|
298
|
-
return this.validators.size;
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
/**
|
|
302
|
-
* Clear all schemas
|
|
303
|
-
*/
|
|
304
|
-
clear(): void {
|
|
305
|
-
this.validators.clear();
|
|
306
|
-
}
|
|
307
|
-
}
|