@kya-os/mcp 1.18.0 → 1.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +336 -0
  2. package/CONFORMANCE.md +10 -4
  3. package/README.md +57 -0
  4. package/SPEC.md +37 -3
  5. package/dist/card/cimd.js +6 -2
  6. package/dist/card/cimd.js.map +1 -1
  7. package/dist/card/index.d.ts +1 -0
  8. package/dist/card/index.js +1 -0
  9. package/dist/card/index.js.map +1 -1
  10. package/dist/card/revocation.d.ts +15 -4
  11. package/dist/card/revocation.js +9 -4
  12. package/dist/card/revocation.js.map +1 -1
  13. package/dist/card/status-list-proof.d.ts +32 -0
  14. package/dist/card/status-list-proof.js +102 -0
  15. package/dist/card/status-list-proof.js.map +1 -0
  16. package/dist/delegation/verification-method-key.d.ts +4 -1
  17. package/dist/delegation/verification-method-key.js.map +1 -1
  18. package/dist/index.d.ts +1 -1
  19. package/dist/index.js +1 -1
  20. package/dist/index.js.map +1 -1
  21. package/dist/middleware/index.d.ts +3 -1
  22. package/dist/middleware/index.js +2 -0
  23. package/dist/middleware/index.js.map +1 -1
  24. package/dist/middleware/kya-os-transport.d.ts +43 -12
  25. package/dist/middleware/kya-os-transport.js +151 -28
  26. package/dist/middleware/kya-os-transport.js.map +1 -1
  27. package/dist/middleware/mcp-tool-callback.d.ts +48 -0
  28. package/dist/middleware/mcp-tool-callback.js +38 -0
  29. package/dist/middleware/mcp-tool-callback.js.map +1 -0
  30. package/dist/middleware/serve-in-process.d.ts +41 -0
  31. package/dist/middleware/serve-in-process.js +86 -0
  32. package/dist/middleware/serve-in-process.js.map +1 -0
  33. package/dist/middleware/with-kya-os-server.d.ts +14 -3
  34. package/dist/middleware/with-kya-os-server.js +4 -1
  35. package/dist/middleware/with-kya-os-server.js.map +1 -1
  36. package/dist/middleware/with-kya-os.config-types.d.ts +24 -0
  37. package/dist/middleware/with-kya-os.d.ts +4 -0
  38. package/dist/middleware/with-kya-os.delegation-gate.d.ts +2 -1
  39. package/dist/middleware/with-kya-os.delegation-gate.js +12 -18
  40. package/dist/middleware/with-kya-os.delegation-gate.js.map +1 -1
  41. package/dist/middleware/with-kya-os.delegation-verify.d.ts +7 -12
  42. package/dist/middleware/with-kya-os.delegation-verify.js +37 -9
  43. package/dist/middleware/with-kya-os.delegation-verify.js.map +1 -1
  44. package/dist/middleware/with-kya-os.deps.d.ts +15 -4
  45. package/dist/middleware/with-kya-os.helpers.d.ts +5 -0
  46. package/dist/middleware/with-kya-os.helpers.js +13 -0
  47. package/dist/middleware/with-kya-os.helpers.js.map +1 -1
  48. package/dist/middleware/with-kya-os.js +23 -0
  49. package/dist/middleware/with-kya-os.js.map +1 -1
  50. package/dist/middleware/with-kya-os.outcome.d.ts +18 -0
  51. package/dist/middleware/with-kya-os.outcome.js +36 -0
  52. package/dist/middleware/with-kya-os.outcome.js.map +1 -0
  53. package/dist/middleware/with-kya-os.policy-gate.d.ts +2 -1
  54. package/dist/middleware/with-kya-os.policy-gate.js +2 -1
  55. package/dist/middleware/with-kya-os.policy-gate.js.map +1 -1
  56. package/dist/middleware/with-kya-os.session.d.ts +76 -10
  57. package/dist/middleware/with-kya-os.session.js +739 -164
  58. package/dist/middleware/with-kya-os.session.js.map +1 -1
  59. package/dist/middleware/with-kya-os.types.d.ts +102 -8
  60. package/dist/proof/generator.d.ts +13 -0
  61. package/dist/proof/generator.js +15 -0
  62. package/dist/proof/generator.js.map +1 -1
  63. package/dist/proof/verifier.js +14 -9
  64. package/dist/proof/verifier.js.map +1 -1
  65. package/package.json +3 -1
@@ -5,9 +5,17 @@
5
5
  * live here, so the borrowing semantics are preserved exactly) and the two proof
6
6
  * paths: `wrapWithProof` (success responses) and `attachOutcomeProof` (denied /
7
7
  * step-up / needs-authorization outcomes). Extracted from `./with-kya-os.ts`.
8
+ *
9
+ * Neither path signs in the handler. The MCP SDK changes a result after the
10
+ * handler returns: SDK 2 adds `resultType` on the 2026-07-28 revision, which
11
+ * the envelope profile covers; both SDKs fill in a missing `content`, and SDK
12
+ * 2 appends a text item to `content` when `structuredContent` is not an
13
+ * object, which the body profile covers. Both paths therefore leave the proof
14
+ * to the outer layer, the withKyaOs transport, which makes it over the result
15
+ * it sends, under either profile.
8
16
  */
9
- import type { KyaOsToolHandler } from "./with-kya-os.types.js";
10
- import type { MiddlewareDeps, AttachOutcomeProof } from "./with-kya-os.deps.js";
17
+ import type { KyaOsToolHandler, KyaOsToolResult } from "./with-kya-os.types.js";
18
+ import type { MiddlewareDeps, AttachOutcomeProof, RequireProofLayer } from "./with-kya-os.deps.js";
11
19
  /**
12
20
  * The private `_meta` member a middleware's wrappers stamp their results with
13
21
  * while an outer layer (the withKyaOs transport) reads them. It holds a random
@@ -17,7 +25,16 @@ import type { MiddlewareDeps, AttachOutcomeProof } from "./with-kya-os.deps.js";
17
25
  * that.
18
26
  */
19
27
  export declare const LIFECYCLE_STAMP_META_KEY = "org.kya-os/lifecycle-stamp";
20
- type ToolResult = Awaited<ReturnType<KyaOsToolHandler>>;
28
+ /**
29
+ * The private `_meta` member that names the proof a wrapper left for the
30
+ * transport to make: a one-time id. What the proof
31
+ * claims stays in the middleware, keyed by that id, so code that can write a
32
+ * result cannot choose the claims. The transport redeems the id only on a
33
+ * result that also carries the middleware's stamp, and strips it as it strips
34
+ * the stamp. A string, so a copy of the result carries it too.
35
+ */
36
+ export declare const PENDING_PROOF_META_KEY = "org.kya-os/pending-proof";
37
+ type ToolResult = KyaOsToolResult;
21
38
  /**
22
39
  * Remove the `_meta` members only the middleware may set (proofs, proof error,
23
40
  * audit marker, lifecycle stamp) from a result it did not produce, keeping
@@ -25,16 +42,62 @@ type ToolResult = Awaited<ReturnType<KyaOsToolHandler>>;
25
42
  * is removed.
26
43
  */
27
44
  export declare function withoutOutcomeMeta<T extends ToolResult>(result: T): T;
28
- /** Remove the lifecycle stamp, which must never leave the process. */
29
- export declare function withoutLifecycleStamp<T extends ToolResult>(result: T): T;
45
+ /**
46
+ * Remove the middleware's private members, which must never leave the
47
+ * process, from `result` and from everything nested in it, at any depth.
48
+ */
49
+ export declare function withoutPrivateMeta<T extends ToolResult>(result: T): T;
50
+ /** Any value without the middleware's private `_meta` members, at any depth. */
51
+ export declare function withoutPrivateMembers(value: unknown): unknown;
52
+ /** What the outer layer (the withKyaOs transport) does with a middleware's results. */
53
+ export interface OuterProofLayer {
54
+ /**
55
+ * Count one more open transport, until the returned function is called.
56
+ * The wrappers refuse to run while none is open.
57
+ * Calling the returned function again does nothing.
58
+ */
59
+ open(): () => void;
60
+ /** Whether the middleware's wrappers returned `result`: it carries their stamp. */
61
+ owns(result: ToolResult): boolean;
62
+ /**
63
+ * `result` as it may leave the process: without the private members, and,
64
+ * when a wrapper left its proof to the transport, carrying that proof, made
65
+ * over `result` as it is now. Never throws: a proof that cannot be made is
66
+ * reported on the result, as one that fails in a wrapper is. A pending
67
+ * proof is redeemed once, and, when the result answers a `tools/call` the
68
+ * transport tracked, only by a proof left for that tool (`answering`).
69
+ */
70
+ send(result: ToolResult, answering?: {
71
+ toolName: string;
72
+ }): Promise<ToolResult>;
73
+ /**
74
+ * Any other part of an outgoing message (a notification's or request's
75
+ * `params`, an error's `data`) as it may leave the process: without the
76
+ * private members at any depth. A waiting proof whose id is found there
77
+ * is closed, so nothing can redeem it. Never throws.
78
+ */
79
+ scrub(value: unknown): unknown;
80
+ }
30
81
  /**
31
82
  * Tell the middleware behind `wrapWithProof` that an outer layer (the withKyaOs
32
83
  * transport) reads its results. From then on its wrappers stamp what they
33
- * return with the middleware's token. Returns the check for that stamp, or
84
+ * return with the middleware's token and leave their proofs to the layer.
85
+ * Returns the layer's view of those results, or
34
86
  * undefined for a middleware this module did not create, whose results are
35
87
  * then never treated as its own.
36
88
  */
37
- export declare function attachOuterProofLayer(wrapWithProof: object): ((result: ToolResult) => boolean) | undefined;
89
+ export declare function attachOuterProofLayer(wrapWithProof: object): OuterProofLayer | undefined;
90
+ /**
91
+ * The fallback session for a call that threaded none, or why there is none:
92
+ * `ambiguous` when several sessions are live and the middleware refuses to
93
+ * pick one, which might be another client's.
94
+ */
95
+ export type FallbackSession = {
96
+ sessionId: string;
97
+ } | {
98
+ sessionId: undefined;
99
+ ambiguous: boolean;
100
+ };
38
101
  export interface SessionProof {
39
102
  /** Establish a session from a handshake and cache it as the fallback. */
40
103
  handleHandshake(args: Record<string, unknown>): Promise<{
@@ -46,14 +109,17 @@ export interface SessionProof {
46
109
  }>;
47
110
  /**
48
111
  * Resolve the single-process fallback session for a call that threaded none —
49
- * or auto-create one when `config.autoSession` is set. Returns undefined (skip
50
- * the proof) when attribution would be ambiguous (multiple live sessions).
112
+ * or auto-create one when `config.autoSession` is set. Returns no session
113
+ * (skip the proof) when there is none, or, marked `ambiguous`, when
114
+ * attribution would be ambiguous (multiple live sessions).
51
115
  */
52
- ensureSession(): Promise<string | undefined>;
116
+ ensureSession(): Promise<FallbackSession>;
53
117
  /** Wrap a tool handler to attach a holder-of-key proof to success responses. */
54
118
  wrapWithProof<T extends Record<string, unknown> = Record<string, unknown>>(toolName: string, handler: KyaOsToolHandler<T>): KyaOsToolHandler;
55
119
  /** Attach a signed proof recording an authorization outcome to a response. */
56
120
  attachOutcomeProof: AttachOutcomeProof;
121
+ /** Refuse a wrapped call whose proof could not be made where it is sent. */
122
+ requireProofLayer: RequireProofLayer;
57
123
  }
58
124
  export declare function createSessionProof(deps: MiddlewareDeps): SessionProof;
59
125
  export {};