@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,233 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Capability check for MRTR inputRequests (spec 2026-07-28, SEP-2322).
|
|
3
|
-
*
|
|
4
|
-
* Rule 7 (MUST NOT): "Servers MUST NOT emit an inputRequest for a capability
|
|
5
|
-
* the client has not declared in io.modelcontextprotocol/clientCapabilities."
|
|
6
|
-
*
|
|
7
|
-
* In the stateless transport model, `clientCapabilities` is per-request: it
|
|
8
|
-
* arrives in `params._meta["io.modelcontextprotocol/clientCapabilities"]` and
|
|
9
|
-
* is therefore already parsed by the time this check runs. There is no session
|
|
10
|
-
* to cache it from — each call carries its own capability declaration.
|
|
11
|
-
*
|
|
12
|
-
* The function is pure: it takes the data it needs and returns a typed result.
|
|
13
|
-
* No network, no server state, no side effects.
|
|
14
|
-
*
|
|
15
|
-
* @module lib/server/mrtr/capability-check
|
|
16
|
-
*/
|
|
17
|
-
// ── Method → capability mapping ───────────────────────────────────────────────
|
|
18
|
-
//
|
|
19
|
-
// Spec 2026-07-28: only these three methods are legal in `inputRequests`.
|
|
20
|
-
// Any unrecognised method is treated as a missing capability (fail-safe): an
|
|
21
|
-
// unknown method is a server-authoring error, and the spec forbids emitting it
|
|
22
|
-
// on the wire. Rejecting it here prevents that wire violation.
|
|
23
|
-
/**
|
|
24
|
-
* The only methods an input request may carry, mapped to the capability each needs.
|
|
25
|
-
*
|
|
26
|
-
* Exported so the Tasks boundary enforces the same grammar. A task that requests
|
|
27
|
-
* input uses MRTR request shapes, and a second, looser list there is how a task
|
|
28
|
-
* ends up asking for a method no client implements — which strands it rather than
|
|
29
|
-
* failing it.
|
|
30
|
-
*/
|
|
31
|
-
export const METHOD_TO_CAPABILITY = {
|
|
32
|
-
"elicitation/create": "elicitation",
|
|
33
|
-
"sampling/createMessage": "sampling",
|
|
34
|
-
"roots/list": "roots",
|
|
35
|
-
};
|
|
36
|
-
// ── checkInputRequestCapabilities ─────────────────────────────────────────────
|
|
37
|
-
/**
|
|
38
|
-
* Verify that every `inputRequest` entry maps to a capability the client declared.
|
|
39
|
-
*
|
|
40
|
-
* Mapping (spec 2026-07-28):
|
|
41
|
-
* elicitation/create → clientCapabilities.elicitation
|
|
42
|
-
* sampling/createMessage → clientCapabilities.sampling
|
|
43
|
-
* roots/list → clientCapabilities.roots
|
|
44
|
-
*
|
|
45
|
-
* Unknown methods fail-safe: the spec only permits the three methods above.
|
|
46
|
-
* An unknown method in `inputRequests` is a server-authoring bug and is
|
|
47
|
-
* rejected here before it reaches the wire.
|
|
48
|
-
*
|
|
49
|
-
* @param inputRequests - The map from the handler's `InputRequiredSignal`.
|
|
50
|
-
* @param clientCapabilities - Parsed from `params._meta[STATELESS_CLIENT_CAPABILITIES_KEY]`.
|
|
51
|
-
* `undefined` when the client sent no `_meta` at all —
|
|
52
|
-
* treated as "no capabilities declared".
|
|
53
|
-
* @returns `{ ok: true }` or `{ ok: false, missingCapabilities: string[] }`.
|
|
54
|
-
*/
|
|
55
|
-
function isRecord(v) {
|
|
56
|
-
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Reduce a value to what it will actually be on the wire.
|
|
60
|
-
*
|
|
61
|
-
* The gate must inspect the JSON representation, not the live object: the two can
|
|
62
|
-
* differ. `new String("url")` is not `=== "url"` but serialises to `"url"`, and a
|
|
63
|
-
* `toJSON()` can introduce fields — `tools`, say — that exist only after
|
|
64
|
-
* serialisation. Checking the live object then shipping the serialised one means
|
|
65
|
-
* the check and the payload disagree, which is precisely the gap a caller would
|
|
66
|
-
* use to obtain an input request the client cannot service.
|
|
67
|
-
*
|
|
68
|
-
* Returns `undefined` when the value cannot be serialised at all, which callers
|
|
69
|
-
* treat as malformed.
|
|
70
|
-
*/
|
|
71
|
-
function canonicalise(value) {
|
|
72
|
-
try {
|
|
73
|
-
return JSON.parse(JSON.stringify(value ?? null));
|
|
74
|
-
}
|
|
75
|
-
catch {
|
|
76
|
-
return undefined;
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
export function checkInputRequestCapabilities(inputRequests, clientCapabilities) {
|
|
80
|
-
// Collect every capability key that is required by the inputRequests.
|
|
81
|
-
// Use a Set to deduplicate: multiple slots may require the same capability.
|
|
82
|
-
// Canonicalise the WHOLE map once. Everything below inspects this clone, and the
|
|
83
|
-
// caller emits it — so the value checked and the value sent are the same object,
|
|
84
|
-
// serialised once.
|
|
85
|
-
const canonicalRequests = canonicalise(inputRequests);
|
|
86
|
-
if (!isRecord(canonicalRequests)) {
|
|
87
|
-
return {
|
|
88
|
-
ok: false,
|
|
89
|
-
kind: "malformed",
|
|
90
|
-
missingCapabilities: ["<inputRequests could not be serialised>"],
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const required = new Set();
|
|
94
|
-
for (const entry of Object.values(canonicalRequests)) {
|
|
95
|
-
// Sub-capabilities: declaring `elicitation` does not grant URL mode, and
|
|
96
|
-
// declaring `sampling` does not grant tool-using sampling. Checking only the
|
|
97
|
-
// top-level key let a server ask for a mode the client cannot service, which
|
|
98
|
-
// strands the request exactly as an undeclared capability would.
|
|
99
|
-
// The map VALUE must itself be an object. `{ k: null }` serialises fine, so it
|
|
100
|
-
// survived canonicalisation and then threw on `entry.params` — landing in the
|
|
101
|
-
// generic tool-error path as a 200, not the 500 a malformed server output
|
|
102
|
-
// requires. Checked before anything dereferences it.
|
|
103
|
-
if (!isRecord(entry)) {
|
|
104
|
-
return {
|
|
105
|
-
ok: false,
|
|
106
|
-
kind: "malformed",
|
|
107
|
-
missingCapabilities: [
|
|
108
|
-
"<inputRequests values must be request objects>",
|
|
109
|
-
],
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
// `method` must be a string, and looked up as an OWN key.
|
|
113
|
-
//
|
|
114
|
-
// Two distinct faults hid here. A non-string method — `{ toString: null }`
|
|
115
|
-
// survives JSON — throws a TypeError when used as a property key, landing in
|
|
116
|
-
// the generic tool-error path as a 200. And `"toString"` or `"constructor"`
|
|
117
|
-
// resolve INHERITED properties of the mapping object, so `capKey` came back
|
|
118
|
-
// as a function rather than undefined and produced a nonsense
|
|
119
|
-
// missing-capability error naming a method that does not exist.
|
|
120
|
-
if (typeof entry.method !== "string") {
|
|
121
|
-
return {
|
|
122
|
-
ok: false,
|
|
123
|
-
kind: "malformed",
|
|
124
|
-
missingCapabilities: ["<inputRequest method must be a string>"],
|
|
125
|
-
};
|
|
126
|
-
}
|
|
127
|
-
// Already canonical: `entry` came out of the clone above. A `params` that is
|
|
128
|
-
// present but not an object is malformed — reading it as `{}` would skip the
|
|
129
|
-
// sub-capability checks entirely, a server-authoring bug resolving to "no
|
|
130
|
-
// extra capability needed".
|
|
131
|
-
//
|
|
132
|
-
// `null` is rejected along with the rest, deliberately. I had intended to let
|
|
133
|
-
// it through as equivalent to "absent", but the two are not the same: omitting
|
|
134
|
-
// `params` says the request needs none, while `params: null` asserts a value
|
|
135
|
-
// that the schema types as an object. Accepting it would mean the sub-capability
|
|
136
|
-
// checks silently do not run for a request that looks like it declared
|
|
137
|
-
// something.
|
|
138
|
-
//
|
|
139
|
-
// Absence is method-specific: the schema requires `params` on
|
|
140
|
-
// `elicitation/create` (message + requestedSchema) and `sampling/createMessage`
|
|
141
|
-
// (messages + maxTokens). Only `ListRootsRequest` may omit it. Accepting an
|
|
142
|
-
// omission everywhere let a request ship that no client could service — it has
|
|
143
|
-
// nothing to render or sample.
|
|
144
|
-
if (entry.params === undefined && entry.method !== "roots/list") {
|
|
145
|
-
return {
|
|
146
|
-
ok: false,
|
|
147
|
-
kind: "malformed",
|
|
148
|
-
missingCapabilities: [
|
|
149
|
-
`<${entry.method} requires params>`,
|
|
150
|
-
],
|
|
151
|
-
};
|
|
152
|
-
}
|
|
153
|
-
if (entry.params !== undefined && !isRecord(entry.params)) {
|
|
154
|
-
return {
|
|
155
|
-
ok: false,
|
|
156
|
-
kind: "malformed",
|
|
157
|
-
missingCapabilities: [
|
|
158
|
-
`<malformed inputRequest params for ${entry.method}>`,
|
|
159
|
-
],
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
const params = isRecord(entry.params) ? entry.params : {};
|
|
163
|
-
if (entry.method === "elicitation/create" && params["mode"] === "url") {
|
|
164
|
-
const elicitation = isRecord(clientCapabilities?.["elicitation"])
|
|
165
|
-
? clientCapabilities["elicitation"]
|
|
166
|
-
: undefined;
|
|
167
|
-
if (elicitation?.["url"] === undefined) {
|
|
168
|
-
return {
|
|
169
|
-
ok: false,
|
|
170
|
-
kind: "missing_capability",
|
|
171
|
-
missingCapabilities: ["elicitation.url"],
|
|
172
|
-
// Nested, matching ClientCapabilities. A flat "elicitation.url" key
|
|
173
|
-
// deserialises to `{}` on a typed client — it reads as "nothing
|
|
174
|
-
// missing", the opposite of the message.
|
|
175
|
-
requiredCapabilities: { elicitation: { url: {} } },
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (entry.method === "sampling/createMessage" &&
|
|
180
|
-
(params["tools"] !== undefined || params["toolChoice"] !== undefined)) {
|
|
181
|
-
const sampling = isRecord(clientCapabilities?.["sampling"])
|
|
182
|
-
? clientCapabilities["sampling"]
|
|
183
|
-
: undefined;
|
|
184
|
-
if (sampling?.["tools"] === undefined) {
|
|
185
|
-
return {
|
|
186
|
-
ok: false,
|
|
187
|
-
kind: "missing_capability",
|
|
188
|
-
missingCapabilities: ["sampling.tools"],
|
|
189
|
-
requiredCapabilities: { sampling: { tools: {} } },
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
const capKey = Object.hasOwn(METHOD_TO_CAPABILITY, entry.method)
|
|
194
|
-
? METHOD_TO_CAPABILITY[entry.method]
|
|
195
|
-
: undefined;
|
|
196
|
-
if (capKey === undefined) {
|
|
197
|
-
// MRTR permits exactly three methods. An unknown one is invalid outright,
|
|
198
|
-
// so it must fail regardless of what the client declared — mapping it to
|
|
199
|
-
// its own name let a client "satisfy" it by declaring a capability of the
|
|
200
|
-
// same name, which is not a capability at all.
|
|
201
|
-
return {
|
|
202
|
-
ok: false,
|
|
203
|
-
kind: "malformed",
|
|
204
|
-
missingCapabilities: [
|
|
205
|
-
`<unsupported inputRequest method: ${entry.method}>`,
|
|
206
|
-
],
|
|
207
|
-
};
|
|
208
|
-
}
|
|
209
|
-
required.add(capKey);
|
|
210
|
-
}
|
|
211
|
-
if (required.size === 0) {
|
|
212
|
-
// Empty inputRequests map — nothing to check
|
|
213
|
-
return { ok: true, canonicalRequests };
|
|
214
|
-
}
|
|
215
|
-
const missing = [];
|
|
216
|
-
for (const capKey of required) {
|
|
217
|
-
// The client "declared" the capability when its key is present in
|
|
218
|
-
// `clientCapabilities` with any value (including `{}`). An absent key or
|
|
219
|
-
// an undefined `clientCapabilities` object means "not declared".
|
|
220
|
-
const declared = clientCapabilities !== undefined &&
|
|
221
|
-
Object.hasOwn(clientCapabilities, capKey);
|
|
222
|
-
if (!declared)
|
|
223
|
-
missing.push(capKey);
|
|
224
|
-
}
|
|
225
|
-
if (missing.length > 0) {
|
|
226
|
-
return {
|
|
227
|
-
ok: false,
|
|
228
|
-
kind: "missing_capability",
|
|
229
|
-
missingCapabilities: missing,
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
return { ok: true, canonicalRequests };
|
|
233
|
-
}
|
package/esm/src/mrtr/mod.d.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MRTR — Multi Round-Trip Requests (Track B, spec 2026-07-28, SEP-2322).
|
|
3
|
-
*
|
|
4
|
-
* Public re-export barrel. Import everything the transport layer needs from
|
|
5
|
-
* this single path rather than reaching into sub-modules directly.
|
|
6
|
-
*
|
|
7
|
-
* @module lib/server/mrtr
|
|
8
|
-
*/
|
|
9
|
-
export type { InputRequestEntry, InputRequestMethod, InputRequiredSignal, MrtrOptions, } from "./types.js";
|
|
10
|
-
export type { MemoryMrtrReplayStoreOptions, MrtrReplayStore, } from "./replay-store.js";
|
|
11
|
-
export { MemoryMrtrReplayStore } from "./replay-store.js";
|
|
12
|
-
export type { GuardMrtrRetryInput, MrtrRetryBindings, MrtrRetryGuardOutcome, } from "./retry-guard.js";
|
|
13
|
-
export { guardMrtrRetry } from "./retry-guard.js";
|
|
14
|
-
export type { RequestStatePayload, RequestStateRejectionReason, VerifyResult, } from "./request-state.js";
|
|
15
|
-
export { exportStateKey, generateStateKey, importStateKey, paramsDigest, sealRequestState, verifyRequestState, } from "./request-state.js";
|
|
16
|
-
export type { CapabilityCheckFail, CapabilityCheckOk, CapabilityCheckResult, } from "./capability-check.js";
|
|
17
|
-
export { checkInputRequestCapabilities } from "./capability-check.js";
|
|
18
|
-
//# sourceMappingURL=mod.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../../../src/src/mrtr/mod.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,YAAY,EACV,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,WAAW,GACZ,MAAM,YAAY,CAAC;AAGpB,YAAY,EACV,4BAA4B,EAC5B,eAAe,GAChB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAG1D,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,YAAY,EACV,mBAAmB,EACnB,2BAA2B,EAC3B,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,oBAAoB,CAAC;AAG5B,YAAY,EACV,mBAAmB,EACnB,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC"}
|
package/esm/src/mrtr/mod.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MRTR — Multi Round-Trip Requests (Track B, spec 2026-07-28, SEP-2322).
|
|
3
|
-
*
|
|
4
|
-
* Public re-export barrel. Import everything the transport layer needs from
|
|
5
|
-
* this single path rather than reaching into sub-modules directly.
|
|
6
|
-
*
|
|
7
|
-
* @module lib/server/mrtr
|
|
8
|
-
*/
|
|
9
|
-
export { MemoryMrtrReplayStore } from "./replay-store.js";
|
|
10
|
-
export { guardMrtrRetry } from "./retry-guard.js";
|
|
11
|
-
export { exportStateKey, generateStateKey, importStateKey, paramsDigest, sealRequestState, verifyRequestState, } from "./request-state.js";
|
|
12
|
-
export { checkInputRequestCapabilities } from "./capability-check.js";
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Atomic nonce consumption for MRTR requestState tokens.
|
|
3
|
-
*
|
|
4
|
-
* Integrity verification proves that a token was minted by the server and is
|
|
5
|
-
* bound to the current request. A replay store adds the separate single-use
|
|
6
|
-
* property by reserving the signed nonce before business logic runs.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Store used to consume a verified MRTR nonce exactly once.
|
|
10
|
-
*
|
|
11
|
-
* Implementations MUST make the check-and-reserve operation atomic. Return
|
|
12
|
-
* `true` only for the caller that reserved the nonce, `false` when it was
|
|
13
|
-
* already consumed, and throw when availability cannot be established.
|
|
14
|
-
*
|
|
15
|
-
* `expiresAt` is the signed token expiry as Unix epoch seconds. Stores should
|
|
16
|
-
* remove the reservation after that time; retaining it longer is safe but
|
|
17
|
-
* wastes capacity.
|
|
18
|
-
*
|
|
19
|
-
* A load-balanced deployment MUST provide one shared implementation to every
|
|
20
|
-
* McpApp instance. Redis can implement the contract with `SET key 1 NX EXAT`.
|
|
21
|
-
*/
|
|
22
|
-
export interface MrtrReplayStore {
|
|
23
|
-
consume(nonce: string, expiresAt: number): boolean | Promise<boolean>;
|
|
24
|
-
}
|
|
25
|
-
export interface MemoryMrtrReplayStoreOptions {
|
|
26
|
-
/**
|
|
27
|
-
* Maximum live reservations before the store fails closed.
|
|
28
|
-
*
|
|
29
|
-
* Default: 100,000.
|
|
30
|
-
*/
|
|
31
|
-
maxEntries?: number;
|
|
32
|
-
/** Test seam for the current Unix epoch time in seconds. */
|
|
33
|
-
nowSecs?: () => number;
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Process-local replay protection.
|
|
37
|
-
*
|
|
38
|
-
* This is the safe default for one continuously running McpApp process. It
|
|
39
|
-
* cannot coordinate separate processes or survive a restart; horizontally
|
|
40
|
-
* scaled or restart-safe deployments must inject a durable shared
|
|
41
|
-
* `MrtrReplayStore`.
|
|
42
|
-
*/
|
|
43
|
-
export declare class MemoryMrtrReplayStore implements MrtrReplayStore {
|
|
44
|
-
private readonly entries;
|
|
45
|
-
private readonly maxEntries;
|
|
46
|
-
private readonly nowSecs;
|
|
47
|
-
constructor(options?: MemoryMrtrReplayStoreOptions);
|
|
48
|
-
consume(nonce: string, expiresAt: number): boolean;
|
|
49
|
-
}
|
|
50
|
-
//# sourceMappingURL=replay-store.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"replay-store.d.ts","sourceRoot":"","sources":["../../../src/src/mrtr/replay-store.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,eAAe;IAC9B,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACvE;AAED,MAAM,WAAW,4BAA4B;IAC3C;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,4DAA4D;IAC5D,OAAO,CAAC,EAAE,MAAM,MAAM,CAAC;CACxB;AAED;;;;;;;GAOG;AACH,qBAAa,qBAAsB,YAAW,eAAe;IAC3D,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA6B;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAe;gBAE3B,OAAO,GAAE,4BAAiC;IAWtD,OAAO,CAAC,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO;CAwCnD"}
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Atomic nonce consumption for MRTR requestState tokens.
|
|
3
|
-
*
|
|
4
|
-
* Integrity verification proves that a token was minted by the server and is
|
|
5
|
-
* bound to the current request. A replay store adds the separate single-use
|
|
6
|
-
* property by reserving the signed nonce before business logic runs.
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* Process-local replay protection.
|
|
10
|
-
*
|
|
11
|
-
* This is the safe default for one continuously running McpApp process. It
|
|
12
|
-
* cannot coordinate separate processes or survive a restart; horizontally
|
|
13
|
-
* scaled or restart-safe deployments must inject a durable shared
|
|
14
|
-
* `MrtrReplayStore`.
|
|
15
|
-
*/
|
|
16
|
-
export class MemoryMrtrReplayStore {
|
|
17
|
-
entries = new Map();
|
|
18
|
-
maxEntries;
|
|
19
|
-
nowSecs;
|
|
20
|
-
constructor(options = {}) {
|
|
21
|
-
const maxEntries = options.maxEntries ?? 100_000;
|
|
22
|
-
if (!Number.isSafeInteger(maxEntries) || maxEntries < 1) {
|
|
23
|
-
throw new Error(`MemoryMrtrReplayStore maxEntries must be a positive integer (got ${maxEntries})`);
|
|
24
|
-
}
|
|
25
|
-
this.maxEntries = maxEntries;
|
|
26
|
-
this.nowSecs = options.nowSecs ?? (() => Math.floor(Date.now() / 1000));
|
|
27
|
-
}
|
|
28
|
-
consume(nonce, expiresAt) {
|
|
29
|
-
if (!/^[0-9a-f]{32}$/.test(nonce)) {
|
|
30
|
-
throw new Error("MRTR replay nonce must be 32 lowercase hex characters");
|
|
31
|
-
}
|
|
32
|
-
if (!Number.isSafeInteger(expiresAt) || expiresAt < 0) {
|
|
33
|
-
throw new Error("MRTR replay expiry must be a non-negative safe-integer Unix timestamp");
|
|
34
|
-
}
|
|
35
|
-
const now = this.nowSecs();
|
|
36
|
-
if (!Number.isSafeInteger(now) || now < 0) {
|
|
37
|
-
throw new Error("MRTR replay clock must return a non-negative safe-integer Unix timestamp");
|
|
38
|
-
}
|
|
39
|
-
const existingExpiry = this.entries.get(nonce);
|
|
40
|
-
if (existingExpiry !== undefined) {
|
|
41
|
-
if (existingExpiry > now)
|
|
42
|
-
return false;
|
|
43
|
-
this.entries.delete(nonce);
|
|
44
|
-
}
|
|
45
|
-
if (expiresAt <= now)
|
|
46
|
-
return false;
|
|
47
|
-
if (this.entries.size >= this.maxEntries) {
|
|
48
|
-
for (const [storedNonce, storedExpiry] of this.entries) {
|
|
49
|
-
if (storedExpiry <= now)
|
|
50
|
-
this.entries.delete(storedNonce);
|
|
51
|
-
}
|
|
52
|
-
if (this.entries.size >= this.maxEntries) {
|
|
53
|
-
throw new Error(`MRTR replay store capacity exceeded (${this.maxEntries} live nonces)`);
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
// No await may occur between the check and this write. In one JS process,
|
|
57
|
-
// that makes the reservation atomic across concurrent request continuations.
|
|
58
|
-
this.entries.set(nonce, expiresAt);
|
|
59
|
-
return true;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* requestState seal/verify — HMAC-SHA256 integrity protection for MRTR tokens
|
|
3
|
-
* (spec 2026-07-28, SEP-2322 §Server Requirements, rule 4-5).
|
|
4
|
-
*
|
|
5
|
-
* The spec requires integrity protection whenever `requestState` influences
|
|
6
|
-
* authorization, resource access, or business logic. This module implements
|
|
7
|
-
* that protection with HMAC-SHA256 over a canonical JSON encoding — not AES-GCM,
|
|
8
|
-
* because the server needs the payload readable (for the binding checks in
|
|
9
|
-
* `verifyRequestState`) and the only threat model it addresses is CLIENT-SIDE
|
|
10
|
-
* TAMPERING. The client sees the token; confidentiality of individual fields is
|
|
11
|
-
* not required. AES-GCM would add the `nonce` / `tag` overhead of authenticated
|
|
12
|
-
* encryption without the benefit, since the `sub`/`method`/`paramsDigest` bindings
|
|
13
|
-
* already prevent cross-request / cross-user replay.
|
|
14
|
-
*
|
|
15
|
-
* Wire format (deliberately NOT JWT — JWT headers add no value here since the
|
|
16
|
-
* algorithm is fixed, and they invite consumers to parse the token as one):
|
|
17
|
-
* base64url(utf8(canonicalJson(payload))) + "." + base64url(hmacBytes)
|
|
18
|
-
*
|
|
19
|
-
* The HMAC covers the base64url-encoded JSON string (as UTF-8 bytes), not the
|
|
20
|
-
* raw JSON. This means the MAC is over the encoding as well as the content,
|
|
21
|
-
* preventing attacks that try to craft a byte string that decodes differently
|
|
22
|
-
* under different parsers.
|
|
23
|
-
*
|
|
24
|
-
* Canonical JSON: keys sorted lexicographically at every nesting level, no
|
|
25
|
-
* extra whitespace, UTF-8 encoded. Two implementations of the same payload
|
|
26
|
-
* always produce the same canonical form.
|
|
27
|
-
*
|
|
28
|
-
* All functions are pure and async (Web Crypto). No network, no server state.
|
|
29
|
-
*
|
|
30
|
-
* @module lib/server/mrtr/request-state
|
|
31
|
-
*/
|
|
32
|
-
/**
|
|
33
|
-
* Claims embedded inside the HMAC-SHA256-protected requestState token.
|
|
34
|
-
*
|
|
35
|
-
* All fields participate in the MAC: modifying any byte causes HMAC mismatch.
|
|
36
|
-
*
|
|
37
|
-
* Replay-bounding properties:
|
|
38
|
-
* - `sub` prevents a different user from reusing the same token.
|
|
39
|
-
* - `exp` limits the time window for replay.
|
|
40
|
-
* - `method` + `paramsDigest` prevent cross-request replay
|
|
41
|
-
* (a token for `tools/call(echo)` is rejected on `tools/call(exec)` or
|
|
42
|
-
* `resources/read`).
|
|
43
|
-
* - `nonce` ensures tokens minted at the same second for the same call are
|
|
44
|
-
* non-identical, defeating precomputation attacks.
|
|
45
|
-
*
|
|
46
|
-
* What these measures do NOT guarantee: single-use within the TTL. The spec
|
|
47
|
-
* explicitly warns about this. Deployers who need at-most-once semantics MUST
|
|
48
|
-
* consume the `nonce` in a server-side store on first use.
|
|
49
|
-
*/
|
|
50
|
-
export interface RequestStatePayload {
|
|
51
|
-
/** Authenticated principal (JWT sub, hashed API-key, …). */
|
|
52
|
-
readonly sub: string;
|
|
53
|
-
/** JSON-RPC method of the originating request (e.g. "tools/call"). */
|
|
54
|
-
readonly method: string;
|
|
55
|
-
/**
|
|
56
|
-
* Hex-encoded SHA-256 of the canonical JSON of salient parameters.
|
|
57
|
-
*
|
|
58
|
-
* For tools/call: canonicalJson({ arguments: args, name: toolName })
|
|
59
|
-
* For resources/read: canonicalJson({ uri })
|
|
60
|
-
* For prompts/get: canonicalJson({ name: promptName })
|
|
61
|
-
*
|
|
62
|
-
* Binding the token to these parameters prevents cross-argument replay:
|
|
63
|
-
* a token minted for `tools/call(echo, {})` is rejected on
|
|
64
|
-
* `tools/call(exec, {cmd:"rm -rf /"})`.
|
|
65
|
-
*/
|
|
66
|
-
readonly paramsDigest: string;
|
|
67
|
-
/** Unix epoch seconds (integer) after which the token MUST be rejected. */
|
|
68
|
-
readonly exp: number;
|
|
69
|
-
/**
|
|
70
|
-
* 16-byte random hex nonce, minted at seal time.
|
|
71
|
-
*
|
|
72
|
-
* Generate with: `bytesToHex(crypto.getRandomValues(new Uint8Array(16)))`.
|
|
73
|
-
*
|
|
74
|
-
* Does NOT guarantee single-use — see the module docstring. Its purpose is to
|
|
75
|
-
* ensure tokens minted for the same call at the same second are non-identical.
|
|
76
|
-
*/
|
|
77
|
-
readonly nonce: string;
|
|
78
|
-
}
|
|
79
|
-
/** Reason a `verifyRequestState` call returned `ok: false`. */
|
|
80
|
-
export type RequestStateRejectionReason =
|
|
81
|
-
/** HMAC mismatch: one or more bytes of the payload were modified after sealing. */
|
|
82
|
-
"tampered"
|
|
83
|
-
/** `sub` does not match the current authenticated principal. */
|
|
84
|
-
| "wrong_principal"
|
|
85
|
-
/** `exp` is in the past (or at `nowSecs`). */
|
|
86
|
-
| "expired"
|
|
87
|
-
/** `method` does not match the current JSON-RPC method. */
|
|
88
|
-
| "wrong_method"
|
|
89
|
-
/** `paramsDigest` does not match the current salient parameters. */
|
|
90
|
-
| "wrong_params";
|
|
91
|
-
/** Return value of `verifyRequestState`. */
|
|
92
|
-
export type VerifyResult = {
|
|
93
|
-
readonly ok: true;
|
|
94
|
-
readonly payload: RequestStatePayload;
|
|
95
|
-
} | {
|
|
96
|
-
readonly ok: false;
|
|
97
|
-
readonly reason: RequestStateRejectionReason;
|
|
98
|
-
readonly message: string;
|
|
99
|
-
};
|
|
100
|
-
/**
|
|
101
|
-
* Import a 32-byte key expressed as 64 lowercase hex characters.
|
|
102
|
-
* The resulting `CryptoKey` supports HMAC-SHA256 sign + verify.
|
|
103
|
-
*
|
|
104
|
-
* @throws If `hexKey` is not exactly 64 lowercase hex chars.
|
|
105
|
-
*/
|
|
106
|
-
export declare function importStateKey(hexKey: string): Promise<CryptoKey>;
|
|
107
|
-
/**
|
|
108
|
-
* Generate a fresh 32-byte HMAC-SHA256 key.
|
|
109
|
-
*
|
|
110
|
-
* Marked `extractable: true` so `exportStateKey` can convert it to hex for
|
|
111
|
-
* storage. Keys at rest should be stored in a secrets manager, not logged.
|
|
112
|
-
*/
|
|
113
|
-
export declare function generateStateKey(): Promise<CryptoKey>;
|
|
114
|
-
/**
|
|
115
|
-
* Export a `CryptoKey` to 64-char lowercase hex for storage or serialization.
|
|
116
|
-
*
|
|
117
|
-
* Only works on keys created with `generateStateKey()` (which sets
|
|
118
|
-
* `extractable: true`). Keys imported with `importStateKey()` are non-extractable
|
|
119
|
-
* by design — re-hex from the original string instead.
|
|
120
|
-
*/
|
|
121
|
-
export declare function exportStateKey(key: CryptoKey): Promise<string>;
|
|
122
|
-
/**
|
|
123
|
-
* Compute the hex-encoded SHA-256 of the canonical JSON of `salientParams`.
|
|
124
|
-
*
|
|
125
|
-
* Pass the result as `paramsDigest` when building a `RequestStatePayload`.
|
|
126
|
-
* Also pass it as `expected.paramsDigest` to `verifyRequestState` on retry
|
|
127
|
-
* to avoid hashing the same input twice.
|
|
128
|
-
*
|
|
129
|
-
* Canonical encoding is deterministic regardless of JS object property order,
|
|
130
|
-
* so the digest is stable across re-construction of the same logical value.
|
|
131
|
-
*/
|
|
132
|
-
export declare function paramsDigest(salientParams: unknown): Promise<string>;
|
|
133
|
-
/**
|
|
134
|
-
* Seal a `RequestStatePayload` into a compact, integrity-protected token.
|
|
135
|
-
*
|
|
136
|
-
* Wire format:
|
|
137
|
-
* base64url(utf8(canonicalJson(payload))) + "." + base64url(hmacSha256)
|
|
138
|
-
*
|
|
139
|
-
* The HMAC covers the base64url-encoded JSON string (as UTF-8 bytes), not the
|
|
140
|
-
* raw JSON, so the MAC binds the encoding. Both segments are base64url (no
|
|
141
|
-
* padding, URL-safe alphabet).
|
|
142
|
-
*
|
|
143
|
-
* @param payload - Fully-formed `RequestStatePayload`. The caller is responsible
|
|
144
|
-
* for generating the `nonce`; see `types.ts` for guidance.
|
|
145
|
-
* @param key - HMAC-SHA256 key from `importStateKey` or `generateStateKey`.
|
|
146
|
-
* @returns Opaque token string to carry in `InputRequiredSignal.requestState`.
|
|
147
|
-
*/
|
|
148
|
-
export declare function sealRequestState(payload: RequestStatePayload, key: CryptoKey): Promise<string>;
|
|
149
|
-
/**
|
|
150
|
-
* Verify a `requestState` token against the expected claims for the current request.
|
|
151
|
-
*
|
|
152
|
-
* The input `token` is ATTACKER-CONTROLLED (the spec requires treating it as
|
|
153
|
-
* such). Checks run in order: integrity first (so a tampered payload never
|
|
154
|
-
* reaches field comparison), then bindings from most-impactful to least.
|
|
155
|
-
*
|
|
156
|
-
* Rejection order: tampered → wrong_principal → expired → wrong_method → wrong_params
|
|
157
|
-
*
|
|
158
|
-
* Each rejection reason is distinct so the server can distinguish attack
|
|
159
|
-
* patterns in logs / metrics without leaking the payload to the client
|
|
160
|
-
* (the client receives only the generic -32602 error code and a safe message).
|
|
161
|
-
*
|
|
162
|
-
* @param token - The token as received from the client (untrusted).
|
|
163
|
-
* @param key - The server's HMAC-SHA256 signing key.
|
|
164
|
-
* @param expected - Values derived from the CURRENT (retry) request.
|
|
165
|
-
* @param expected.principal - Authenticated principal (JWT sub, …). Pass `""` when
|
|
166
|
-
* the endpoint is unauthenticated; the token's `sub`
|
|
167
|
-
* must also be `""` for a match.
|
|
168
|
-
* @param expected.method - JSON-RPC method of the retry request.
|
|
169
|
-
* @param expected.paramsDigest - Pre-computed digest of the retry's salient params.
|
|
170
|
-
* Avoids double-hashing: compute once, pass here and
|
|
171
|
-
* keep for business logic.
|
|
172
|
-
* @param expected.nowSecs - Wall-clock Unix epoch seconds. Defaults to
|
|
173
|
-
* `Math.floor(Date.now() / 1000)`. Override in tests.
|
|
174
|
-
*/
|
|
175
|
-
export declare function verifyRequestState(token: string, key: CryptoKey, expected: {
|
|
176
|
-
readonly principal: string;
|
|
177
|
-
readonly method: string;
|
|
178
|
-
readonly paramsDigest: string;
|
|
179
|
-
readonly nowSecs?: number;
|
|
180
|
-
}): Promise<VerifyResult>;
|
|
181
|
-
//# sourceMappingURL=request-state.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"request-state.d.ts","sourceRoot":"","sources":["../../../src/src/mrtr/request-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAIH;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,WAAW,mBAAmB;IAClC,4DAA4D;IAC5D,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,sEAAsE;IACtE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;;;;;;;OAUG;IACH,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,2EAA2E;IAC3E,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB;;;;;;;OAOG;IACH,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,+DAA+D;AAC/D,MAAM,MAAM,2BAA2B;AACrC,mFAAmF;AACjF,UAAU;AACZ,gEAAgE;GAC9D,iBAAiB;AACnB,8CAA8C;GAC5C,SAAS;AACX,2DAA2D;GACzD,cAAc;AAChB,oEAAoE;GAClE,cAAc,CAAC;AAEnB,4CAA4C;AAC5C,MAAM,MAAM,YAAY,GACpB;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,mBAAmB,CAAA;CAAE,GAC5D;IACA,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,2BAA2B,CAAC;IAC7C,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B,CAAC;AA+DJ;;;;;GAKG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC,CAmBvE;AAED;;;;;GAKG;AACH,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,SAAS,CAAC,CAU3D;AAED;;;;;;GAMG;AACH,wBAAsB,cAAc,CAAC,GAAG,EAAE,SAAS,GAAG,OAAO,CAAC,MAAM,CAAC,CAMpE;AAID;;;;;;;;;GASG;AACH,wBAAsB,YAAY,CAAC,aAAa,EAAE,OAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CAQ1E;AAID;;;;;;;;;;;;;;GAcG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,mBAAmB,EAC5B,GAAG,EAAE,SAAS,GACb,OAAO,CAAC,MAAM,CAAC,CAajB;AAID;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,wBAAsB,kBAAkB,CACtC,KAAK,EAAE,MAAM,EACb,GAAG,EAAE,SAAS,EACd,QAAQ,EAAE;IACR,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B,GACA,OAAO,CAAC,YAAY,CAAC,CAmHvB"}
|