@casys/mcp-server 0.27.0 → 0.27.2
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 +18 -1764
- package/README.md +21 -631
- package/esm/mod.d.ts +1 -102
- package/esm/mod.js +1 -103
- package/package.json +17 -25
- package/esm/_dnt.polyfills.d.ts +0 -12
- package/esm/_dnt.polyfills.d.ts.map +0 -1
- package/esm/_dnt.polyfills.js +0 -15
- package/esm/_dnt.shims.d.ts +0 -2
- package/esm/_dnt.shims.d.ts.map +0 -1
- package/esm/_dnt.shims.js +0 -57
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts +0 -33
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_chars.js +0 -48
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts +0 -106
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_dumper_state.js +0 -636
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts +0 -67
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_loader_state.js +0 -1393
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts +0 -44
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_schema.js +0 -117
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/binary.js +0 -103
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/bool.js +0 -32
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/float.js +0 -96
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/int.js +0 -159
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/map.js +0 -14
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/merge.js +0 -10
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/nil.js +0 -22
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/omap.js +0 -29
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/pairs.js +0 -19
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/regexp.js +0 -30
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/seq.js +0 -10
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/set.js +0 -14
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/str.js +0 -9
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/timestamp.js +0 -81
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts +0 -3
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type/undefined.js +0 -20
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts +0 -32
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_type.js +0 -6
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts +0 -4
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/_utils.js +0 -13
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts +0 -51
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/mod.js +0 -53
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts +0 -79
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/parse.js +0 -91
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts +0 -100
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/stringify.js +0 -33
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts +0 -111
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.d.ts.map +0 -1
- package/esm/deps/jsr.io/@std/yaml/1.2.0/types.js +0 -104
- package/esm/mod.d.ts.map +0 -1
- package/esm/package.json +0 -3
- package/esm/src/auth/as-metadata-proxy.d.ts +0 -112
- package/esm/src/auth/as-metadata-proxy.d.ts.map +0 -1
- package/esm/src/auth/as-metadata-proxy.js +0 -171
- package/esm/src/auth/config.d.ts +0 -117
- package/esm/src/auth/config.d.ts.map +0 -1
- package/esm/src/auth/config.js +0 -219
- package/esm/src/auth/jwt-provider.d.ts +0 -157
- package/esm/src/auth/jwt-provider.d.ts.map +0 -1
- package/esm/src/auth/jwt-provider.js +0 -187
- package/esm/src/auth/middleware.d.ts +0 -61
- package/esm/src/auth/middleware.d.ts.map +0 -1
- package/esm/src/auth/middleware.js +0 -209
- package/esm/src/auth/mod.d.ts +0 -23
- package/esm/src/auth/mod.d.ts.map +0 -1
- package/esm/src/auth/mod.js +0 -27
- package/esm/src/auth/multi-tenant-middleware.d.ts +0 -131
- package/esm/src/auth/multi-tenant-middleware.d.ts.map +0 -1
- package/esm/src/auth/multi-tenant-middleware.js +0 -128
- package/esm/src/auth/presets.d.ts +0 -231
- package/esm/src/auth/presets.d.ts.map +0 -1
- package/esm/src/auth/presets.js +0 -223
- package/esm/src/auth/provider.d.ts +0 -47
- package/esm/src/auth/provider.d.ts.map +0 -1
- package/esm/src/auth/provider.js +0 -34
- package/esm/src/auth/scope-middleware.d.ts +0 -30
- package/esm/src/auth/scope-middleware.d.ts.map +0 -1
- package/esm/src/auth/scope-middleware.js +0 -48
- package/esm/src/auth/static-token-provider.d.ts +0 -155
- package/esm/src/auth/static-token-provider.d.ts.map +0 -1
- package/esm/src/auth/static-token-provider.js +0 -256
- package/esm/src/auth/types.d.ts +0 -151
- package/esm/src/auth/types.d.ts.map +0 -1
- package/esm/src/auth/types.js +0 -64
- package/esm/src/client-auth/callback-server.d.ts +0 -34
- package/esm/src/client-auth/callback-server.d.ts.map +0 -1
- package/esm/src/client-auth/callback-server.js +0 -141
- package/esm/src/client-auth/client-id-metadata.d.ts +0 -29
- package/esm/src/client-auth/client-id-metadata.d.ts.map +0 -1
- package/esm/src/client-auth/client-id-metadata.js +0 -149
- package/esm/src/client-auth/connect.d.ts +0 -32
- package/esm/src/client-auth/connect.d.ts.map +0 -1
- package/esm/src/client-auth/connect.js +0 -47
- package/esm/src/client-auth/mod.d.ts +0 -19
- package/esm/src/client-auth/mod.d.ts.map +0 -1
- package/esm/src/client-auth/mod.js +0 -19
- package/esm/src/client-auth/provider.d.ts +0 -78
- package/esm/src/client-auth/provider.d.ts.map +0 -1
- package/esm/src/client-auth/provider.js +0 -246
- package/esm/src/client-auth/token-store/file-store.d.ts +0 -20
- package/esm/src/client-auth/token-store/file-store.d.ts.map +0 -1
- package/esm/src/client-auth/token-store/file-store.js +0 -62
- package/esm/src/client-auth/token-store/memory-store.d.ts +0 -14
- package/esm/src/client-auth/token-store/memory-store.d.ts.map +0 -1
- package/esm/src/client-auth/token-store/memory-store.js +0 -25
- package/esm/src/client-auth/types.d.ts +0 -89
- package/esm/src/client-auth/types.d.ts.map +0 -1
- package/esm/src/client-auth/types.js +0 -10
- package/esm/src/concurrency/rate-limiter.d.ts +0 -87
- package/esm/src/concurrency/rate-limiter.d.ts.map +0 -1
- package/esm/src/concurrency/rate-limiter.js +0 -165
- package/esm/src/concurrency/request-queue.d.ts +0 -71
- package/esm/src/concurrency/request-queue.d.ts.map +0 -1
- package/esm/src/concurrency/request-queue.js +0 -128
- package/esm/src/http/body.d.ts +0 -20
- package/esm/src/http/body.d.ts.map +0 -1
- package/esm/src/http/body.js +0 -63
- package/esm/src/http/request-guards.d.ts +0 -54
- package/esm/src/http/request-guards.d.ts.map +0 -1
- package/esm/src/http/request-guards.js +0 -114
- package/esm/src/http/wire.d.ts +0 -26
- package/esm/src/http/wire.d.ts.map +0 -1
- package/esm/src/http/wire.js +0 -35
- package/esm/src/inspector/launcher.d.ts +0 -48
- package/esm/src/inspector/launcher.d.ts.map +0 -1
- package/esm/src/inspector/launcher.js +0 -100
- package/esm/src/mcp-app.d.ts +0 -728
- package/esm/src/mcp-app.d.ts.map +0 -1
- package/esm/src/mcp-app.js +0 -3530
- package/esm/src/middleware/backpressure.d.ts +0 -24
- package/esm/src/middleware/backpressure.d.ts.map +0 -1
- package/esm/src/middleware/backpressure.js +0 -31
- package/esm/src/middleware/mod.d.ts +0 -11
- package/esm/src/middleware/mod.d.ts.map +0 -1
- package/esm/src/middleware/mod.js +0 -11
- package/esm/src/middleware/rate-limit.d.ts +0 -22
- package/esm/src/middleware/rate-limit.d.ts.map +0 -1
- package/esm/src/middleware/rate-limit.js +0 -33
- package/esm/src/middleware/runner.d.ts +0 -32
- package/esm/src/middleware/runner.d.ts.map +0 -1
- package/esm/src/middleware/runner.js +0 -49
- package/esm/src/middleware/types.d.ts +0 -76
- package/esm/src/middleware/types.d.ts.map +0 -1
- package/esm/src/middleware/types.js +0 -9
- package/esm/src/middleware/validation.d.ts +0 -24
- package/esm/src/middleware/validation.d.ts.map +0 -1
- package/esm/src/middleware/validation.js +0 -30
- package/esm/src/mrtr/capability-check.d.ts +0 -75
- package/esm/src/mrtr/capability-check.d.ts.map +0 -1
- package/esm/src/mrtr/capability-check.js +0 -233
- package/esm/src/mrtr/mod.d.ts +0 -18
- package/esm/src/mrtr/mod.d.ts.map +0 -1
- package/esm/src/mrtr/mod.js +0 -12
- package/esm/src/mrtr/replay-store.d.ts +0 -50
- package/esm/src/mrtr/replay-store.d.ts.map +0 -1
- package/esm/src/mrtr/replay-store.js +0 -61
- package/esm/src/mrtr/request-state.d.ts +0 -181
- package/esm/src/mrtr/request-state.d.ts.map +0 -1
- package/esm/src/mrtr/request-state.js +0 -313
- package/esm/src/mrtr/retry-guard.d.ts +0 -61
- package/esm/src/mrtr/retry-guard.d.ts.map +0 -1
- package/esm/src/mrtr/retry-guard.js +0 -53
- package/esm/src/mrtr/types.d.ts +0 -99
- package/esm/src/mrtr/types.d.ts.map +0 -1
- package/esm/src/mrtr/types.js +0 -14
- package/esm/src/observability/metrics.d.ts +0 -104
- package/esm/src/observability/metrics.d.ts.map +0 -1
- package/esm/src/observability/metrics.js +0 -207
- package/esm/src/observability/mod.d.ts +0 -12
- package/esm/src/observability/mod.d.ts.map +0 -1
- package/esm/src/observability/mod.js +0 -11
- package/esm/src/observability/otel.d.ts +0 -73
- package/esm/src/observability/otel.d.ts.map +0 -1
- package/esm/src/observability/otel.js +0 -260
- package/esm/src/runtime/runtime.d.ts +0 -10
- package/esm/src/runtime/runtime.d.ts.map +0 -1
- package/esm/src/runtime/runtime.deno.d.ts +0 -50
- package/esm/src/runtime/runtime.deno.d.ts.map +0 -1
- package/esm/src/runtime/runtime.deno.js +0 -120
- package/esm/src/runtime/runtime.js +0 -41
- package/esm/src/runtime/runtime.node.d.ts +0 -51
- package/esm/src/runtime/runtime.node.d.ts.map +0 -1
- package/esm/src/runtime/runtime.node.js +0 -268
- package/esm/src/runtime/types.d.ts +0 -107
- package/esm/src/runtime/types.d.ts.map +0 -1
- package/esm/src/runtime/types.js +0 -12
- package/esm/src/security/channel-hmac.d.ts +0 -43
- package/esm/src/security/channel-hmac.d.ts.map +0 -1
- package/esm/src/security/channel-hmac.js +0 -135
- package/esm/src/security/csp.d.ts +0 -50
- package/esm/src/security/csp.d.ts.map +0 -1
- package/esm/src/security/csp.js +0 -63
- package/esm/src/security/message-signer.d.ts +0 -88
- package/esm/src/security/message-signer.d.ts.map +0 -1
- package/esm/src/security/message-signer.js +0 -166
- package/esm/src/subscriptions/subscription-registry.d.ts +0 -256
- package/esm/src/subscriptions/subscription-registry.d.ts.map +0 -1
- package/esm/src/subscriptions/subscription-registry.js +0 -406
- package/esm/src/tasks/mod.d.ts +0 -13
- package/esm/src/tasks/mod.d.ts.map +0 -1
- package/esm/src/tasks/mod.js +0 -11
- package/esm/src/tasks/task-store.d.ts +0 -342
- package/esm/src/tasks/task-store.d.ts.map +0 -1
- package/esm/src/tasks/task-store.js +0 -649
- package/esm/src/transport/request-headers.d.ts +0 -145
- package/esm/src/transport/request-headers.d.ts.map +0 -1
- package/esm/src/transport/request-headers.js +0 -525
- package/esm/src/types.d.ts +0 -776
- package/esm/src/types.d.ts.map +0 -1
- package/esm/src/types.js +0 -92
- package/esm/src/ui/viewer-utils.d.ts +0 -45
- package/esm/src/ui/viewer-utils.d.ts.map +0 -1
- package/esm/src/ui/viewer-utils.js +0 -97
- package/esm/src/validation/schema-validator.d.ts +0 -115
- package/esm/src/validation/schema-validator.d.ts.map +0 -1
- package/esm/src/validation/schema-validator.js +0 -249
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscription registry for subscriptions/listen (spec 2026-07-28, SEP-2575).
|
|
3
|
-
*
|
|
4
|
-
* Owns the lifecycle of long-lived notification streams opened by the client
|
|
5
|
-
* via subscriptions/listen. Handles filter intersection, fan-out, keep-alive,
|
|
6
|
-
* and both client- and server-initiated teardown.
|
|
7
|
-
*
|
|
8
|
-
* Everything here is pure-function-first and testable without a real HTTP
|
|
9
|
-
* server. The SubscriptionSink interface is the seam: in production it wraps
|
|
10
|
-
* a ReadableStreamDefaultController; in tests it can be an in-memory array.
|
|
11
|
-
*
|
|
12
|
-
* SSE format: spec 2026-07-28 drops resumable streams (Last-Event-ID is
|
|
13
|
-
* ignored, event IDs MUST NOT be emitted). Every event is just:
|
|
14
|
-
* data: {json}\n\n
|
|
15
|
-
* Keep-alive lines are SSE comment lines:
|
|
16
|
-
* :\n\n
|
|
17
|
-
*
|
|
18
|
-
* @module lib/server/subscriptions/subscription-registry
|
|
19
|
-
*/
|
|
20
|
-
/**
|
|
21
|
-
* Notification filter from params.notifications of a subscriptions/listen
|
|
22
|
-
* request. All fields optional — an omitted field means "not subscribed".
|
|
23
|
-
*/
|
|
24
|
-
export interface SubscriptionFilter {
|
|
25
|
-
readonly toolsListChanged?: boolean;
|
|
26
|
-
readonly promptsListChanged?: boolean;
|
|
27
|
-
readonly resourcesListChanged?: boolean;
|
|
28
|
-
/** URIs for which the client wants notifications/resources/updated events. */
|
|
29
|
-
readonly resourceSubscriptions?: readonly string[];
|
|
30
|
-
/**
|
|
31
|
-
* Task ids for which the client wants `notifications/tasks` (Tasks extension).
|
|
32
|
-
*
|
|
33
|
-
* Recognising this field is not optional even though *pushing* task updates is:
|
|
34
|
-
* a client that asks for task notifications without declaring the Tasks
|
|
35
|
-
* extension MUST be refused with the missing-capability error, and a filter that
|
|
36
|
-
* does not know the field cannot tell the difference between that and a client
|
|
37
|
-
* asking for nothing.
|
|
38
|
-
*/
|
|
39
|
-
readonly taskIds?: readonly string[];
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* Injectable stream sink. In production wraps a ReadableStreamDefaultController.
|
|
43
|
-
* In tests, an in-memory collector.
|
|
44
|
-
*
|
|
45
|
-
* Implementations MUST silently swallow errors from writing to an already-
|
|
46
|
-
* closed controller — the ReadableStream cancel() callback fires before
|
|
47
|
-
* unregister(), so a race window exists on every HTTP client disconnect.
|
|
48
|
-
*/
|
|
49
|
-
export interface SubscriptionSink {
|
|
50
|
-
enqueue(chunk: Uint8Array): void;
|
|
51
|
-
/** Idempotent: calling twice MUST NOT throw. */
|
|
52
|
-
close(): void;
|
|
53
|
-
/** True once close() has been called or the underlying stream errored. */
|
|
54
|
-
readonly isClosed: boolean;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Compute the subset of requestedFilter the server agrees to honour.
|
|
58
|
-
*
|
|
59
|
-
* Spec: "The notifications field in the acknowledgment reflects the subset
|
|
60
|
-
* the server agreed to honor. Notification types the server does not support
|
|
61
|
-
* are omitted."
|
|
62
|
-
*
|
|
63
|
-
* For boolean fields: include only when both the client requested (true) AND
|
|
64
|
-
* the server supports (true). For resourceSubscriptions: accept all requested
|
|
65
|
-
* URIs when the server mask has a non-empty or undefined resourceSubscriptions
|
|
66
|
-
* (undefined = "accept all"). A server that sets serverSupports.resourceSubscriptions
|
|
67
|
-
* to [] opts out of resource URI tracking entirely.
|
|
68
|
-
*/
|
|
69
|
-
export declare function intersectFilter(requested: SubscriptionFilter, serverSupports: SubscriptionFilter): SubscriptionFilter;
|
|
70
|
-
/**
|
|
71
|
-
* Build the notifications/subscriptions/acknowledged JSON-RPC notification.
|
|
72
|
-
*
|
|
73
|
-
* Spec (subscriptions page — Acknowledgment): MUST be the first message;
|
|
74
|
-
* MUST carry subscriptionId in _meta; MUST echo only the agreed filter.
|
|
75
|
-
*/
|
|
76
|
-
export declare function buildAcknowledgedMessage(subscriptionId: string | number, agreedFilter: SubscriptionFilter): Record<string, unknown>;
|
|
77
|
-
/**
|
|
78
|
-
* Inject io.modelcontextprotocol/subscriptionId into a notification's _meta.
|
|
79
|
-
*
|
|
80
|
-
* Called on every outgoing notification before it is enqueued on the stream.
|
|
81
|
-
* Merges rather than replaces _meta so that other _meta fields are preserved.
|
|
82
|
-
* Merges rather than replaces params so non-_meta fields (e.g. uri) survive.
|
|
83
|
-
*/
|
|
84
|
-
export declare function stampSubscriptionMeta(message: Record<string, unknown>, subscriptionId: string | number): Record<string, unknown>;
|
|
85
|
-
/**
|
|
86
|
-
* Build the graceful-close JSON-RPC response for the subscriptions/listen
|
|
87
|
-
* request.
|
|
88
|
-
*
|
|
89
|
-
* Spec (subscriptions page — Graceful Closure): server SHOULD respond to the
|
|
90
|
-
* original subscriptions/listen request with an empty result before closing
|
|
91
|
-
* the stream. The result carries resultType: "complete" and subscriptionId in
|
|
92
|
-
* _meta, identifying which subscription is closing.
|
|
93
|
-
*
|
|
94
|
-
* The id in the response is the JSON-RPC id of the original request, which
|
|
95
|
-
* is the same value as the subscriptionId.
|
|
96
|
-
*/
|
|
97
|
-
export declare function buildGracefulCloseResult(subscriptionId: string | number, serverInfo: {
|
|
98
|
-
readonly name: string;
|
|
99
|
-
readonly version: string;
|
|
100
|
-
}): Record<string, unknown>;
|
|
101
|
-
/**
|
|
102
|
-
* Build the notifications/cancelled notification the server MUST emit when it
|
|
103
|
-
* tears down a subscription on its own initiative.
|
|
104
|
-
*
|
|
105
|
-
* Spec (cancellation page — §2): "A server MUST send notifications/cancelled
|
|
106
|
-
* referencing a subscriptions/listen request ID when it tears down that
|
|
107
|
-
* subscription stream."
|
|
108
|
-
*
|
|
109
|
-
* On HTTP the sequence is: enqueue this, then enqueue the graceful-close
|
|
110
|
-
* result, then close the stream. On stdio it travels on the shared channel.
|
|
111
|
-
*/
|
|
112
|
-
export declare function buildServerCancelledNotification(subscriptionId: string | number): Record<string, unknown>;
|
|
113
|
-
/**
|
|
114
|
-
* Encode a JSON-RPC message as a single SSE event chunk.
|
|
115
|
-
*
|
|
116
|
-
* Format: "data: {json}\n\n" — NO "id:" line.
|
|
117
|
-
* Spec 2026-07-28 drops resumable streams: SSE event IDs MUST NOT be emitted
|
|
118
|
-
* (streamable-http page — Earlier Streamable HTTP Revisions: "Resumable SSE
|
|
119
|
-
* streams via Last-Event-ID are not supported").
|
|
120
|
-
*/
|
|
121
|
-
export declare function encodeSSEEvent(message: Record<string, unknown>): Uint8Array;
|
|
122
|
-
/**
|
|
123
|
-
* Emit a bare SSE comment line as a keep-alive heartbeat.
|
|
124
|
-
*
|
|
125
|
-
* Format: ":\n\n" — per the SSE spec any line beginning with ":" is a
|
|
126
|
-
* comment; clients MUST ignore it. Spec 2026-07-28 explicitly encourages
|
|
127
|
-
* servers to use these for long-lived streams to prevent intermediary timeouts.
|
|
128
|
-
*/
|
|
129
|
-
export declare function encodeSSEKeepAlive(): Uint8Array;
|
|
130
|
-
export interface SubscriptionRegistryOptions {
|
|
131
|
-
/** Server identity echoed in graceful-close results. */
|
|
132
|
-
readonly serverInfo: {
|
|
133
|
-
readonly name: string;
|
|
134
|
-
readonly version: string;
|
|
135
|
-
};
|
|
136
|
-
/**
|
|
137
|
-
* Interval between keep-alive SSE comment lines. Default: 30_000 ms.
|
|
138
|
-
* "Periodically" per spec; 30 s is the de-facto SSE convention and avoids
|
|
139
|
-
* intermediate proxy idle timeouts (nginx default keepalive_timeout: 65 s).
|
|
140
|
-
*/
|
|
141
|
-
readonly keepAliveIntervalMs?: number;
|
|
142
|
-
/**
|
|
143
|
-
* Server capability mask — which notification types this server can deliver.
|
|
144
|
-
*
|
|
145
|
-
* An **allowlist**: a supplied mask must name every type it wants delivered,
|
|
146
|
-
* because an omitted field means "not supported". This is deliberate — an
|
|
147
|
-
* operator narrowing delivery should not have a type they forgot to mention
|
|
148
|
-
* granted back to them.
|
|
149
|
-
*
|
|
150
|
-
* Omit the option entirely (the default) to support all four types. Supplying
|
|
151
|
-
* `{}` therefore supports none, which is a legal way to accept subscriptions
|
|
152
|
-
* while delivering nothing.
|
|
153
|
-
*/
|
|
154
|
-
readonly serverSupports?: SubscriptionFilter;
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Registry that owns live subscriptions and their fan-out.
|
|
158
|
-
*
|
|
159
|
-
* Keyed internally by a random UUID generated at register() time — NOT by the
|
|
160
|
-
* client-visible subscriptionId, because two concurrent HTTP connections MAY
|
|
161
|
-
* legitimately use the same JSON-RPC id value (e.g., both send id: 1). The
|
|
162
|
-
* UUID is the opaque key returned to the caller for later unregister() calls.
|
|
163
|
-
*
|
|
164
|
-
* Thread-safety note: Deno is single-threaded, so concurrent access between
|
|
165
|
-
* the register/unregister path and the fan-out path is serialised by the event
|
|
166
|
-
* loop. No locking is needed, but async gaps (await) inside register/unregister
|
|
167
|
-
* must not be introduced.
|
|
168
|
-
*/
|
|
169
|
-
export declare class SubscriptionRegistry {
|
|
170
|
-
private readonly entries;
|
|
171
|
-
private readonly opts;
|
|
172
|
-
private keepAliveTimer;
|
|
173
|
-
constructor(options: SubscriptionRegistryOptions);
|
|
174
|
-
/**
|
|
175
|
-
* The subset of `requested` this server will actually honour.
|
|
176
|
-
*
|
|
177
|
-
* Exposed so a caller can build the acknowledgement from the same value the
|
|
178
|
-
* registry will enforce. Computing it independently on both sides is how a
|
|
179
|
-
* client ends up told it subscribed to something the registry then ignores.
|
|
180
|
-
*/
|
|
181
|
-
computeAgreedFilter(requested: SubscriptionFilter): SubscriptionFilter;
|
|
182
|
-
/**
|
|
183
|
-
* Register a new subscription.
|
|
184
|
-
*
|
|
185
|
-
* MUST be called AFTER the acknowledged message has been successfully
|
|
186
|
-
* enqueued on the sink. The spec requires the acknowledged message to be the
|
|
187
|
-
* FIRST message on the stream — registering before sending it would allow a
|
|
188
|
-
* concurrent fanOut to race ahead of the acknowledged message.
|
|
189
|
-
*
|
|
190
|
-
* @returns Opaque internal key — pass to unregister().
|
|
191
|
-
*/
|
|
192
|
-
register(subscriptionId: string | number, requestedFilter: SubscriptionFilter, sink: SubscriptionSink): string;
|
|
193
|
-
/**
|
|
194
|
-
* Remove a subscription by its internal key.
|
|
195
|
-
*
|
|
196
|
-
* Server-initiated teardown ("server"):
|
|
197
|
-
* 1. Enqueue notifications/cancelled (spec MUST, cancellation page §2).
|
|
198
|
-
* 2. Enqueue graceful-close result (spec SHOULD, subscriptions page).
|
|
199
|
-
* 3. Close the sink.
|
|
200
|
-
*
|
|
201
|
-
* Client-initiated (HTTP SSE cancel() callback, "client"):
|
|
202
|
-
* Remove the entry only. The client already closed the stream — enqueue
|
|
203
|
-
* attempts would silently fail or throw, and the spec says no further
|
|
204
|
-
* messages are required or expected when the client disconnects.
|
|
205
|
-
*
|
|
206
|
-
* No-op when the key is not found (race between shutdown and disconnect).
|
|
207
|
-
*/
|
|
208
|
-
unregister(internalKey: string, initiator?: "client" | "server"): void;
|
|
209
|
-
/**
|
|
210
|
-
* Fan-out a list-changed notification to every subscription that opted in.
|
|
211
|
-
*
|
|
212
|
-
* Prunes sinks whose isClosed is true (client disconnected between the
|
|
213
|
-
* cancel() callback and the next fanOut call). A closed sink is removed from
|
|
214
|
-
* the map so it does not accumulate indefinitely.
|
|
215
|
-
*
|
|
216
|
-
* MUST NOT be called with request-scoped types (progress, message).
|
|
217
|
-
*/
|
|
218
|
-
fanOut(type: "toolsListChanged" | "promptsListChanged" | "resourcesListChanged"): void;
|
|
219
|
-
/**
|
|
220
|
-
* Fan-out a notifications/resources/updated event to subscriptions whose
|
|
221
|
-
* agreed filter includes the given URI.
|
|
222
|
-
*/
|
|
223
|
-
fanOutResourceUpdated(uri: string): void;
|
|
224
|
-
/**
|
|
225
|
-
* Gracefully shut down all live subscriptions (call from McpApp.stop()).
|
|
226
|
-
*
|
|
227
|
-
* Equivalent to unregister(key, "server") for every live entry, then
|
|
228
|
-
* stopping the keep-alive timer.
|
|
229
|
-
*/
|
|
230
|
-
shutdown(): void;
|
|
231
|
-
/** Count of live (not-yet-unregistered) subscriptions. */
|
|
232
|
-
get count(): number;
|
|
233
|
-
/**
|
|
234
|
-
* Start the periodic keep-alive timer.
|
|
235
|
-
*
|
|
236
|
-
* Injectable setInterval and unref so tests can use fake timers and the
|
|
237
|
-
* timer does not prevent process exit. Calling again while a timer is
|
|
238
|
-
* already running is a no-op (guards against double-start in embedded mode
|
|
239
|
-
* where startHttp may be called via getFetchHandler).
|
|
240
|
-
*/
|
|
241
|
-
startKeepAlive(setIntervalFn?: (fn: () => void, ms: number) => ReturnType<typeof setInterval>, unrefFn?: (id: ReturnType<typeof setInterval>) => void): void;
|
|
242
|
-
/** Stop the keep-alive timer (called internally by shutdown()). */
|
|
243
|
-
stopKeepAlive(): void;
|
|
244
|
-
/**
|
|
245
|
-
* Emit a keep-alive comment line on every live sink.
|
|
246
|
-
*
|
|
247
|
-
* Spec (streamable-http page — Receiving Messages Note): "servers are
|
|
248
|
-
* encouraged to periodically emit an SSE comment line (a line beginning
|
|
249
|
-
* with a colon, e.g. `:\r\n`) as a keep-alive".
|
|
250
|
-
*
|
|
251
|
-
* Internal — called by the interval timer. Not private so tests can invoke
|
|
252
|
-
* it directly without fake timers.
|
|
253
|
-
*/
|
|
254
|
-
_sendKeepAlive(): void;
|
|
255
|
-
}
|
|
256
|
-
//# sourceMappingURL=subscription-registry.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"subscription-registry.d.ts","sourceRoot":"","sources":["../../../src/src/subscriptions/subscription-registry.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,406 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Subscription registry for subscriptions/listen (spec 2026-07-28, SEP-2575).
|
|
3
|
-
*
|
|
4
|
-
* Owns the lifecycle of long-lived notification streams opened by the client
|
|
5
|
-
* via subscriptions/listen. Handles filter intersection, fan-out, keep-alive,
|
|
6
|
-
* and both client- and server-initiated teardown.
|
|
7
|
-
*
|
|
8
|
-
* Everything here is pure-function-first and testable without a real HTTP
|
|
9
|
-
* server. The SubscriptionSink interface is the seam: in production it wraps
|
|
10
|
-
* a ReadableStreamDefaultController; in tests it can be an in-memory array.
|
|
11
|
-
*
|
|
12
|
-
* SSE format: spec 2026-07-28 drops resumable streams (Last-Event-ID is
|
|
13
|
-
* ignored, event IDs MUST NOT be emitted). Every event is just:
|
|
14
|
-
* data: {json}\n\n
|
|
15
|
-
* Keep-alive lines are SSE comment lines:
|
|
16
|
-
* :\n\n
|
|
17
|
-
*
|
|
18
|
-
* @module lib/server/subscriptions/subscription-registry
|
|
19
|
-
*/
|
|
20
|
-
// ── Spec constants ────────────────────────────────────────────────────────────
|
|
21
|
-
/** _meta key identifying the subscription (spec 2026-07-28). */
|
|
22
|
-
const SUBSCRIPTION_ID_KEY = "io.modelcontextprotocol/subscriptionId";
|
|
23
|
-
/**
|
|
24
|
-
* _meta key carrying server identity in results (spec 2026-07-28, SHOULD).
|
|
25
|
-
* Duplicated from mcp-app.ts to keep this module self-contained and testable
|
|
26
|
-
* without importing from the app layer.
|
|
27
|
-
*/
|
|
28
|
-
const SERVER_INFO_KEY = "io.modelcontextprotocol/serverInfo";
|
|
29
|
-
// ── Pure functions ────────────────────────────────────────────────────────────
|
|
30
|
-
function isRecord(v) {
|
|
31
|
-
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Compute the subset of requestedFilter the server agrees to honour.
|
|
35
|
-
*
|
|
36
|
-
* Spec: "The notifications field in the acknowledgment reflects the subset
|
|
37
|
-
* the server agreed to honor. Notification types the server does not support
|
|
38
|
-
* are omitted."
|
|
39
|
-
*
|
|
40
|
-
* For boolean fields: include only when both the client requested (true) AND
|
|
41
|
-
* the server supports (true). For resourceSubscriptions: accept all requested
|
|
42
|
-
* URIs when the server mask has a non-empty or undefined resourceSubscriptions
|
|
43
|
-
* (undefined = "accept all"). A server that sets serverSupports.resourceSubscriptions
|
|
44
|
-
* to [] opts out of resource URI tracking entirely.
|
|
45
|
-
*/
|
|
46
|
-
export function intersectFilter(requested, serverSupports) {
|
|
47
|
-
const result = {};
|
|
48
|
-
if (requested.toolsListChanged && serverSupports.toolsListChanged) {
|
|
49
|
-
result.toolsListChanged = true;
|
|
50
|
-
}
|
|
51
|
-
if (requested.promptsListChanged && serverSupports.promptsListChanged) {
|
|
52
|
-
result.promptsListChanged = true;
|
|
53
|
-
}
|
|
54
|
-
if (requested.resourcesListChanged && serverSupports.resourcesListChanged) {
|
|
55
|
-
result.resourcesListChanged = true;
|
|
56
|
-
}
|
|
57
|
-
if (Array.isArray(requested.resourceSubscriptions) &&
|
|
58
|
-
requested.resourceSubscriptions.length > 0) {
|
|
59
|
-
// Server's resourceSubscriptions mask: undefined means "accept all",
|
|
60
|
-
// empty array means "refuse all", non-empty array means "accept only these".
|
|
61
|
-
const serverMask = serverSupports.resourceSubscriptions;
|
|
62
|
-
if (serverMask === undefined) {
|
|
63
|
-
// No server-side restriction — accept all requested URIs.
|
|
64
|
-
result.resourceSubscriptions = [...requested.resourceSubscriptions];
|
|
65
|
-
}
|
|
66
|
-
else if (serverMask.length > 0) {
|
|
67
|
-
const allowed = new Set(serverMask);
|
|
68
|
-
const intersection = requested.resourceSubscriptions.filter((u) => allowed.has(u));
|
|
69
|
-
if (intersection.length > 0)
|
|
70
|
-
result.resourceSubscriptions = intersection;
|
|
71
|
-
}
|
|
72
|
-
// serverMask === [] → no URI tracking, field omitted.
|
|
73
|
-
}
|
|
74
|
-
// taskIds mirrors resourceSubscriptions: same undefined/empty/non-empty mask
|
|
75
|
-
// semantics. Carried through so the acknowledgement tells the client which task
|
|
76
|
-
// ids the server actually agreed to track.
|
|
77
|
-
if (Array.isArray(requested.taskIds) && requested.taskIds.length > 0) {
|
|
78
|
-
const serverMask = serverSupports.taskIds;
|
|
79
|
-
if (serverMask === undefined) {
|
|
80
|
-
result.taskIds = [...requested.taskIds];
|
|
81
|
-
}
|
|
82
|
-
else if (serverMask.length > 0) {
|
|
83
|
-
const allowed = new Set(serverMask);
|
|
84
|
-
const intersection = requested.taskIds.filter((tid) => allowed.has(tid));
|
|
85
|
-
if (intersection.length > 0)
|
|
86
|
-
result.taskIds = intersection;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return result;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Build the notifications/subscriptions/acknowledged JSON-RPC notification.
|
|
93
|
-
*
|
|
94
|
-
* Spec (subscriptions page — Acknowledgment): MUST be the first message;
|
|
95
|
-
* MUST carry subscriptionId in _meta; MUST echo only the agreed filter.
|
|
96
|
-
*/
|
|
97
|
-
export function buildAcknowledgedMessage(subscriptionId, agreedFilter) {
|
|
98
|
-
return {
|
|
99
|
-
jsonrpc: "2.0",
|
|
100
|
-
method: "notifications/subscriptions/acknowledged",
|
|
101
|
-
params: {
|
|
102
|
-
_meta: { [SUBSCRIPTION_ID_KEY]: subscriptionId },
|
|
103
|
-
notifications: agreedFilter,
|
|
104
|
-
},
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Inject io.modelcontextprotocol/subscriptionId into a notification's _meta.
|
|
109
|
-
*
|
|
110
|
-
* Called on every outgoing notification before it is enqueued on the stream.
|
|
111
|
-
* Merges rather than replaces _meta so that other _meta fields are preserved.
|
|
112
|
-
* Merges rather than replaces params so non-_meta fields (e.g. uri) survive.
|
|
113
|
-
*/
|
|
114
|
-
export function stampSubscriptionMeta(message, subscriptionId) {
|
|
115
|
-
const existingParams = isRecord(message["params"]) ? message["params"] : {};
|
|
116
|
-
const existingMeta = isRecord(existingParams["_meta"])
|
|
117
|
-
? existingParams["_meta"]
|
|
118
|
-
: {};
|
|
119
|
-
return {
|
|
120
|
-
...message,
|
|
121
|
-
params: {
|
|
122
|
-
...existingParams,
|
|
123
|
-
_meta: {
|
|
124
|
-
...existingMeta,
|
|
125
|
-
[SUBSCRIPTION_ID_KEY]: subscriptionId,
|
|
126
|
-
},
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Build the graceful-close JSON-RPC response for the subscriptions/listen
|
|
132
|
-
* request.
|
|
133
|
-
*
|
|
134
|
-
* Spec (subscriptions page — Graceful Closure): server SHOULD respond to the
|
|
135
|
-
* original subscriptions/listen request with an empty result before closing
|
|
136
|
-
* the stream. The result carries resultType: "complete" and subscriptionId in
|
|
137
|
-
* _meta, identifying which subscription is closing.
|
|
138
|
-
*
|
|
139
|
-
* The id in the response is the JSON-RPC id of the original request, which
|
|
140
|
-
* is the same value as the subscriptionId.
|
|
141
|
-
*/
|
|
142
|
-
export function buildGracefulCloseResult(subscriptionId, serverInfo) {
|
|
143
|
-
return {
|
|
144
|
-
jsonrpc: "2.0",
|
|
145
|
-
id: subscriptionId,
|
|
146
|
-
result: {
|
|
147
|
-
resultType: "complete",
|
|
148
|
-
_meta: {
|
|
149
|
-
[SUBSCRIPTION_ID_KEY]: subscriptionId,
|
|
150
|
-
[SERVER_INFO_KEY]: serverInfo,
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
* Build the notifications/cancelled notification the server MUST emit when it
|
|
157
|
-
* tears down a subscription on its own initiative.
|
|
158
|
-
*
|
|
159
|
-
* Spec (cancellation page — §2): "A server MUST send notifications/cancelled
|
|
160
|
-
* referencing a subscriptions/listen request ID when it tears down that
|
|
161
|
-
* subscription stream."
|
|
162
|
-
*
|
|
163
|
-
* On HTTP the sequence is: enqueue this, then enqueue the graceful-close
|
|
164
|
-
* result, then close the stream. On stdio it travels on the shared channel.
|
|
165
|
-
*/
|
|
166
|
-
export function buildServerCancelledNotification(subscriptionId) {
|
|
167
|
-
// Stamped like every other message on the stream. The rule is unconditional —
|
|
168
|
-
// "All notifications delivered on the stream carry
|
|
169
|
-
// io.modelcontextprotocol/subscriptionId in _meta" — and on stdio, where every
|
|
170
|
-
// subscription shares one channel, it is the only way a client can tell which
|
|
171
|
-
// subscription is being torn down.
|
|
172
|
-
return stampSubscriptionMeta({
|
|
173
|
-
jsonrpc: "2.0",
|
|
174
|
-
method: "notifications/cancelled",
|
|
175
|
-
params: {
|
|
176
|
-
requestId: subscriptionId,
|
|
177
|
-
},
|
|
178
|
-
}, subscriptionId);
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Encode a JSON-RPC message as a single SSE event chunk.
|
|
182
|
-
*
|
|
183
|
-
* Format: "data: {json}\n\n" — NO "id:" line.
|
|
184
|
-
* Spec 2026-07-28 drops resumable streams: SSE event IDs MUST NOT be emitted
|
|
185
|
-
* (streamable-http page — Earlier Streamable HTTP Revisions: "Resumable SSE
|
|
186
|
-
* streams via Last-Event-ID are not supported").
|
|
187
|
-
*/
|
|
188
|
-
export function encodeSSEEvent(message) {
|
|
189
|
-
return new TextEncoder().encode(`data: ${JSON.stringify(message)}\n\n`);
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Emit a bare SSE comment line as a keep-alive heartbeat.
|
|
193
|
-
*
|
|
194
|
-
* Format: ":\n\n" — per the SSE spec any line beginning with ":" is a
|
|
195
|
-
* comment; clients MUST ignore it. Spec 2026-07-28 explicitly encourages
|
|
196
|
-
* servers to use these for long-lived streams to prevent intermediary timeouts.
|
|
197
|
-
*/
|
|
198
|
-
export function encodeSSEKeepAlive() {
|
|
199
|
-
return new TextEncoder().encode(":\n\n");
|
|
200
|
-
}
|
|
201
|
-
// Map notification-filter field names to their wire method names.
|
|
202
|
-
const TYPE_TO_METHOD = {
|
|
203
|
-
toolsListChanged: "notifications/tools/list_changed",
|
|
204
|
-
promptsListChanged: "notifications/prompts/list_changed",
|
|
205
|
-
resourcesListChanged: "notifications/resources/list_changed",
|
|
206
|
-
};
|
|
207
|
-
/**
|
|
208
|
-
* Registry that owns live subscriptions and their fan-out.
|
|
209
|
-
*
|
|
210
|
-
* Keyed internally by a random UUID generated at register() time — NOT by the
|
|
211
|
-
* client-visible subscriptionId, because two concurrent HTTP connections MAY
|
|
212
|
-
* legitimately use the same JSON-RPC id value (e.g., both send id: 1). The
|
|
213
|
-
* UUID is the opaque key returned to the caller for later unregister() calls.
|
|
214
|
-
*
|
|
215
|
-
* Thread-safety note: Deno is single-threaded, so concurrent access between
|
|
216
|
-
* the register/unregister path and the fan-out path is serialised by the event
|
|
217
|
-
* loop. No locking is needed, but async gaps (await) inside register/unregister
|
|
218
|
-
* must not be introduced.
|
|
219
|
-
*/
|
|
220
|
-
export class SubscriptionRegistry {
|
|
221
|
-
entries = new Map();
|
|
222
|
-
opts;
|
|
223
|
-
keepAliveTimer = null;
|
|
224
|
-
constructor(options) {
|
|
225
|
-
// Default: all four notification types supported.
|
|
226
|
-
const defaultSupports = {
|
|
227
|
-
toolsListChanged: true,
|
|
228
|
-
promptsListChanged: true,
|
|
229
|
-
resourcesListChanged: true,
|
|
230
|
-
resourceSubscriptions: undefined, // undefined = accept all URIs
|
|
231
|
-
taskIds: undefined, // undefined = accept all task ids
|
|
232
|
-
};
|
|
233
|
-
this.opts = {
|
|
234
|
-
serverInfo: options.serverInfo,
|
|
235
|
-
keepAliveIntervalMs: options.keepAliveIntervalMs ?? 30_000,
|
|
236
|
-
// Whole-object fallback, deliberately: a supplied mask is an ALLOWLIST, so
|
|
237
|
-
// an omitted field means "not supported". Merging per-field would instead
|
|
238
|
-
// make a partial mask grant everything it forgot to mention — the opposite
|
|
239
|
-
// of what an operator restricting delivery intends. Fail closed.
|
|
240
|
-
serverSupports: options.serverSupports ?? defaultSupports,
|
|
241
|
-
};
|
|
242
|
-
}
|
|
243
|
-
/**
|
|
244
|
-
* The subset of `requested` this server will actually honour.
|
|
245
|
-
*
|
|
246
|
-
* Exposed so a caller can build the acknowledgement from the same value the
|
|
247
|
-
* registry will enforce. Computing it independently on both sides is how a
|
|
248
|
-
* client ends up told it subscribed to something the registry then ignores.
|
|
249
|
-
*/
|
|
250
|
-
computeAgreedFilter(requested) {
|
|
251
|
-
return intersectFilter(requested, this.opts.serverSupports);
|
|
252
|
-
}
|
|
253
|
-
/**
|
|
254
|
-
* Register a new subscription.
|
|
255
|
-
*
|
|
256
|
-
* MUST be called AFTER the acknowledged message has been successfully
|
|
257
|
-
* enqueued on the sink. The spec requires the acknowledged message to be the
|
|
258
|
-
* FIRST message on the stream — registering before sending it would allow a
|
|
259
|
-
* concurrent fanOut to race ahead of the acknowledged message.
|
|
260
|
-
*
|
|
261
|
-
* @returns Opaque internal key — pass to unregister().
|
|
262
|
-
*/
|
|
263
|
-
register(subscriptionId, requestedFilter, sink) {
|
|
264
|
-
const agreedFilter = intersectFilter(requestedFilter, this.opts.serverSupports);
|
|
265
|
-
const internalKey = crypto.randomUUID();
|
|
266
|
-
this.entries.set(internalKey, { subscriptionId, agreedFilter, sink });
|
|
267
|
-
return internalKey;
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* Remove a subscription by its internal key.
|
|
271
|
-
*
|
|
272
|
-
* Server-initiated teardown ("server"):
|
|
273
|
-
* 1. Enqueue notifications/cancelled (spec MUST, cancellation page §2).
|
|
274
|
-
* 2. Enqueue graceful-close result (spec SHOULD, subscriptions page).
|
|
275
|
-
* 3. Close the sink.
|
|
276
|
-
*
|
|
277
|
-
* Client-initiated (HTTP SSE cancel() callback, "client"):
|
|
278
|
-
* Remove the entry only. The client already closed the stream — enqueue
|
|
279
|
-
* attempts would silently fail or throw, and the spec says no further
|
|
280
|
-
* messages are required or expected when the client disconnects.
|
|
281
|
-
*
|
|
282
|
-
* No-op when the key is not found (race between shutdown and disconnect).
|
|
283
|
-
*/
|
|
284
|
-
unregister(internalKey, initiator = "client") {
|
|
285
|
-
const entry = this.entries.get(internalKey);
|
|
286
|
-
if (!entry)
|
|
287
|
-
return;
|
|
288
|
-
this.entries.delete(internalKey);
|
|
289
|
-
if (initiator === "server") {
|
|
290
|
-
// MUST send notifications/cancelled before the graceful-close result.
|
|
291
|
-
// (spec: cancellation page §2 — server MUST send this when tearing down
|
|
292
|
-
// a subscription on its own initiative.)
|
|
293
|
-
entry.sink.enqueue(encodeSSEEvent(buildServerCancelledNotification(entry.subscriptionId)));
|
|
294
|
-
// SHOULD send the empty graceful-close result (spec: subscriptions page
|
|
295
|
-
// — Graceful Closure). Lets the client distinguish a clean shutdown from
|
|
296
|
-
// an unexpected transport drop.
|
|
297
|
-
entry.sink.enqueue(encodeSSEEvent(buildGracefulCloseResult(entry.subscriptionId, this.opts.serverInfo)));
|
|
298
|
-
entry.sink.close();
|
|
299
|
-
}
|
|
300
|
-
// "client": entry removed above; nothing else to do.
|
|
301
|
-
}
|
|
302
|
-
/**
|
|
303
|
-
* Fan-out a list-changed notification to every subscription that opted in.
|
|
304
|
-
*
|
|
305
|
-
* Prunes sinks whose isClosed is true (client disconnected between the
|
|
306
|
-
* cancel() callback and the next fanOut call). A closed sink is removed from
|
|
307
|
-
* the map so it does not accumulate indefinitely.
|
|
308
|
-
*
|
|
309
|
-
* MUST NOT be called with request-scoped types (progress, message).
|
|
310
|
-
*/
|
|
311
|
-
fanOut(type) {
|
|
312
|
-
const method = TYPE_TO_METHOD[type];
|
|
313
|
-
for (const [key, entry] of this.entries) {
|
|
314
|
-
if (entry.sink.isClosed) {
|
|
315
|
-
// Dead entry — prune it now rather than waiting for unregister.
|
|
316
|
-
this.entries.delete(key);
|
|
317
|
-
continue;
|
|
318
|
-
}
|
|
319
|
-
if (!entry.agreedFilter[type])
|
|
320
|
-
continue;
|
|
321
|
-
const notification = stampSubscriptionMeta({ jsonrpc: "2.0", method, params: {} }, entry.subscriptionId);
|
|
322
|
-
entry.sink.enqueue(encodeSSEEvent(notification));
|
|
323
|
-
}
|
|
324
|
-
}
|
|
325
|
-
/**
|
|
326
|
-
* Fan-out a notifications/resources/updated event to subscriptions whose
|
|
327
|
-
* agreed filter includes the given URI.
|
|
328
|
-
*/
|
|
329
|
-
fanOutResourceUpdated(uri) {
|
|
330
|
-
for (const [key, entry] of this.entries) {
|
|
331
|
-
if (entry.sink.isClosed) {
|
|
332
|
-
this.entries.delete(key);
|
|
333
|
-
continue;
|
|
334
|
-
}
|
|
335
|
-
const uris = entry.agreedFilter.resourceSubscriptions;
|
|
336
|
-
if (!Array.isArray(uris) || !uris.includes(uri))
|
|
337
|
-
continue;
|
|
338
|
-
const notification = stampSubscriptionMeta({
|
|
339
|
-
jsonrpc: "2.0",
|
|
340
|
-
method: "notifications/resources/updated",
|
|
341
|
-
params: { uri },
|
|
342
|
-
}, entry.subscriptionId);
|
|
343
|
-
entry.sink.enqueue(encodeSSEEvent(notification));
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
/**
|
|
347
|
-
* Gracefully shut down all live subscriptions (call from McpApp.stop()).
|
|
348
|
-
*
|
|
349
|
-
* Equivalent to unregister(key, "server") for every live entry, then
|
|
350
|
-
* stopping the keep-alive timer.
|
|
351
|
-
*/
|
|
352
|
-
shutdown() {
|
|
353
|
-
// Snapshot keys to avoid mutation-while-iterating issues.
|
|
354
|
-
const keys = [...this.entries.keys()];
|
|
355
|
-
for (const key of keys) {
|
|
356
|
-
this.unregister(key, "server");
|
|
357
|
-
}
|
|
358
|
-
this.stopKeepAlive();
|
|
359
|
-
}
|
|
360
|
-
/** Count of live (not-yet-unregistered) subscriptions. */
|
|
361
|
-
get count() {
|
|
362
|
-
return this.entries.size;
|
|
363
|
-
}
|
|
364
|
-
/**
|
|
365
|
-
* Start the periodic keep-alive timer.
|
|
366
|
-
*
|
|
367
|
-
* Injectable setInterval and unref so tests can use fake timers and the
|
|
368
|
-
* timer does not prevent process exit. Calling again while a timer is
|
|
369
|
-
* already running is a no-op (guards against double-start in embedded mode
|
|
370
|
-
* where startHttp may be called via getFetchHandler).
|
|
371
|
-
*/
|
|
372
|
-
startKeepAlive(setIntervalFn = globalThis.setInterval, unrefFn) {
|
|
373
|
-
if (this.keepAliveTimer !== null)
|
|
374
|
-
return;
|
|
375
|
-
this.keepAliveTimer = setIntervalFn(() => this._sendKeepAlive(), this.opts.keepAliveIntervalMs);
|
|
376
|
-
if (unrefFn)
|
|
377
|
-
unrefFn(this.keepAliveTimer);
|
|
378
|
-
}
|
|
379
|
-
/** Stop the keep-alive timer (called internally by shutdown()). */
|
|
380
|
-
stopKeepAlive() {
|
|
381
|
-
if (this.keepAliveTimer === null)
|
|
382
|
-
return;
|
|
383
|
-
clearInterval(this.keepAliveTimer);
|
|
384
|
-
this.keepAliveTimer = null;
|
|
385
|
-
}
|
|
386
|
-
/**
|
|
387
|
-
* Emit a keep-alive comment line on every live sink.
|
|
388
|
-
*
|
|
389
|
-
* Spec (streamable-http page — Receiving Messages Note): "servers are
|
|
390
|
-
* encouraged to periodically emit an SSE comment line (a line beginning
|
|
391
|
-
* with a colon, e.g. `:\r\n`) as a keep-alive".
|
|
392
|
-
*
|
|
393
|
-
* Internal — called by the interval timer. Not private so tests can invoke
|
|
394
|
-
* it directly without fake timers.
|
|
395
|
-
*/
|
|
396
|
-
_sendKeepAlive() {
|
|
397
|
-
const ping = encodeSSEKeepAlive();
|
|
398
|
-
for (const [key, entry] of this.entries) {
|
|
399
|
-
if (entry.sink.isClosed) {
|
|
400
|
-
this.entries.delete(key);
|
|
401
|
-
continue;
|
|
402
|
-
}
|
|
403
|
-
entry.sink.enqueue(ping);
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}
|
package/esm/src/tasks/mod.d.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Public API for the Tasks extension (io.modelcontextprotocol/tasks, SEP-2663).
|
|
3
|
-
*
|
|
4
|
-
* Tool handlers use `createTask()` to opt into async-task mode.
|
|
5
|
-
* The transport layer uses `TaskStore` to manage task lifecycle.
|
|
6
|
-
* `isAsyncTaskDescriptor()` is the discriminant the framework uses at the
|
|
7
|
-
* tools/call boundary to decide whether to spawn a task or return a result.
|
|
8
|
-
*
|
|
9
|
-
* @module lib/server/tasks
|
|
10
|
-
*/
|
|
11
|
-
export type { AsyncTaskDescriptor, CancelledTask, CompletedTask, CreateTaskOptions, CreateTaskResultFields, DetailedTask, FailedTask, InputRequest, InputRequiredTask, Task, TaskController, TaskStoreOptions, WorkingTask, } from "./task-store.js";
|
|
12
|
-
export { createTask, generateTaskId, isAsyncTaskDescriptor, TaskStore, } from "./task-store.js";
|
|
13
|
-
//# sourceMappingURL=mod.d.ts.map
|