@casys/mcp-server 0.26.1 → 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 +15 -4
- 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 -24
- 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 -4595
- 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 -54
- package/src/mrtr/replay-store.ts +0 -103
- package/src/mrtr/request-state.ts +0 -435
- package/src/mrtr/retry-guard.ts +0 -110
- 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/transport/request-headers.ts +0 -661
- package/src/types.ts +0 -908
- package/src/ui/viewer-utils.ts +0 -117
- package/src/validation/schema-validator.ts +0 -307
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Request Queue with Concurrency Control and Backpressure
|
|
3
|
-
*
|
|
4
|
-
* Limits the number of concurrent requests to prevent resource exhaustion
|
|
5
|
-
* and implements backpressure strategies when at capacity.
|
|
6
|
-
*
|
|
7
|
-
* @module lib/server/request-queue
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
|
-
import type { QueueMetrics, QueueOptions } from "../types.js";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* RequestQueue manages concurrent request execution with backpressure
|
|
14
|
-
*
|
|
15
|
-
* Features:
|
|
16
|
-
* - Limits max concurrent requests (default: 10)
|
|
17
|
-
* - Multiple backpressure strategies: sleep, queue, reject
|
|
18
|
-
* - Metrics for monitoring (inFlight, queued)
|
|
19
|
-
* - Graceful degradation under load
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```typescript
|
|
23
|
-
* const queue = new RequestQueue({
|
|
24
|
-
* maxConcurrent: 5,
|
|
25
|
-
* strategy: 'queue',
|
|
26
|
-
* sleepMs: 10
|
|
27
|
-
* });
|
|
28
|
-
*
|
|
29
|
-
* await queue.acquire();
|
|
30
|
-
* try {
|
|
31
|
-
* // Execute request
|
|
32
|
-
* } finally {
|
|
33
|
-
* queue.release();
|
|
34
|
-
* }
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export class RequestQueue {
|
|
38
|
-
private inFlight = 0;
|
|
39
|
-
private maxConcurrent: number;
|
|
40
|
-
private strategy: "sleep" | "queue" | "reject";
|
|
41
|
-
private sleepMs: number;
|
|
42
|
-
private waitQueue: Array<() => void> = [];
|
|
43
|
-
|
|
44
|
-
constructor(options: QueueOptions) {
|
|
45
|
-
this.maxConcurrent = options.maxConcurrent;
|
|
46
|
-
this.strategy = options.strategy;
|
|
47
|
-
this.sleepMs = options.sleepMs;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Acquire a slot for request execution
|
|
52
|
-
* Blocks until a slot is available based on backpressure strategy
|
|
53
|
-
*
|
|
54
|
-
* @throws {Error} If strategy is 'reject' and queue is at capacity
|
|
55
|
-
*/
|
|
56
|
-
async acquire(): Promise<void> {
|
|
57
|
-
if (this.strategy === "reject") {
|
|
58
|
-
// Fail fast - reject immediately if at capacity
|
|
59
|
-
if (this.inFlight >= this.maxConcurrent) {
|
|
60
|
-
throw new Error(
|
|
61
|
-
`Server at capacity (${this.maxConcurrent} concurrent requests)`,
|
|
62
|
-
);
|
|
63
|
-
}
|
|
64
|
-
this.inFlight++;
|
|
65
|
-
return;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (this.strategy === "queue") {
|
|
69
|
-
// Queue-based backpressure - wait in FIFO queue.
|
|
70
|
-
// Claim the slot BEFORE awaiting to prevent TOCTOU race:
|
|
71
|
-
// without this, two waiters woken back-to-back could both see
|
|
72
|
-
// inFlight < maxConcurrent and both increment past the limit.
|
|
73
|
-
if (this.inFlight >= this.maxConcurrent) {
|
|
74
|
-
await new Promise<void>((resolve) => {
|
|
75
|
-
this.waitQueue.push(resolve);
|
|
76
|
-
});
|
|
77
|
-
// Slot was pre-claimed by release() before waking us
|
|
78
|
-
} else {
|
|
79
|
-
this.inFlight++;
|
|
80
|
-
}
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
// Sleep-based backpressure (default) - busy-wait with sleep.
|
|
85
|
-
// The check + increment is safe here because JS is single-threaded
|
|
86
|
-
// for synchronous code: after the while loop exits, no other code
|
|
87
|
-
// runs before inFlight++ (no await between check and increment).
|
|
88
|
-
while (this.inFlight >= this.maxConcurrent) {
|
|
89
|
-
await new Promise((resolve) => setTimeout(resolve, this.sleepMs));
|
|
90
|
-
}
|
|
91
|
-
this.inFlight++;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Release a slot after request completion
|
|
96
|
-
* Notifies next waiting request if using queue strategy
|
|
97
|
-
*/
|
|
98
|
-
release(): void {
|
|
99
|
-
if (this.strategy === "queue" && this.waitQueue.length > 0) {
|
|
100
|
-
// Transfer the slot directly to the next waiter without decrementing.
|
|
101
|
-
// This prevents the TOCTOU race: the waiter wakes up with
|
|
102
|
-
// the slot already claimed (inFlight unchanged).
|
|
103
|
-
const next = this.waitQueue.shift()!;
|
|
104
|
-
next();
|
|
105
|
-
} else {
|
|
106
|
-
this.inFlight--;
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Get current queue metrics for monitoring
|
|
112
|
-
*/
|
|
113
|
-
getMetrics(): QueueMetrics {
|
|
114
|
-
return {
|
|
115
|
-
inFlight: this.inFlight,
|
|
116
|
-
queued: this.waitQueue.length,
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* Check if queue is at capacity
|
|
122
|
-
*/
|
|
123
|
-
isAtCapacity(): boolean {
|
|
124
|
-
return this.inFlight >= this.maxConcurrent;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Get current in-flight request count
|
|
129
|
-
*/
|
|
130
|
-
getInFlight(): number {
|
|
131
|
-
return this.inFlight;
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Get current queued request count
|
|
136
|
-
*/
|
|
137
|
-
getQueued(): number {
|
|
138
|
-
return this.waitQueue.length;
|
|
139
|
-
}
|
|
140
|
-
}
|
package/src/http/body.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HTTP body reading, with a size ceiling.
|
|
3
|
-
*
|
|
4
|
-
* Extracted from `mcp-app.ts`: these are pure functions over Web APIs with no
|
|
5
|
-
* dependency on `McpApp` state, which is exactly what made them separable when
|
|
6
|
-
* the dispatch code was not. Keeping them here makes them unit-testable without
|
|
7
|
-
* standing up a server.
|
|
8
|
-
*
|
|
9
|
-
* Not re-exported from `mod.ts` — this is internal.
|
|
10
|
-
*
|
|
11
|
-
* @module lib/server/http/body
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/** Default cap on a request body, in bytes. */
|
|
15
|
-
export const DEFAULT_MAX_BODY_BYTES = 1_000_000;
|
|
16
|
-
|
|
17
|
-
export class BodyTooLargeError extends Error {
|
|
18
|
-
constructor(maxBytes: number) {
|
|
19
|
-
super(`Payload too large. Max ${maxBytes} bytes.`);
|
|
20
|
-
this.name = "BodyTooLargeError";
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export function getClientIpFromHeaders(headers: Headers): string {
|
|
25
|
-
const forwarded = headers.get("x-forwarded-for");
|
|
26
|
-
if (forwarded) {
|
|
27
|
-
return forwarded.split(",")[0]?.trim() || "unknown";
|
|
28
|
-
}
|
|
29
|
-
return headers.get("x-real-ip") ??
|
|
30
|
-
headers.get("cf-connecting-ip") ??
|
|
31
|
-
"unknown";
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
export async function readBodyWithLimit(
|
|
35
|
-
request: Request,
|
|
36
|
-
maxBytes: number | null,
|
|
37
|
-
): Promise<Uint8Array> {
|
|
38
|
-
const contentLength = request.headers.get("content-length");
|
|
39
|
-
if (maxBytes !== null && contentLength) {
|
|
40
|
-
const length = Number(contentLength);
|
|
41
|
-
if (!Number.isNaN(length) && length > maxBytes) {
|
|
42
|
-
throw new BodyTooLargeError(maxBytes);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (!request.body) {
|
|
47
|
-
return new Uint8Array();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const reader = request.body.getReader();
|
|
51
|
-
const chunks: Uint8Array[] = [];
|
|
52
|
-
let total = 0;
|
|
53
|
-
|
|
54
|
-
while (true) {
|
|
55
|
-
const { done, value } = await reader.read();
|
|
56
|
-
if (done) break;
|
|
57
|
-
if (!value) continue;
|
|
58
|
-
total += value.length;
|
|
59
|
-
if (maxBytes !== null && total > maxBytes) {
|
|
60
|
-
throw new BodyTooLargeError(maxBytes);
|
|
61
|
-
}
|
|
62
|
-
chunks.push(value);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
const body = new Uint8Array(total);
|
|
66
|
-
let offset = 0;
|
|
67
|
-
for (const chunk of chunks) {
|
|
68
|
-
body.set(chunk, offset);
|
|
69
|
-
offset += chunk.length;
|
|
70
|
-
}
|
|
71
|
-
return body;
|
|
72
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Request-scoped guards: who is calling, and may they touch this task.
|
|
3
|
-
*
|
|
4
|
-
* Extracted from `mcp-app.ts`. Like `body.ts`, these are pure over their
|
|
5
|
-
* arguments — they read no `McpApp` state — which is what let them move at all.
|
|
6
|
-
* `jsonRpcResponse` stays in `mcp-app.ts` and is passed in rather than imported,
|
|
7
|
-
* so this module has no edge back to the class.
|
|
8
|
-
*
|
|
9
|
-
* Not re-exported from `mod.ts` — internal.
|
|
10
|
-
*
|
|
11
|
-
* @module lib/server/http/request-guards
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
import { ErrorCode } from "@modelcontextprotocol/sdk/types.js";
|
|
15
|
-
import type { AuthInfo } from "./../auth/types.js";
|
|
16
|
-
import type { McpAppOptions } from "./../types.js";
|
|
17
|
-
import { jsonRpcResponse, MRTR_NO_AUTH_PRINCIPAL } from "./wire.js";
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Principal to bind a `requestState` to.
|
|
21
|
-
*
|
|
22
|
-
* Three cases, only two of which are acceptable:
|
|
23
|
-
*
|
|
24
|
-
* 1. **No auth configured** — every caller shares one authority by definition, so
|
|
25
|
-
* there is no boundary to enforce and the sentinel above is honest about it.
|
|
26
|
-
* The method and argument bindings still apply.
|
|
27
|
-
* 2. **Authenticated with a subject** — the binding separates callers, which is
|
|
28
|
-
* the case it exists for.
|
|
29
|
-
* 3. **Authenticated without a usable subject** — `AuthInfo.subject` falls back to
|
|
30
|
-
* `"unknown"` for a valid token carrying no `sub` claim. Sealing against that
|
|
31
|
-
* would put every such caller under one identity: a token minted for one could
|
|
32
|
-
* be spent by another, while the code reads as though the binding were
|
|
33
|
-
* enforced. That is worse than no auth, because it is invisible. Throws.
|
|
34
|
-
*/
|
|
35
|
-
export function callerPrincipal(authInfo: AuthInfo | undefined): string | null {
|
|
36
|
-
if (authInfo === undefined) return MRTR_NO_AUTH_PRINCIPAL;
|
|
37
|
-
const subject = authInfo.subject;
|
|
38
|
-
if (subject === undefined || subject === "" || subject === "unknown") {
|
|
39
|
-
// `null`, not a throw: the task handlers call this outside any try/catch, so
|
|
40
|
-
// a throw would surface through the POST-level catch as -32700 "Parse error"
|
|
41
|
-
// — a diagnosis pointing nowhere near a misconfigured auth provider. The
|
|
42
|
-
// caller turns this into an explicit error instead.
|
|
43
|
-
return null;
|
|
44
|
-
}
|
|
45
|
-
return subject;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Authorization key for a task-related request.
|
|
50
|
-
*
|
|
51
|
-
* Defaults to the authenticated principal. A consumer whose authorization depends
|
|
52
|
-
* on more than identity — a tenant, an organisation, a workspace — supplies
|
|
53
|
-
* `taskOwnerKey` so that dimension becomes part of the key. Without it, binding to
|
|
54
|
-
* the subject alone leaves a task created under one tenant reachable from another
|
|
55
|
-
* by the same user.
|
|
56
|
-
*/
|
|
57
|
-
export async function taskOwnerKeyFor(
|
|
58
|
-
options: McpAppOptions,
|
|
59
|
-
authInfo: AuthInfo | undefined,
|
|
60
|
-
request: Request | undefined,
|
|
61
|
-
principal: string,
|
|
62
|
-
): Promise<string | null> {
|
|
63
|
-
if (options.taskOwnerKey === undefined || request === undefined) {
|
|
64
|
-
return principal;
|
|
65
|
-
}
|
|
66
|
-
let key: unknown;
|
|
67
|
-
try {
|
|
68
|
-
key = await options.taskOwnerKey(authInfo, request);
|
|
69
|
-
} catch {
|
|
70
|
-
// A throwing hook is a consumer bug, but it must fail closed and legibly —
|
|
71
|
-
// not escape to the POST-level catch and be reported as -32700 Parse error.
|
|
72
|
-
return null;
|
|
73
|
-
}
|
|
74
|
-
// An empty or non-string key would put every caller under one owner, undoing
|
|
75
|
-
// the isolation the hook exists to provide — and `""` is exactly what the
|
|
76
|
-
// obvious implementation yields when a header is missing. Refuse it rather
|
|
77
|
-
// than silently sharing tasks between callers.
|
|
78
|
-
if (typeof key !== "string" || key.length === 0) return null;
|
|
79
|
-
return key;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/** The error to return when `taskOwnerKey` produced an unusable value. */
|
|
83
|
-
export function noOwnerKeyError(id: unknown, version: string): Response {
|
|
84
|
-
return jsonRpcResponse(
|
|
85
|
-
{
|
|
86
|
-
jsonrpc: "2.0",
|
|
87
|
-
id,
|
|
88
|
-
error: {
|
|
89
|
-
code: ErrorCode.InternalError,
|
|
90
|
-
message:
|
|
91
|
-
"taskOwnerKey returned an empty or non-string value, which would place every caller under one owner.",
|
|
92
|
-
data: {
|
|
93
|
-
problem: "invalid_task_owner_key",
|
|
94
|
-
recovery:
|
|
95
|
-
'Return a non-empty string. If the value it derives from can be absent, decide explicitly what an anonymous caller\'s key is rather than letting it fall to "".',
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
500,
|
|
100
|
-
{ "MCP-Protocol-Version": version },
|
|
101
|
-
);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/** The error to return when no caller boundary can be established. */
|
|
105
|
-
export function noPrincipalError(id: unknown, version: string): Response {
|
|
106
|
-
return jsonRpcResponse(
|
|
107
|
-
{
|
|
108
|
-
jsonrpc: "2.0",
|
|
109
|
-
id,
|
|
110
|
-
error: {
|
|
111
|
-
code: ErrorCode.InternalError,
|
|
112
|
-
message:
|
|
113
|
-
"Server cannot establish a caller identity: the auth provider returned no usable subject for an authenticated request.",
|
|
114
|
-
data: {
|
|
115
|
-
problem: "no_caller_principal",
|
|
116
|
-
recovery:
|
|
117
|
-
"Configure the auth provider to supply a subject claim, or disable auth if all callers genuinely share one authority.",
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
},
|
|
121
|
-
500,
|
|
122
|
-
{ "MCP-Protocol-Version": version },
|
|
123
|
-
);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/** Lowercase hex encoding, for the requestState nonce. */
|
|
127
|
-
export function bytesToHexLocal(bytes: Uint8Array): string {
|
|
128
|
-
return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
/**
|
|
132
|
-
* Build a JSON-RPC response with an explicit HTTP status.
|
|
133
|
-
*
|
|
134
|
-
* Module-scoped rather than nested in `startHttp`: request-validation helpers on
|
|
135
|
-
* the class need it too, and duplicating the header defaults is how a response
|
|
136
|
-
* ends up missing its Content-Type.
|
|
137
|
-
*/
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MCP Inspector Launcher
|
|
3
|
-
*
|
|
4
|
-
* Launches the official @modelcontextprotocol/inspector to debug
|
|
5
|
-
* and test MCP servers interactively in a browser.
|
|
6
|
-
*
|
|
7
|
-
* Runtime-agnostic: process spawning goes through `node:` builtins, which
|
|
8
|
-
* both Deno (via its Node compat layer) and Node.js support — one code path
|
|
9
|
-
* instead of a per-runtime adapter. The `node:` modules are imported
|
|
10
|
-
* dynamically inside the function bodies so nothing process-related enters
|
|
11
|
-
* the module graph at load time (mod.ts re-exports this module, and its
|
|
12
|
-
* import must stay side-effect free on constrained runtimes like
|
|
13
|
-
* Deno Deploy).
|
|
14
|
-
*
|
|
15
|
-
* Usage from a server script:
|
|
16
|
-
* ```typescript
|
|
17
|
-
* import { launchInspector } from "@casys/mcp-server";
|
|
18
|
-
*
|
|
19
|
-
* if (Deno.args.includes("--inspect")) {
|
|
20
|
-
* await launchInspector("deno", ["run", "--allow-all", "server.ts"]);
|
|
21
|
-
* }
|
|
22
|
-
* ```
|
|
23
|
-
*
|
|
24
|
-
* @module lib/server/inspector/launcher
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
/** Options for the MCP Inspector launcher. */
|
|
28
|
-
export interface InspectorOptions {
|
|
29
|
-
/** Port for the inspector web UI (default: 6274) */
|
|
30
|
-
port?: number;
|
|
31
|
-
/** Automatically open the browser (default: true) */
|
|
32
|
-
open?: boolean;
|
|
33
|
-
/** Environment variables to pass to the MCP server process */
|
|
34
|
-
env?: Record<string, string>;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Launch the MCP Inspector to debug a server.
|
|
39
|
-
*
|
|
40
|
-
* Spawns `npx @modelcontextprotocol/inspector` which:
|
|
41
|
-
* 1. Starts a web UI on the given port (default 6274)
|
|
42
|
-
* 2. Proxies stdio to the MCP server subprocess
|
|
43
|
-
* 3. Allows interactive tool calls, resource browsing, etc.
|
|
44
|
-
*
|
|
45
|
-
* @param serverCommand - Command to start the MCP server (e.g. "deno", "node")
|
|
46
|
-
* @param serverArgs - Arguments for the server command (e.g. ["run", "--allow-all", "server.ts"])
|
|
47
|
-
* @param options - Inspector configuration
|
|
48
|
-
*/
|
|
49
|
-
export async function launchInspector(
|
|
50
|
-
serverCommand: string,
|
|
51
|
-
serverArgs: string[],
|
|
52
|
-
options?: InspectorOptions,
|
|
53
|
-
): Promise<void> {
|
|
54
|
-
const { spawn } = await import("node:child_process");
|
|
55
|
-
const { env, exit } = await import("node:process");
|
|
56
|
-
|
|
57
|
-
const port = options?.port ?? 6274;
|
|
58
|
-
const shouldOpen = options?.open ?? true;
|
|
59
|
-
|
|
60
|
-
// Filter out --inspect from args to avoid recursion
|
|
61
|
-
const filteredArgs = serverArgs.filter((a) => a !== "--inspect");
|
|
62
|
-
|
|
63
|
-
const inspectorEnv: Record<string, string> = {
|
|
64
|
-
...options?.env,
|
|
65
|
-
CLIENT_PORT: String(port),
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
console.error(
|
|
69
|
-
`[mcp-inspector] Starting inspector on http://localhost:${port}`,
|
|
70
|
-
);
|
|
71
|
-
console.error(
|
|
72
|
-
`[mcp-inspector] Server: ${serverCommand} ${filteredArgs.join(" ")}`,
|
|
73
|
-
);
|
|
74
|
-
|
|
75
|
-
// Use npx to run the inspector
|
|
76
|
-
const child = spawn(
|
|
77
|
-
"npx",
|
|
78
|
-
[
|
|
79
|
-
"-y",
|
|
80
|
-
"@modelcontextprotocol/inspector",
|
|
81
|
-
serverCommand,
|
|
82
|
-
...filteredArgs,
|
|
83
|
-
],
|
|
84
|
-
{
|
|
85
|
-
env: { ...env, ...inspectorEnv },
|
|
86
|
-
stdio: "inherit",
|
|
87
|
-
},
|
|
88
|
-
);
|
|
89
|
-
|
|
90
|
-
// Open browser after a short delay
|
|
91
|
-
if (shouldOpen) {
|
|
92
|
-
setTimeout(() => {
|
|
93
|
-
openBrowser(`http://localhost:${port}`).catch(() => {
|
|
94
|
-
// Ignore — user can open manually
|
|
95
|
-
});
|
|
96
|
-
}, 2000);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// Wait for the inspector process to exit
|
|
100
|
-
const code = await new Promise<number>((resolve, reject) => {
|
|
101
|
-
child.on("error", reject);
|
|
102
|
-
child.on("exit", (exitCode) => resolve(exitCode ?? 1));
|
|
103
|
-
});
|
|
104
|
-
if (code !== 0) {
|
|
105
|
-
console.error(`[mcp-inspector] Inspector exited with code ${code}`);
|
|
106
|
-
exit(code);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Open a URL in the default browser (cross-platform).
|
|
112
|
-
*/
|
|
113
|
-
async function openBrowser(url: string): Promise<void> {
|
|
114
|
-
const { spawn } = await import("node:child_process");
|
|
115
|
-
const { platform } = await import("node:process");
|
|
116
|
-
|
|
117
|
-
let cmd: string[];
|
|
118
|
-
if (platform === "darwin") {
|
|
119
|
-
cmd = ["open", url];
|
|
120
|
-
} else if (platform === "win32") {
|
|
121
|
-
cmd = ["cmd", "/c", "start", url];
|
|
122
|
-
} else {
|
|
123
|
-
cmd = ["xdg-open", url];
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const child = spawn(cmd[0], cmd.slice(1), { stdio: "ignore" });
|
|
127
|
-
await new Promise<void>((resolve, reject) => {
|
|
128
|
-
child.on("error", reject);
|
|
129
|
-
child.on("exit", () => resolve());
|
|
130
|
-
});
|
|
131
|
-
}
|