@kya-os/mcp-i-cloudflare 1.17.0 → 1.18.1

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 (268) hide show
  1. package/README.md +273 -54
  2. package/dist/adapter.d.ts +3 -17
  3. package/dist/adapter.d.ts.map +1 -1
  4. package/dist/adapter.js +39 -477
  5. package/dist/adapter.js.map +1 -1
  6. package/dist/agent.d.ts +59 -35
  7. package/dist/agent.d.ts.map +1 -1
  8. package/dist/agent.js +386 -404
  9. package/dist/agent.js.map +1 -1
  10. package/dist/app.d.ts.map +1 -1
  11. package/dist/app.js +150 -94
  12. package/dist/app.js.map +1 -1
  13. package/dist/audit/deployment-binding.d.ts +16 -16
  14. package/dist/authority-outcome.d.ts +110 -0
  15. package/dist/authority-outcome.d.ts.map +1 -0
  16. package/dist/authority-outcome.js +154 -0
  17. package/dist/authority-outcome.js.map +1 -0
  18. package/dist/config.d.ts +8 -77
  19. package/dist/config.d.ts.map +1 -1
  20. package/dist/config.js +0 -83
  21. package/dist/config.js.map +1 -1
  22. package/dist/delegation-http/bearer-retry.d.ts +84 -32
  23. package/dist/delegation-http/bearer-retry.d.ts.map +1 -1
  24. package/dist/delegation-http/bearer-retry.js +124 -139
  25. package/dist/delegation-http/bearer-retry.js.map +1 -1
  26. package/dist/delegation-http/connect-gate.d.ts +47 -0
  27. package/dist/delegation-http/connect-gate.d.ts.map +1 -0
  28. package/dist/delegation-http/connect-gate.js +104 -0
  29. package/dist/delegation-http/connect-gate.js.map +1 -0
  30. package/dist/delegation-http/constants.d.ts +4 -49
  31. package/dist/delegation-http/constants.d.ts.map +1 -1
  32. package/dist/delegation-http/constants.js +4 -58
  33. package/dist/delegation-http/constants.js.map +1 -1
  34. package/dist/delegation-http/issuer-binding.d.ts +26 -0
  35. package/dist/delegation-http/issuer-binding.d.ts.map +1 -0
  36. package/dist/delegation-http/issuer-binding.js +51 -0
  37. package/dist/delegation-http/issuer-binding.js.map +1 -0
  38. package/dist/delegation-http/lazy-auth-gate.d.ts +88 -0
  39. package/dist/delegation-http/lazy-auth-gate.d.ts.map +1 -0
  40. package/dist/delegation-http/lazy-auth-gate.js +203 -0
  41. package/dist/delegation-http/lazy-auth-gate.js.map +1 -0
  42. package/dist/delegation-http/native-challenge.d.ts +52 -0
  43. package/dist/delegation-http/native-challenge.d.ts.map +1 -0
  44. package/dist/delegation-http/native-challenge.js +124 -0
  45. package/dist/delegation-http/native-challenge.js.map +1 -0
  46. package/dist/delegation-http/native-consent-redirect.d.ts +21 -0
  47. package/dist/delegation-http/native-consent-redirect.d.ts.map +1 -0
  48. package/dist/delegation-http/native-consent-redirect.js +43 -0
  49. package/dist/delegation-http/native-consent-redirect.js.map +1 -0
  50. package/dist/delegation-http/native-http.d.ts +1 -86
  51. package/dist/delegation-http/native-http.d.ts.map +1 -1
  52. package/dist/delegation-http/native-http.js +2 -130
  53. package/dist/delegation-http/native-http.js.map +1 -1
  54. package/dist/delegation-http/native-oauth-state-do.d.ts +13 -35
  55. package/dist/delegation-http/native-oauth-state-do.d.ts.map +1 -1
  56. package/dist/delegation-http/native-oauth-state-do.js +10 -165
  57. package/dist/delegation-http/native-oauth-state-do.js.map +1 -1
  58. package/dist/delegation-http/protected-resource.d.ts +37 -0
  59. package/dist/delegation-http/protected-resource.d.ts.map +1 -0
  60. package/dist/delegation-http/protected-resource.js +43 -0
  61. package/dist/delegation-http/protected-resource.js.map +1 -0
  62. package/dist/delegation-http/request-proof.d.ts +20 -0
  63. package/dist/delegation-http/request-proof.d.ts.map +1 -0
  64. package/dist/delegation-http/request-proof.js +29 -0
  65. package/dist/delegation-http/request-proof.js.map +1 -0
  66. package/dist/delegation-http/sid.d.ts +4 -12
  67. package/dist/delegation-http/sid.d.ts.map +1 -1
  68. package/dist/delegation-http/sid.js +4 -19
  69. package/dist/delegation-http/sid.js.map +1 -1
  70. package/dist/delegation-http/well-known-capability.d.ts +8 -12
  71. package/dist/delegation-http/well-known-capability.d.ts.map +1 -1
  72. package/dist/delegation-http/well-known-capability.js +9 -18
  73. package/dist/delegation-http/well-known-capability.js.map +1 -1
  74. package/dist/helpers/env-mapper.d.ts.map +1 -1
  75. package/dist/helpers/env-mapper.js +7 -29
  76. package/dist/helpers/env-mapper.js.map +1 -1
  77. package/dist/index.d.ts +2 -4
  78. package/dist/index.d.ts.map +1 -1
  79. package/dist/index.js +11 -8
  80. package/dist/index.js.map +1 -1
  81. package/dist/proof-generator.d.ts +24 -17
  82. package/dist/proof-generator.d.ts.map +1 -1
  83. package/dist/proof-generator.js +42 -56
  84. package/dist/proof-generator.js.map +1 -1
  85. package/dist/runtime/amount-limit-refusal.d.ts +3 -0
  86. package/dist/runtime/amount-limit-refusal.d.ts.map +1 -0
  87. package/dist/runtime/amount-limit-refusal.js +7 -0
  88. package/dist/runtime/amount-limit-refusal.js.map +1 -0
  89. package/dist/runtime/oauth-handler.d.ts +1 -1
  90. package/dist/runtime/oauth-handler.d.ts.map +1 -1
  91. package/dist/runtime/oauth-handler.js +31 -34
  92. package/dist/runtime/oauth-handler.js.map +1 -1
  93. package/dist/runtime.d.ts +34 -10
  94. package/dist/runtime.d.ts.map +1 -1
  95. package/dist/runtime.js +65 -16
  96. package/dist/runtime.js.map +1 -1
  97. package/dist/security/admission-refusal.d.ts +3 -3
  98. package/dist/security/admission-refusal.d.ts.map +1 -1
  99. package/dist/security/admission-refusal.js +14 -6
  100. package/dist/security/admission-refusal.js.map +1 -1
  101. package/dist/security/holder-binding.d.ts +34 -0
  102. package/dist/security/holder-binding.d.ts.map +1 -0
  103. package/dist/security/holder-binding.js +75 -0
  104. package/dist/security/holder-binding.js.map +1 -0
  105. package/dist/security/mcp-admission.d.ts +29 -1
  106. package/dist/security/mcp-admission.d.ts.map +1 -1
  107. package/dist/security/mcp-admission.js +78 -12
  108. package/dist/security/mcp-admission.js.map +1 -1
  109. package/dist/security/native-holder-admission.d.ts +39 -0
  110. package/dist/security/native-holder-admission.d.ts.map +1 -0
  111. package/dist/security/native-holder-admission.js +65 -0
  112. package/dist/security/native-holder-admission.js.map +1 -0
  113. package/dist/security/outcome-proof.d.ts +39 -0
  114. package/dist/security/outcome-proof.d.ts.map +1 -0
  115. package/dist/security/outcome-proof.js +54 -0
  116. package/dist/security/outcome-proof.js.map +1 -0
  117. package/dist/security/request-nonce-store.d.ts +43 -0
  118. package/dist/security/request-nonce-store.d.ts.map +1 -0
  119. package/dist/security/request-nonce-store.js +129 -0
  120. package/dist/security/request-nonce-store.js.map +1 -0
  121. package/dist/security/routed-request.d.ts +41 -0
  122. package/dist/security/routed-request.d.ts.map +1 -0
  123. package/dist/security/routed-request.js +86 -0
  124. package/dist/security/routed-request.js.map +1 -0
  125. package/dist/security/sign-in-amr.d.ts +23 -0
  126. package/dist/security/sign-in-amr.d.ts.map +1 -0
  127. package/dist/security/sign-in-amr.js +44 -0
  128. package/dist/security/sign-in-amr.js.map +1 -0
  129. package/dist/services/approval-route.d.ts +3 -2
  130. package/dist/services/approval-route.d.ts.map +1 -1
  131. package/dist/services/approval-route.js.map +1 -1
  132. package/dist/services/checkpoint-decision.d.ts +56 -0
  133. package/dist/services/checkpoint-decision.d.ts.map +1 -0
  134. package/dist/services/checkpoint-decision.js +109 -0
  135. package/dist/services/checkpoint-decision.js.map +1 -0
  136. package/dist/services/consent-page-renderer.d.ts.map +1 -1
  137. package/dist/services/consent-page-renderer.js +2 -3
  138. package/dist/services/consent-page-renderer.js.map +1 -1
  139. package/dist/services/consent.service.d.ts +11 -49
  140. package/dist/services/consent.service.d.ts.map +1 -1
  141. package/dist/services/consent.service.js +81 -307
  142. package/dist/services/consent.service.js.map +1 -1
  143. package/dist/services/credential-auth.handler.d.ts.map +1 -1
  144. package/dist/services/credential-auth.handler.js +2 -8
  145. package/dist/services/credential-auth.handler.js.map +1 -1
  146. package/dist/services/delegation-authority.d.ts +53 -0
  147. package/dist/services/delegation-authority.d.ts.map +1 -0
  148. package/dist/services/delegation-authority.js +130 -0
  149. package/dist/services/delegation-authority.js.map +1 -0
  150. package/dist/services/delegation-trust.d.ts +35 -64
  151. package/dist/services/delegation-trust.d.ts.map +1 -1
  152. package/dist/services/delegation-trust.js +98 -279
  153. package/dist/services/delegation-trust.js.map +1 -1
  154. package/dist/services/delegation.service.d.ts +83 -105
  155. package/dist/services/delegation.service.d.ts.map +1 -1
  156. package/dist/services/delegation.service.js +166 -518
  157. package/dist/services/delegation.service.js.map +1 -1
  158. package/dist/services/idp-token-storage.d.ts +32 -12
  159. package/dist/services/idp-token-storage.d.ts.map +1 -1
  160. package/dist/services/idp-token-storage.js +79 -36
  161. package/dist/services/idp-token-storage.js.map +1 -1
  162. package/dist/services/issuer-keys.d.ts +55 -0
  163. package/dist/services/issuer-keys.d.ts.map +1 -0
  164. package/dist/services/issuer-keys.js +184 -0
  165. package/dist/services/issuer-keys.js.map +1 -0
  166. package/dist/services/oauth-security.service.d.ts +17 -1
  167. package/dist/services/oauth-security.service.d.ts.map +1 -1
  168. package/dist/services/oauth-security.service.js +29 -10
  169. package/dist/services/oauth-security.service.js.map +1 -1
  170. package/dist/services/proof.service.d.ts +10 -0
  171. package/dist/services/proof.service.d.ts.map +1 -1
  172. package/dist/services/proof.service.js +28 -6
  173. package/dist/services/proof.service.js.map +1 -1
  174. package/dist/services/resource-audience.d.ts +12 -9
  175. package/dist/services/resource-audience.d.ts.map +1 -1
  176. package/dist/services/resource-audience.js +12 -9
  177. package/dist/services/resource-audience.js.map +1 -1
  178. package/dist/services/unenforceable-tool-protection.d.ts +32 -0
  179. package/dist/services/unenforceable-tool-protection.d.ts.map +1 -0
  180. package/dist/services/unenforceable-tool-protection.js +90 -0
  181. package/dist/services/unenforceable-tool-protection.js.map +1 -0
  182. package/dist/services/upstream-fetch.d.ts +14 -0
  183. package/dist/services/upstream-fetch.d.ts.map +1 -0
  184. package/dist/services/upstream-fetch.js +56 -0
  185. package/dist/services/upstream-fetch.js.map +1 -0
  186. package/dist/types.d.ts +5 -18
  187. package/dist/types.d.ts.map +1 -1
  188. package/dist/utils/oauth-profile.d.ts +19 -0
  189. package/dist/utils/oauth-profile.d.ts.map +1 -1
  190. package/dist/utils/oauth-profile.js +54 -1
  191. package/dist/utils/oauth-profile.js.map +1 -1
  192. package/dist/utils/tool-security-schemes.d.ts +65 -0
  193. package/dist/utils/tool-security-schemes.d.ts.map +1 -0
  194. package/dist/utils/tool-security-schemes.js +168 -0
  195. package/dist/utils/tool-security-schemes.js.map +1 -0
  196. package/package.json +5 -6
  197. package/dist/delegation-http/anchor-do.d.ts +0 -84
  198. package/dist/delegation-http/anchor-do.d.ts.map +0 -1
  199. package/dist/delegation-http/anchor-do.js +0 -412
  200. package/dist/delegation-http/anchor-do.js.map +0 -1
  201. package/dist/delegation-http/anchor-registration-validate.d.ts +0 -61
  202. package/dist/delegation-http/anchor-registration-validate.d.ts.map +0 -1
  203. package/dist/delegation-http/anchor-registration-validate.js +0 -191
  204. package/dist/delegation-http/anchor-registration-validate.js.map +0 -1
  205. package/dist/delegation-http/anchor-registration.d.ts +0 -62
  206. package/dist/delegation-http/anchor-registration.d.ts.map +0 -1
  207. package/dist/delegation-http/anchor-registration.js +0 -337
  208. package/dist/delegation-http/anchor-registration.js.map +0 -1
  209. package/dist/delegation-http/anchor-routing.d.ts +0 -20
  210. package/dist/delegation-http/anchor-routing.d.ts.map +0 -1
  211. package/dist/delegation-http/anchor-routing.js +0 -27
  212. package/dist/delegation-http/anchor-routing.js.map +0 -1
  213. package/dist/delegation-http/challenge-middleware.d.ts +0 -28
  214. package/dist/delegation-http/challenge-middleware.d.ts.map +0 -1
  215. package/dist/delegation-http/challenge-middleware.js +0 -190
  216. package/dist/delegation-http/challenge-middleware.js.map +0 -1
  217. package/dist/delegation-http/challenge.d.ts +0 -102
  218. package/dist/delegation-http/challenge.d.ts.map +0 -1
  219. package/dist/delegation-http/challenge.js +0 -223
  220. package/dist/delegation-http/challenge.js.map +0 -1
  221. package/dist/delegation-http/consent-anchor-bridge.d.ts +0 -70
  222. package/dist/delegation-http/consent-anchor-bridge.d.ts.map +0 -1
  223. package/dist/delegation-http/consent-anchor-bridge.js +0 -1130
  224. package/dist/delegation-http/consent-anchor-bridge.js.map +0 -1
  225. package/dist/delegation-http/consent-preparation-page.d.ts +0 -18
  226. package/dist/delegation-http/consent-preparation-page.d.ts.map +0 -1
  227. package/dist/delegation-http/consent-preparation-page.js +0 -172
  228. package/dist/delegation-http/consent-preparation-page.js.map +0 -1
  229. package/dist/delegation-http/credential-consent.d.ts +0 -149
  230. package/dist/delegation-http/credential-consent.d.ts.map +0 -1
  231. package/dist/delegation-http/credential-consent.js +0 -338
  232. package/dist/delegation-http/credential-consent.js.map +0 -1
  233. package/dist/delegation-http/native-capabilities.d.ts +0 -4
  234. package/dist/delegation-http/native-capabilities.d.ts.map +0 -1
  235. package/dist/delegation-http/native-capabilities.js +0 -53
  236. package/dist/delegation-http/native-capabilities.js.map +0 -1
  237. package/dist/delegation-http/native-oauth-state.d.ts +0 -28
  238. package/dist/delegation-http/native-oauth-state.d.ts.map +0 -1
  239. package/dist/delegation-http/native-oauth-state.js +0 -146
  240. package/dist/delegation-http/native-oauth-state.js.map +0 -1
  241. package/dist/delegation-http/native-oauth.d.ts +0 -26
  242. package/dist/delegation-http/native-oauth.d.ts.map +0 -1
  243. package/dist/delegation-http/native-oauth.js +0 -393
  244. package/dist/delegation-http/native-oauth.js.map +0 -1
  245. package/dist/delegation-http/native-pickup.d.ts +0 -20
  246. package/dist/delegation-http/native-pickup.d.ts.map +0 -1
  247. package/dist/delegation-http/native-pickup.js +0 -227
  248. package/dist/delegation-http/native-pickup.js.map +0 -1
  249. package/dist/delegation-http/pickup-routes.d.ts +0 -43
  250. package/dist/delegation-http/pickup-routes.d.ts.map +0 -1
  251. package/dist/delegation-http/pickup-routes.js +0 -166
  252. package/dist/delegation-http/pickup-routes.js.map +0 -1
  253. package/dist/delegation-http/register.d.ts +0 -26
  254. package/dist/delegation-http/register.d.ts.map +0 -1
  255. package/dist/delegation-http/register.js +0 -95
  256. package/dist/delegation-http/register.js.map +0 -1
  257. package/dist/delegation-http/registrar-auth.d.ts +0 -24
  258. package/dist/delegation-http/registrar-auth.d.ts.map +0 -1
  259. package/dist/delegation-http/registrar-auth.js +0 -61
  260. package/dist/delegation-http/registrar-auth.js.map +0 -1
  261. package/dist/delegation-http/remote-issuer.d.ts +0 -52
  262. package/dist/delegation-http/remote-issuer.d.ts.map +0 -1
  263. package/dist/delegation-http/remote-issuer.js +0 -324
  264. package/dist/delegation-http/remote-issuer.js.map +0 -1
  265. package/dist/delegation-http/types.d.ts +0 -116
  266. package/dist/delegation-http/types.d.ts.map +0 -1
  267. package/dist/delegation-http/types.js +0 -11
  268. package/dist/delegation-http/types.js.map +0 -1
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Bounded upstream reads for delegation verification.
3
+ *
4
+ * DID documents and status lists are fetched from URLs a pinned issuer
5
+ * controls, but the bytes still cross the network: every fetch refuses
6
+ * redirects, times out, and is size-capped before anything is parsed.
7
+ */
8
+ /** GET `url` without following redirects, with a timeout. */
9
+ export declare function upstreamFetch(url: string, accept?: string): Promise<Response>;
10
+ /** Read a body, refusing it once it exceeds `maxBytes`. */
11
+ export declare function readBounded(stream: ReadableStream<Uint8Array> | null, maxBytes: number): Promise<Uint8Array>;
12
+ /** The body of a 200 response as text, size-capped; any other status throws. */
13
+ export declare function readBoundedText(response: Response, maxBytes: number): Promise<string>;
14
+ //# sourceMappingURL=upstream-fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstream-fetch.d.ts","sourceRoot":"","sources":["../../src/services/upstream-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAMH,6DAA6D;AAC7D,wBAAgB,aAAa,CAC3B,GAAG,EAAE,MAAM,EACX,MAAM,SAA8C,GACnD,OAAO,CAAC,QAAQ,CAAC,CAKnB;AAED,2DAA2D;AAC3D,wBAAsB,WAAW,CAC/B,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,EACzC,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,UAAU,CAAC,CA0BrB;AAED,gFAAgF;AAChF,wBAAsB,eAAe,CACnC,QAAQ,EAAE,QAAQ,EAClB,QAAQ,EAAE,MAAM,GACf,OAAO,CAAC,MAAM,CAAC,CAMjB"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Bounded upstream reads for delegation verification.
3
+ *
4
+ * DID documents and status lists are fetched from URLs a pinned issuer
5
+ * controls, but the bytes still cross the network: every fetch refuses
6
+ * redirects, times out, and is size-capped before anything is parsed.
7
+ */
8
+ import { fetchNativeNoRedirect } from "../delegation-http/native-fetch";
9
+ const UPSTREAM_TIMEOUT_MS = 3_000;
10
+ /** GET `url` without following redirects, with a timeout. */
11
+ export function upstreamFetch(url, accept = "application/did+ld+json, application/json") {
12
+ return fetchNativeNoRedirect(url, {
13
+ signal: AbortSignal.timeout(UPSTREAM_TIMEOUT_MS),
14
+ headers: { Accept: accept },
15
+ });
16
+ }
17
+ /** Read a body, refusing it once it exceeds `maxBytes`. */
18
+ export async function readBounded(stream, maxBytes) {
19
+ if (!stream)
20
+ throw new Error("Empty body");
21
+ const reader = stream.getReader();
22
+ const chunks = [];
23
+ let length = 0;
24
+ try {
25
+ for (;;) {
26
+ const { done, value } = await reader.read();
27
+ if (done)
28
+ break;
29
+ length += value.length;
30
+ if (length > maxBytes) {
31
+ void reader.cancel().catch(() => { });
32
+ throw new Error("Body exceeds limit");
33
+ }
34
+ chunks.push(value);
35
+ }
36
+ }
37
+ finally {
38
+ reader.releaseLock();
39
+ }
40
+ const bytes = new Uint8Array(length);
41
+ let offset = 0;
42
+ for (const chunk of chunks) {
43
+ bytes.set(chunk, offset);
44
+ offset += chunk.length;
45
+ }
46
+ return bytes;
47
+ }
48
+ /** The body of a 200 response as text, size-capped; any other status throws. */
49
+ export async function readBoundedText(response, maxBytes) {
50
+ if (response.status !== 200) {
51
+ void response.body?.cancel().catch(() => { });
52
+ throw new Error(`Unexpected status ${response.status}`);
53
+ }
54
+ return new TextDecoder().decode(await readBounded(response.body, maxBytes));
55
+ }
56
+ //# sourceMappingURL=upstream-fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upstream-fetch.js","sourceRoot":"","sources":["../../src/services/upstream-fetch.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,MAAM,mBAAmB,GAAG,KAAK,CAAC;AAElC,6DAA6D;AAC7D,MAAM,UAAU,aAAa,CAC3B,GAAW,EACX,MAAM,GAAG,2CAA2C;IAEpD,OAAO,qBAAqB,CAAC,GAAG,EAAE;QAChC,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,mBAAmB,CAAC;QAChD,OAAO,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;KAC5B,CAAC,CAAC;AACL,CAAC;AAED,2DAA2D;AAC3D,MAAM,CAAC,KAAK,UAAU,WAAW,CAC/B,MAAyC,EACzC,QAAgB;IAEhB,IAAI,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAC3C,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAC;IAClC,MAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,IAAI,CAAC;QACH,SAAS,CAAC;YACR,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;YAC5C,IAAI,IAAI;gBAAE,MAAM;YAChB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;YACvB,IAAI,MAAM,GAAG,QAAQ,EAAE,CAAC;gBACtB,KAAK,MAAM,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;gBACrC,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;YACxC,CAAC;YACD,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;YAAS,CAAC;QACT,MAAM,CAAC,WAAW,EAAE,CAAC;IACvB,CAAC;IACD,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC;IACrC,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,KAAK,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IACzB,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,gFAAgF;AAChF,MAAM,CAAC,KAAK,UAAU,eAAe,CACnC,QAAkB,EAClB,QAAgB;IAEhB,IAAI,QAAQ,CAAC,MAAM,KAAK,GAAG,EAAE,CAAC;QAC5B,KAAK,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QAC7C,MAAM,IAAI,KAAK,CAAC,qBAAqB,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;IACD,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,MAAM,WAAW,CAAC,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC;AAC9E,CAAC"}
package/dist/types.d.ts CHANGED
@@ -51,14 +51,10 @@ export interface CloudflareEnv {
51
51
  CHECKPOINT_PROJECT_ID?: string;
52
52
  /** Provisioned public org issuer binding; contains no organization private key. */
53
53
  MCPI_NATIVE_HTTP_ISSUER_CONFIG?: string;
54
- /** Explicit trusted Cloudflare dispatch ingress for native replay admission. */
55
- MCPI_NATIVE_HTTP_INGRESS?: string;
56
- /** Exact deployment role key, mirrored in the existing API aliases. */
57
- MCPI_NATIVE_HTTP_ISSUER_API_KEY?: string;
58
54
  /**
59
- * Comma- or whitespace-separated issuer DIDs whose delegation VC-JWTs this
60
- * worker accepts, in addition to its own identity, the native issuer binding
61
- * and the Checkpoint platform signer. Read by DelegationService.
55
+ * Comma- or whitespace-separated org issuer DIDs whose delegation VC-JWTs
56
+ * this worker accepts, for a worker without a native issuer binding. Read
57
+ * by DelegationService. The worker's own DID is never an issuer.
62
58
  */
63
59
  KYA_OS_TRUSTED_DELEGATION_ISSUERS?: string;
64
60
  /**
@@ -68,11 +64,6 @@ export interface CloudflareEnv {
68
64
  * malformed, every delegation is refused. Read by DelegationService.
69
65
  */
70
66
  KYA_OS_RESOURCE_DIDS?: string;
71
- /**
72
- * "1"/"true" accepts legacy (non VC-JWT) delegation tokens unchecked when no
73
- * CHECKPOINT_API_KEY is configured. Local development only; never cached.
74
- */
75
- KYA_OS_INSECURE_DEV_TOKENS?: string;
76
67
  /** Know That AI API URL for client DID lookups */
77
68
  KTA_API_URL?: string;
78
69
  /** Know That AI registration record written by `mcpi register` (JSON string) */
@@ -117,14 +108,10 @@ export interface CloudflareEnv {
117
108
  DO_SHARD_COUNT?: string;
118
109
  /** Enable MCP Apps inline consent UI ("true" to enable) */
119
110
  MCPI_INLINE_CONSENT?: string;
120
- /** draft-kya-http-02: enable the HTTP delegation challenge layer ("true"/"1" on, "false"/"0" off). Read by resolveHttpChallengeConfig; must survive mapPrefixedEnv under an env prefix. */
121
- MCPI_HTTP_CHALLENGE?: string;
111
+ /** Require a valid Bearer credential to connect ("true"/"1" on). Overrides the config flag; default off. */
112
+ MCPI_REQUIRE_TOKEN_TO_CONNECT?: string;
122
113
  /** draft-kya-http-02: relax consent CSRF for local/miniflare testing ("true" to relax) */
123
114
  MCPI_TEST_CONSENT?: string;
124
- /** draft-kya-http-02: ops kill switch for the anchor-registration route ("false"/"0" to disable). Must survive mapPrefixedEnv under an env prefix. */
125
- MCPI_ANCHOR_REGISTRATION?: string;
126
- /** draft-kya-http-02: overrides the challenge `realm` (branded consent host). Read by resolveHttpChallengeConfig; must survive mapPrefixedEnv under an env prefix. */
127
- MCPI_REALM?: string;
128
115
  /** Fail-closed identity gate on POST /consent/approve for non-consent-only provider types ("true"/"1" on, "false"/"0" off). Defaults to enabled. Read by ConsentService.isIdentityRequired; must survive mapPrefixedEnv under an env prefix. */
129
116
  CONSENT_REQUIRE_IDENTITY?: string;
130
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,kBAAkB,EAClB,sBAAsB,EACvB,MAAM,2BAA2B,CAAC;AAEnC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,aAAa;IAC5B,2EAA2E;IAC3E,WAAW,EAAE,WAAW,CAAC;IACzB,kEAAkE;IAClE,aAAa,CAAC,EAAE,WAAW,CAAC;IAC5B,kFAAkF;IAClF,gBAAgB,CAAC,EAAE,WAAW,CAAC;IAC/B,oGAAoG;IACpG,kBAAkB,CAAC,EAAE,WAAW,CAAC;IACjC,gFAAgF;IAChF,kBAAkB,CAAC,EAAE,WAAW,CAAC;IACjC,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,wEAAwE;IACxE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,mFAAmF;IACnF,8BAA8B,CAAC,EAAE,MAAM,CAAC;IACxC,gFAAgF;IAChF,wBAAwB,CAAC,EAAE,MAAM,CAAC;IAClC,uEAAuE;IACvE,+BAA+B,CAAC,EAAE,MAAM,CAAC;IACzC;;;;OAIG;IACH,iCAAiC,CAAC,EAAE,MAAM,CAAC;IAC3C;;;;;OAKG;IACH,oBAAoB,CA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MAAM,CAAC;IAC3B,gPAAgP;IAChP,wBAAwB,CAAC,EAAE,MAAM,CAAC;CACnC"}
@@ -4,4 +4,23 @@ export declare function oauthProfileString(value: unknown): string | undefined;
4
4
  export declare function normalizeOAuthSubject(value: unknown): string | undefined;
5
5
  /** Use provider identifiers; an email alone is not a provider subject. */
6
6
  export declare function oauthProfileSubject(profile: unknown): string | undefined;
7
+ /**
8
+ * The email to send for identity linking, and whether the provider verified it.
9
+ *
10
+ * GitHub's /user has no verification flag, so for a profile read from the
11
+ * GitHub API the only verified email is the primary one on /user/emails (needs
12
+ * the `user:email` scope). A missing scope, an error or an unverified primary
13
+ * leaves the profile email unverified. The token only goes to the API that
14
+ * already served the profile. Other providers keep their explicit boolean claim.
15
+ */
16
+ export declare function resolveOAuthEmail(params: {
17
+ profile: Record<string, unknown>;
18
+ userInfoUrl: string;
19
+ accessToken: string;
20
+ fetchImpl: typeof fetch;
21
+ userAgent: string;
22
+ }): Promise<{
23
+ email?: string;
24
+ emailVerified: boolean;
25
+ }>;
7
26
  //# sourceMappingURL=oauth-profile.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-profile.d.ts","sourceRoot":"","sources":["../../src/utils/oauth-profile.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAIrE;AAED,8EAA8E;AAC9E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAKxE;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAUxE"}
1
+ {"version":3,"file":"oauth-profile.d.ts","sourceRoot":"","sources":["../../src/utils/oauth-profile.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAIrE;AAED,8EAA8E;AAC9E,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAOxE;AAED,0EAA0E;AAC1E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAUxE;AAmBD;;;;;;;;GAQG;AACH,wBAAsB,iBAAiB,CAAC,MAAM,EAAE;IAC9C,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,OAAO,KAAK,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB,GAAG,OAAO,CAAC;IAAE,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,OAAO,CAAA;CAAE,CAAC,CA2BtD"}
@@ -7,7 +7,9 @@ export function oauthProfileString(value) {
7
7
  /** GitHub subjects are numeric IDs; preserve them as exact scalar strings. */
8
8
  export function normalizeOAuthSubject(value) {
9
9
  if (typeof value === "number") {
10
- return Number.isSafeInteger(value) && value >= 0 ? String(value) : undefined;
10
+ return Number.isSafeInteger(value) && value >= 0
11
+ ? String(value)
12
+ : undefined;
11
13
  }
12
14
  return oauthProfileString(value);
13
15
  }
@@ -21,4 +23,55 @@ export function oauthProfileSubject(profile) {
21
23
  normalizeOAuthSubject(claims.id) ??
22
24
  oauthProfileString(claims.login));
23
25
  }
26
+ const GITHUB_API_ORIGIN = "https://api.github.com";
27
+ /** The primary address from GitHub's /user/emails, only when GitHub verified it. */
28
+ function githubVerifiedPrimaryEmail(emails) {
29
+ if (!Array.isArray(emails))
30
+ return undefined;
31
+ const primary = emails.find((entry) => !!entry &&
32
+ typeof entry === "object" &&
33
+ "primary" in entry &&
34
+ entry.primary === true);
35
+ return primary?.verified === true
36
+ ? oauthProfileString(primary.email)
37
+ : undefined;
38
+ }
39
+ /**
40
+ * The email to send for identity linking, and whether the provider verified it.
41
+ *
42
+ * GitHub's /user has no verification flag, so for a profile read from the
43
+ * GitHub API the only verified email is the primary one on /user/emails (needs
44
+ * the `user:email` scope). A missing scope, an error or an unverified primary
45
+ * leaves the profile email unverified. The token only goes to the API that
46
+ * already served the profile. Other providers keep their explicit boolean claim.
47
+ */
48
+ export async function resolveOAuthEmail(params) {
49
+ const profileEmail = oauthProfileString(params.profile.email);
50
+ if (new URL(params.userInfoUrl).origin !== GITHUB_API_ORIGIN) {
51
+ return {
52
+ email: profileEmail,
53
+ emailVerified: params.profile.email_verified === true,
54
+ };
55
+ }
56
+ // Unbound: Workers throws "Illegal invocation" for fetch called as a method.
57
+ const { fetchImpl } = params;
58
+ try {
59
+ const response = await fetchImpl(`${GITHUB_API_ORIGIN}/user/emails`, {
60
+ headers: {
61
+ Authorization: `Bearer ${params.accessToken}`,
62
+ Accept: "application/vnd.github+json",
63
+ "User-Agent": params.userAgent,
64
+ },
65
+ });
66
+ const verified = response.ok
67
+ ? githubVerifiedPrimaryEmail(await response.json())
68
+ : undefined;
69
+ return verified
70
+ ? { email: verified, emailVerified: true }
71
+ : { email: profileEmail, emailVerified: false };
72
+ }
73
+ catch {
74
+ return { email: profileEmail, emailVerified: false };
75
+ }
76
+ }
24
77
  //# sourceMappingURL=oauth-profile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"oauth-profile.js","sourceRoot":"","sources":["../../src/utils/oauth-profile.ts"],"names":[],"mappings":"AAAA,+EAA+E;AAC/E,MAAM,UAAU,kBAAkB,CAAC,KAAc;IAC/C,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC;QACzD,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,SAAS,CAAC;AAChB,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,OAAO,MAAM,CAAC,aAAa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;IACJ,CAAC;IACD,6EAA6E;IAC7E,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,CAAC;IAC7B,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,MAAM,SAAS,CAAC,GAAG,iBAAiB,cAAc,EAAE;YACnE,OAAO,EAAE;gBACP,aAAa,EAAE,UAAU,MAAM,CAAC,WAAW,EAAE;gBAC7C,MAAM,EAAE,6BAA6B;gBACrC,YAAY,EAAE,MAAM,CAAC,SAAS;aAC/B;SACF,CAAC,CAAC;QACH,MAAM,QAAQ,GAAG,QAAQ,CAAC,EAAE;YAC1B,CAAC,CAAC,0BAA0B,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YACnD,CAAC,CAAC,SAAS,CAAC;QACd,OAAO,QAAQ;YACb,CAAC,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,IAAI,EAAE;YAC1C,CAAC,CAAC,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IACpD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,aAAa,EAAE,KAAK,EAAE,CAAC;IACvD,CAAC;AACH,CAAC"}
@@ -0,0 +1,65 @@
1
+ /**
2
+ * Per-tool `securitySchemes` on `tools/list`.
3
+ *
4
+ * A host that links accounts through OAuth (ChatGPT) shows its linking UI only
5
+ * when the challenge hint on a tool result is paired with per-tool
6
+ * `securitySchemes` in the listing. A tool whose served protection requires
7
+ * delegation lists an `oauth2` scheme with its required scopes; every other
8
+ * tool lists `noauth`. The field appears at the top level of the tool and
9
+ * under `_meta.securitySchemes`, which is where hosts that read tool metadata
10
+ * look.
11
+ *
12
+ * Wraps the SDK's `tools/list` handler at request time, so tools registered
13
+ * after the wrap are listed too.
14
+ *
15
+ * Hosts snapshot tool metadata when a connector is created, so a listing that
16
+ * goes out without `securitySchemes` can stick. When the served protection
17
+ * cannot be resolved, the listing therefore carries the last protections that
18
+ * did resolve (kept in memory, and in an optional store that survives
19
+ * restarts). Only when none were ever recorded is the listing returned
20
+ * unchanged.
21
+ */
22
+ import type { KVNamespace } from "@cloudflare/workers-types";
23
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
24
+ /** The part of a tool's served protection the listing reads. */
25
+ export interface ListedToolProtection {
26
+ readonly requiresDelegation?: boolean;
27
+ readonly requiredScopes?: readonly string[];
28
+ }
29
+ /** Served protection by tool name (`*` is the wildcard), or undefined. */
30
+ export type ServedProtections = Readonly<Record<string, ListedToolProtection | undefined>>;
31
+ /** Where the last protections that resolved are kept between instances. */
32
+ export interface LastKnownGoodProtections {
33
+ get(): Promise<ServedProtections | undefined>;
34
+ put(protections: ServedProtections): Promise<void>;
35
+ }
36
+ /** The schemes a tool advertises under the served protections. */
37
+ export declare function securitySchemesFor(toolName: string, protections: ServedProtections): Array<{
38
+ type: "oauth2";
39
+ scopes: string[];
40
+ } | {
41
+ type: "noauth";
42
+ }>;
43
+ /**
44
+ * A last-known-good store backed by Workers KV, with no expiry.
45
+ *
46
+ * Writes only when the stored JSON differs from the new value: KV allows about
47
+ * one write per second per key and `tools/list` runs about once per session.
48
+ * Anything unreadable in KV reads as undefined.
49
+ */
50
+ export declare function kvLastKnownGoodProtections(kv: KVNamespace, key: string): LastKnownGoodProtections;
51
+ /**
52
+ * Add `securitySchemes` to every tool in the server's `tools/list` result.
53
+ *
54
+ * Call after at least one tool is registered (the SDK installs its handler on
55
+ * first registration).
56
+ *
57
+ * @param resolve - the served protections, or undefined when they cannot be
58
+ * resolved (the last known good protections are then used)
59
+ * @param lastKnownGood - optional store for the last protections that
60
+ * resolved; a store error never fails the listing
61
+ * @returns true if the handler was wrapped, false if no `tools/list` handler
62
+ * was found
63
+ */
64
+ export declare function addSecuritySchemesToListing(server: McpServer, resolve: () => Promise<ServedProtections | undefined>, lastKnownGood?: LastKnownGoodProtections): boolean;
65
+ //# sourceMappingURL=tool-security-schemes.d.ts.map
@@ -0,0 +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OAAO,CA2DT"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Per-tool `securitySchemes` on `tools/list`.
3
+ *
4
+ * A host that links accounts through OAuth (ChatGPT) shows its linking UI only
5
+ * when the challenge hint on a tool result is paired with per-tool
6
+ * `securitySchemes` in the listing. A tool whose served protection requires
7
+ * delegation lists an `oauth2` scheme with its required scopes; every other
8
+ * tool lists `noauth`. The field appears at the top level of the tool and
9
+ * under `_meta.securitySchemes`, which is where hosts that read tool metadata
10
+ * look.
11
+ *
12
+ * Wraps the SDK's `tools/list` handler at request time, so tools registered
13
+ * after the wrap are listed too.
14
+ *
15
+ * Hosts snapshot tool metadata when a connector is created, so a listing that
16
+ * goes out without `securitySchemes` can stick. When the served protection
17
+ * cannot be resolved, the listing therefore carries the last protections that
18
+ * did resolve (kept in memory, and in an optional store that survives
19
+ * restarts). Only when none were ever recorded is the listing returned
20
+ * unchanged.
21
+ */
22
+ import { ListToolsRequestSchema, } from "@modelcontextprotocol/sdk/types.js";
23
+ import { scopeTokens } from "../delegation-http/lazy-auth-gate";
24
+ /** The schemes a tool advertises under the served protections. */
25
+ export function securitySchemesFor(toolName, protections) {
26
+ const own = Object.prototype.hasOwnProperty.call(protections, toolName)
27
+ ? protections[toolName]
28
+ : undefined;
29
+ const protection = own ?? protections["*"];
30
+ return protection?.requiresDelegation
31
+ ? [{ type: "oauth2", scopes: scopeTokens(protection.requiredScopes ?? []) }]
32
+ : [{ type: "noauth" }];
33
+ }
34
+ /** Only the fields the listing reads, so the stored value stays small. */
35
+ function toStoredShape(protections) {
36
+ const stored = {};
37
+ for (const [name, protection] of Object.entries(protections)) {
38
+ if (!protection)
39
+ continue;
40
+ stored[name] = {
41
+ requiresDelegation: protection.requiresDelegation === true,
42
+ requiredScopes: [...(protection.requiredScopes ?? [])],
43
+ };
44
+ }
45
+ return stored;
46
+ }
47
+ function parseStoredProtections(raw) {
48
+ if (!raw)
49
+ return undefined;
50
+ try {
51
+ const parsed = JSON.parse(raw);
52
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
53
+ return undefined;
54
+ }
55
+ const result = {};
56
+ for (const [name, value] of Object.entries(parsed)) {
57
+ if (!value || typeof value !== "object" || Array.isArray(value)) {
58
+ return undefined;
59
+ }
60
+ const { requiresDelegation, requiredScopes } = value;
61
+ if (typeof requiresDelegation !== "boolean" ||
62
+ !Array.isArray(requiredScopes) ||
63
+ !requiredScopes.every((scope) => typeof scope === "string")) {
64
+ return undefined;
65
+ }
66
+ result[name] = { requiresDelegation, requiredScopes };
67
+ }
68
+ return result;
69
+ }
70
+ catch {
71
+ return undefined;
72
+ }
73
+ }
74
+ /**
75
+ * A last-known-good store backed by Workers KV, with no expiry.
76
+ *
77
+ * Writes only when the stored JSON differs from the new value: KV allows about
78
+ * one write per second per key and `tools/list` runs about once per session.
79
+ * Anything unreadable in KV reads as undefined.
80
+ */
81
+ export function kvLastKnownGoodProtections(kv, key) {
82
+ return {
83
+ async get() {
84
+ return parseStoredProtections(await kv.get(key));
85
+ },
86
+ async put(protections) {
87
+ const next = JSON.stringify(toStoredShape(protections));
88
+ if ((await kv.get(key)) === next)
89
+ return;
90
+ await kv.put(key, next);
91
+ },
92
+ };
93
+ }
94
+ /**
95
+ * Add `securitySchemes` to every tool in the server's `tools/list` result.
96
+ *
97
+ * Call after at least one tool is registered (the SDK installs its handler on
98
+ * first registration).
99
+ *
100
+ * @param resolve - the served protections, or undefined when they cannot be
101
+ * resolved (the last known good protections are then used)
102
+ * @param lastKnownGood - optional store for the last protections that
103
+ * resolved; a store error never fails the listing
104
+ * @returns true if the handler was wrapped, false if no `tools/list` handler
105
+ * was found
106
+ */
107
+ export function addSecuritySchemesToListing(server, resolve, lastKnownGood) {
108
+ // The low-level Server keeps handlers in a private map with no getter; the
109
+ // same minimal private read hidden-consent-tools makes.
110
+ const lowLevel = server.server;
111
+ const inner = lowLevel;
112
+ const original = inner?._requestHandlers?.get("tools/list");
113
+ if (!lowLevel || typeof original !== "function")
114
+ return false;
115
+ let remembered;
116
+ lowLevel.setRequestHandler(ListToolsRequestSchema, async (request, extra) => {
117
+ const result = await original(request, extra);
118
+ let protections;
119
+ try {
120
+ protections = await resolve();
121
+ }
122
+ catch {
123
+ protections = undefined;
124
+ }
125
+ if (protections) {
126
+ const changed = !remembered ||
127
+ JSON.stringify(toStoredShape(remembered)) !==
128
+ JSON.stringify(toStoredShape(protections));
129
+ remembered = protections;
130
+ if (changed && lastKnownGood) {
131
+ try {
132
+ await lastKnownGood.put(protections);
133
+ }
134
+ catch {
135
+ // Best effort: the listing does not depend on the store.
136
+ }
137
+ }
138
+ }
139
+ else {
140
+ protections = remembered;
141
+ if (!protections && lastKnownGood) {
142
+ try {
143
+ protections = await lastKnownGood.get();
144
+ }
145
+ catch {
146
+ protections = undefined;
147
+ }
148
+ remembered = protections;
149
+ }
150
+ }
151
+ if (!protections)
152
+ return result;
153
+ const served = protections;
154
+ return {
155
+ ...result,
156
+ tools: (result.tools ?? []).map((tool) => {
157
+ const securitySchemes = securitySchemesFor(tool.name, served);
158
+ return {
159
+ ...tool,
160
+ securitySchemes,
161
+ _meta: { ...tool._meta, securitySchemes },
162
+ };
163
+ }),
164
+ };
165
+ });
166
+ return true;
167
+ }
168
+ //# sourceMappingURL=tool-security-schemes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-security-schemes.js","sourceRoot":"","sources":["../../src/utils/tool-security-schemes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAIH,OAAO,EACL,sBAAsB,GAEvB,MAAM,oCAAoC,CAAC;AAE5C,OAAO,EAAE,WAAW,EAAE,MAAM,mCAAmC,CAAC;AAwBhE,kEAAkE;AAClE,MAAM,UAAU,kBAAkB,CAChC,QAAgB,EAChB,WAA8B;IAE9B,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,WAAW,EAAE,QAAQ,CAAC;QACrE,CAAC,CAAC,WAAW,CAAC,QAAQ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BAAC,MAAM,CAAC;oBACP,WAAW,GAAG,SAAS,CAAC;gBAC1B,CAAC;gBACD,UAAU,GAAG,WAAW,CAAC;YAC3B,CAAC;QACH,CAAC;QACD,IAAI,CAAC,WAAW;YAAE,OAAO,MAAM,CAAC;QAChC,MAAM,MAAM,GAAG,WAAW,CAAC;QAC3B,OAAO;YACL,GAAG,MAAM;YACT,KAAK,EAAE,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;gBACvC,MAAM,eAAe,GAAG,kBAAkB,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;gBAC9D,OAAO;oBACL,GAAG,IAAI;oBACP,eAAe;oBACf,KAAK,EAAE,EAAE,GAAG,IAAI,CAAC,KAAK,EAAE,eAAe,EAAE;iBAC1C,CAAC;YACJ,CAAC,CAAC;SACH,CAAC;IACJ,CAAC,CAAC,CAAC;IACH,OAAO,IAAI,CAAC;AACd,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kya-os/mcp-i-cloudflare",
3
- "version": "1.17.0",
3
+ "version": "1.18.1",
4
4
  "description": "Cloudflare Workers adapter for MCP-I framework",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -19,7 +19,6 @@
19
19
  "test:workers": "vitest run --config vitest.workers.config.ts",
20
20
  "test:workers:watch": "vitest --config vitest.workers.config.ts",
21
21
  "test:e2e": "playwright test",
22
- "test:preparation-browser": "playwright test --config playwright.preparation.config.ts",
23
22
  "test:e2e:headed": "playwright test --headed",
24
23
  "test:e2e:ui": "playwright test --ui",
25
24
  "test:e2e:debug": "playwright test --debug",
@@ -31,11 +30,11 @@
31
30
  "prepublishOnly": "npm run build && node ../create-mcpi-app/scripts/validate-no-workspace.js"
32
31
  },
33
32
  "dependencies": {
34
- "@kya-os/consent": "^0.1.50",
35
- "@kya-os/contracts": "^1.13.1",
36
- "@kya-os/mcp": "1.16.0",
33
+ "@kya-os/consent": "^0.2.0",
34
+ "@kya-os/contracts": "^1.14.0",
35
+ "@kya-os/mcp": "1.20.0",
37
36
  "@kya-os/mcp-i-core": "^1.9.4",
38
- "@kya-os/mcp-i-runtime": "^1.3.1",
37
+ "@kya-os/mcp-i-runtime": "^1.3.2",
39
38
  "@kya-os/provider-registry": "^0.1.7",
40
39
  "@modelcontextprotocol/sdk": "^1.25.2",
41
40
  "agents": "^0.4.1",
@@ -1,84 +0,0 @@
1
- /**
2
- * draft-kya-http-02 delegation layer — pickup-anchor durable object.
3
- *
4
- * Implements the §13 anchor state machine: create → PENDING (or PINNED for a
5
- * challenge-time signed caller) → first poll pins the holder → human approves
6
- * (PINNED→APPROVED, credential parked) → the pinned holder polls 200-ready,
7
- * repeatably, until the anchor TTL elapses.
8
- *
9
- * Design:
10
- * - ALL transition logic lives in the pure, synchronous reducers
11
- * `reduceCreate` / `reducePoll` / `reduceApprove` (injectable `now`). They never
12
- * touch storage and never await — which is what lets the Cloudflare DO input gate
13
- * serialize the first-poll race (the dispatcher does `get → reduce → put` with no
14
- * intervening non-storage await, so the read-modify-write is atomic per the gate).
15
- * - `handlePickupInternal` is the only async surface: it reads the record from
16
- * `ctx.storage`, runs the reducer, then persists or deletes.
17
- *
18
- * Non-negotiables:
19
- * - never store/log a raw token — only its `sha256Hex` digest (see `./hash`);
20
- * - no `alarm()` override: the `agents` SDK base class assigns `this.alarm` as an
21
- * own-property arrow (its SQL scheduler), which shadows any subclass method and
22
- * exposes no `super.alarm` to delegate to — so anchor lifetime is instead bounded
23
- * by idempotent creation (one anchor per deterministic sid) plus the ≤600s TTL;
24
- * - lazy expiry with delete-on-expired-read (a 410 outcome deletes the key);
25
- * - every response carries `Cache-Control: no-store`;
26
- * - 429 is status + `Retry-After` only — never a body.
27
- *
28
- * @module @kya-os/mcp-i-cloudflare/delegation-http/anchor-do
29
- */
30
- import type { DurableObjectState } from "@cloudflare/workers-types";
31
- import type { PickupAnchorRecord, PickupHolder } from "./types";
32
- /**
33
- * Pure reducer for `create`. Writes a fresh anchor record (PENDING, or PINNED when a
34
- * challenge-time keyid pin is supplied). Idempotent by construction: a `pickup:<sid>`
35
- * instance is created once, by the challenge emitter, before the 401 leaves.
36
- */
37
- export declare function reduceCreate(rec: PickupAnchorRecord | undefined, input: unknown, now: number): {
38
- record?: PickupAnchorRecord;
39
- response: {
40
- status: number;
41
- body?: unknown;
42
- };
43
- };
44
- /**
45
- * Pure reducer for `poll`. The §13 wire state machine:
46
- * - no record → 404 invalid-session;
47
- * - `now > expiresAt` → 410 pickup-expired (the dispatcher deletes the key);
48
- * - no pin yet → this poll pins `sha256Hex(holder.value)` (PENDING→PINNED);
49
- * - pin mismatch (any state, incl. after approval) → 403 pickup-pinned;
50
- * - pinned holder, awaiting consent, polling faster than `pollIntervalS` → 429;
51
- * - pinned holder, credential parked → 200 ready (repeatable, no consume-on-read);
52
- * - otherwise → 202 pending.
53
- */
54
- export declare function reducePoll(rec: PickupAnchorRecord | undefined, holder: PickupHolder, now: number): {
55
- record?: PickupAnchorRecord;
56
- response: {
57
- status: 200 | 202 | 403 | 404 | 410 | 429;
58
- body?: unknown;
59
- retryAfterS?: number;
60
- };
61
- };
62
- /**
63
- * Pure reducer for `approve`. Parks the minted credential on a live anchor
64
- * (PENDING or PINNED → APPROVED). Consent on an EXPIRED anchor MUST fail (410); an
65
- * unknown anchor is 404 invalid-session.
66
- */
67
- export declare function reduceApprove(rec: PickupAnchorRecord | undefined, input: unknown, now: number): {
68
- record?: PickupAnchorRecord;
69
- response: {
70
- status: number;
71
- body?: unknown;
72
- };
73
- };
74
- /**
75
- * Dispatch `/_internal/pickup/*` requests against the anchor's durable-object
76
- * storage. One `ctx.storage.get` up front, the matching pure reducer, then a single
77
- * `put` (or `delete` on an expired 410 read) — no non-storage await between read and
78
- * write, so the DO input gate makes the first-poll pin a compare-and-set.
79
- *
80
- * `now` is injectable for tests; production callers omit it and it resolves to the
81
- * wall clock.
82
- */
83
- export declare function handlePickupInternal(ctx: DurableObjectState, request: Request, now?: number): Promise<Response>;
84
- //# sourceMappingURL=anchor-do.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"anchor-do.d.ts","sourceRoot":"","sources":["../../src/delegation-http/anchor-do.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAEpE,OAAO,KAAK,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAuGhE;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,GAAG,EAAE,kBAAkB,GAAG,SAAS,EACnC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV;IACD,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,QAAQ,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,CAAC;CAC9C,CAmEA;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,GAAG,EAAE,kBAAkB,GAAG,SAAS,EACnC,MAAM,EAAE,YAAY,EACpB,GAAG,EAAE,MAAM,GACV;IACD,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,QAAQ,EAAE;QACR,MAAM,EAAE,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;QAC1C,IAAI,CAAC,EAAE,OAAO,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,CAAC;KACtB,CAAC;CACH,CA+EA;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,GAAG,EAAE,kBAAkB,GAAG,SAAS,EACnC,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,MAAM,GACV;IACD,MAAM,CAAC,EAAE,kBAAkB,CAAC;IAC5B,QAAQ,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QA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