@kya-os/mcp-i-cloudflare 1.18.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 (256) 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 +30 -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 +383 -406
  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/oauth-handler.d.ts +1 -1
  86. package/dist/runtime/oauth-handler.d.ts.map +1 -1
  87. package/dist/runtime/oauth-handler.js +15 -30
  88. package/dist/runtime/oauth-handler.js.map +1 -1
  89. package/dist/runtime.d.ts +34 -10
  90. package/dist/runtime.d.ts.map +1 -1
  91. package/dist/runtime.js +54 -12
  92. package/dist/runtime.js.map +1 -1
  93. package/dist/security/admission-refusal.d.ts +3 -3
  94. package/dist/security/admission-refusal.d.ts.map +1 -1
  95. package/dist/security/admission-refusal.js +14 -6
  96. package/dist/security/admission-refusal.js.map +1 -1
  97. package/dist/security/holder-binding.d.ts +34 -0
  98. package/dist/security/holder-binding.d.ts.map +1 -0
  99. package/dist/security/holder-binding.js +75 -0
  100. package/dist/security/holder-binding.js.map +1 -0
  101. package/dist/security/mcp-admission.d.ts +29 -1
  102. package/dist/security/mcp-admission.d.ts.map +1 -1
  103. package/dist/security/mcp-admission.js +78 -12
  104. package/dist/security/mcp-admission.js.map +1 -1
  105. package/dist/security/native-holder-admission.d.ts +39 -0
  106. package/dist/security/native-holder-admission.d.ts.map +1 -0
  107. package/dist/security/native-holder-admission.js +65 -0
  108. package/dist/security/native-holder-admission.js.map +1 -0
  109. package/dist/security/outcome-proof.d.ts +39 -0
  110. package/dist/security/outcome-proof.d.ts.map +1 -0
  111. package/dist/security/outcome-proof.js +54 -0
  112. package/dist/security/outcome-proof.js.map +1 -0
  113. package/dist/security/request-nonce-store.d.ts +43 -0
  114. package/dist/security/request-nonce-store.d.ts.map +1 -0
  115. package/dist/security/request-nonce-store.js +129 -0
  116. package/dist/security/request-nonce-store.js.map +1 -0
  117. package/dist/security/routed-request.d.ts +41 -0
  118. package/dist/security/routed-request.d.ts.map +1 -0
  119. package/dist/security/routed-request.js +86 -0
  120. package/dist/security/routed-request.js.map +1 -0
  121. package/dist/security/sign-in-amr.d.ts +23 -0
  122. package/dist/security/sign-in-amr.d.ts.map +1 -0
  123. package/dist/security/sign-in-amr.js +44 -0
  124. package/dist/security/sign-in-amr.js.map +1 -0
  125. package/dist/services/approval-route.d.ts +3 -2
  126. package/dist/services/approval-route.d.ts.map +1 -1
  127. package/dist/services/approval-route.js.map +1 -1
  128. package/dist/services/checkpoint-decision.d.ts +56 -0
  129. package/dist/services/checkpoint-decision.d.ts.map +1 -0
  130. package/dist/services/checkpoint-decision.js +109 -0
  131. package/dist/services/checkpoint-decision.js.map +1 -0
  132. package/dist/services/consent-page-renderer.d.ts.map +1 -1
  133. package/dist/services/consent-page-renderer.js +2 -3
  134. package/dist/services/consent-page-renderer.js.map +1 -1
  135. package/dist/services/consent.service.d.ts +11 -49
  136. package/dist/services/consent.service.d.ts.map +1 -1
  137. package/dist/services/consent.service.js +81 -307
  138. package/dist/services/consent.service.js.map +1 -1
  139. package/dist/services/credential-auth.handler.d.ts.map +1 -1
  140. package/dist/services/credential-auth.handler.js +2 -8
  141. package/dist/services/credential-auth.handler.js.map +1 -1
  142. package/dist/services/delegation-authority.d.ts +53 -0
  143. package/dist/services/delegation-authority.d.ts.map +1 -0
  144. package/dist/services/delegation-authority.js +130 -0
  145. package/dist/services/delegation-authority.js.map +1 -0
  146. package/dist/services/delegation-trust.d.ts +35 -64
  147. package/dist/services/delegation-trust.d.ts.map +1 -1
  148. package/dist/services/delegation-trust.js +98 -279
  149. package/dist/services/delegation-trust.js.map +1 -1
  150. package/dist/services/delegation.service.d.ts +83 -105
  151. package/dist/services/delegation.service.d.ts.map +1 -1
  152. package/dist/services/delegation.service.js +166 -518
  153. package/dist/services/delegation.service.js.map +1 -1
  154. package/dist/services/idp-token-storage.d.ts +32 -12
  155. package/dist/services/idp-token-storage.d.ts.map +1 -1
  156. package/dist/services/idp-token-storage.js +79 -36
  157. package/dist/services/idp-token-storage.js.map +1 -1
  158. package/dist/services/issuer-keys.d.ts +55 -0
  159. package/dist/services/issuer-keys.d.ts.map +1 -0
  160. package/dist/services/issuer-keys.js +184 -0
  161. package/dist/services/issuer-keys.js.map +1 -0
  162. package/dist/services/oauth-security.service.d.ts +17 -1
  163. package/dist/services/oauth-security.service.d.ts.map +1 -1
  164. package/dist/services/oauth-security.service.js +29 -10
  165. package/dist/services/oauth-security.service.js.map +1 -1
  166. package/dist/services/resource-audience.d.ts +12 -9
  167. package/dist/services/resource-audience.d.ts.map +1 -1
  168. package/dist/services/resource-audience.js +12 -9
  169. package/dist/services/resource-audience.js.map +1 -1
  170. package/dist/services/unenforceable-tool-protection.d.ts +32 -0
  171. package/dist/services/unenforceable-tool-protection.d.ts.map +1 -0
  172. package/dist/services/unenforceable-tool-protection.js +90 -0
  173. package/dist/services/unenforceable-tool-protection.js.map +1 -0
  174. package/dist/services/upstream-fetch.d.ts +14 -0
  175. package/dist/services/upstream-fetch.d.ts.map +1 -0
  176. package/dist/services/upstream-fetch.js +56 -0
  177. package/dist/services/upstream-fetch.js.map +1 -0
  178. package/dist/types.d.ts +5 -18
  179. package/dist/types.d.ts.map +1 -1
  180. package/dist/utils/tool-security-schemes.d.ts +65 -0
  181. package/dist/utils/tool-security-schemes.d.ts.map +1 -0
  182. package/dist/utils/tool-security-schemes.js +168 -0
  183. package/dist/utils/tool-security-schemes.js.map +1 -0
  184. package/package.json +3 -4
  185. package/dist/delegation-http/anchor-do.d.ts +0 -84
  186. package/dist/delegation-http/anchor-do.d.ts.map +0 -1
  187. package/dist/delegation-http/anchor-do.js +0 -412
  188. package/dist/delegation-http/anchor-do.js.map +0 -1
  189. package/dist/delegation-http/anchor-registration-validate.d.ts +0 -61
  190. package/dist/delegation-http/anchor-registration-validate.d.ts.map +0 -1
  191. package/dist/delegation-http/anchor-registration-validate.js +0 -191
  192. package/dist/delegation-http/anchor-registration-validate.js.map +0 -1
  193. package/dist/delegation-http/anchor-registration.d.ts +0 -62
  194. package/dist/delegation-http/anchor-registration.d.ts.map +0 -1
  195. package/dist/delegation-http/anchor-registration.js +0 -337
  196. package/dist/delegation-http/anchor-registration.js.map +0 -1
  197. package/dist/delegation-http/anchor-routing.d.ts +0 -20
  198. package/dist/delegation-http/anchor-routing.d.ts.map +0 -1
  199. package/dist/delegation-http/anchor-routing.js +0 -27
  200. package/dist/delegation-http/anchor-routing.js.map +0 -1
  201. package/dist/delegation-http/challenge-middleware.d.ts +0 -28
  202. package/dist/delegation-http/challenge-middleware.d.ts.map +0 -1
  203. package/dist/delegation-http/challenge-middleware.js +0 -190
  204. package/dist/delegation-http/challenge-middleware.js.map +0 -1
  205. package/dist/delegation-http/challenge.d.ts +0 -102
  206. package/dist/delegation-http/challenge.d.ts.map +0 -1
  207. package/dist/delegation-http/challenge.js +0 -223
  208. package/dist/delegation-http/challenge.js.map +0 -1
  209. package/dist/delegation-http/consent-anchor-bridge.d.ts +0 -70
  210. package/dist/delegation-http/consent-anchor-bridge.d.ts.map +0 -1
  211. package/dist/delegation-http/consent-anchor-bridge.js +0 -1130
  212. package/dist/delegation-http/consent-anchor-bridge.js.map +0 -1
  213. package/dist/delegation-http/consent-preparation-page.d.ts +0 -18
  214. package/dist/delegation-http/consent-preparation-page.d.ts.map +0 -1
  215. package/dist/delegation-http/consent-preparation-page.js +0 -172
  216. package/dist/delegation-http/consent-preparation-page.js.map +0 -1
  217. package/dist/delegation-http/credential-consent.d.ts +0 -149
  218. package/dist/delegation-http/credential-consent.d.ts.map +0 -1
  219. package/dist/delegation-http/credential-consent.js +0 -338
  220. package/dist/delegation-http/credential-consent.js.map +0 -1
  221. package/dist/delegation-http/native-capabilities.d.ts +0 -4
  222. package/dist/delegation-http/native-capabilities.d.ts.map +0 -1
  223. package/dist/delegation-http/native-capabilities.js +0 -53
  224. package/dist/delegation-http/native-capabilities.js.map +0 -1
  225. package/dist/delegation-http/native-oauth-state.d.ts +0 -28
  226. package/dist/delegation-http/native-oauth-state.d.ts.map +0 -1
  227. package/dist/delegation-http/native-oauth-state.js +0 -146
  228. package/dist/delegation-http/native-oauth-state.js.map +0 -1
  229. package/dist/delegation-http/native-oauth.d.ts +0 -26
  230. package/dist/delegation-http/native-oauth.d.ts.map +0 -1
  231. package/dist/delegation-http/native-oauth.js +0 -401
  232. package/dist/delegation-http/native-oauth.js.map +0 -1
  233. package/dist/delegation-http/native-pickup.d.ts +0 -20
  234. package/dist/delegation-http/native-pickup.d.ts.map +0 -1
  235. package/dist/delegation-http/native-pickup.js +0 -227
  236. package/dist/delegation-http/native-pickup.js.map +0 -1
  237. package/dist/delegation-http/pickup-routes.d.ts +0 -43
  238. package/dist/delegation-http/pickup-routes.d.ts.map +0 -1
  239. package/dist/delegation-http/pickup-routes.js +0 -166
  240. package/dist/delegation-http/pickup-routes.js.map +0 -1
  241. package/dist/delegation-http/register.d.ts +0 -26
  242. package/dist/delegation-http/register.d.ts.map +0 -1
  243. package/dist/delegation-http/register.js +0 -95
  244. package/dist/delegation-http/register.js.map +0 -1
  245. package/dist/delegation-http/registrar-auth.d.ts +0 -24
  246. package/dist/delegation-http/registrar-auth.d.ts.map +0 -1
  247. package/dist/delegation-http/registrar-auth.js +0 -61
  248. package/dist/delegation-http/registrar-auth.js.map +0 -1
  249. package/dist/delegation-http/remote-issuer.d.ts +0 -52
  250. package/dist/delegation-http/remote-issuer.d.ts.map +0 -1
  251. package/dist/delegation-http/remote-issuer.js +0 -324
  252. package/dist/delegation-http/remote-issuer.js.map +0 -1
  253. package/dist/delegation-http/types.d.ts +0 -116
  254. package/dist/delegation-http/types.d.ts.map +0 -1
  255. package/dist/delegation-http/types.js +0 -11
  256. package/dist/delegation-http/types.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAUH,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAGhF,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AA8e7E;;GAEG;AACH,MAAM,CAAC,MAAM,8BAA8B,GACzC;IACE,WAAW,EAAE,aAAa;IAC1B,OAAO,EAAE;QACP,KAAK,EAAE,EAAE;QACT,QAAQ,EAAE,GAAG;KACd;IACD,EAAE,EAAE,EAAE;IACN,cAAc,EAAE,EAAE;IAClB,EAAE,EAAE,EAAE;IACN,IAAI,EAAE;QACJ,WAAW,EAAE,aAAa;KAC3B;IACD,OAAO,EAAE,EAAE;IACX,QAAQ,EAAE,EAAE;CACb,CAAC;AAEJ;;GAEG;AACH,MAAM,CAAC,MAAM,4BAA4B,GAA0B;IACjE,IAAI,EAAE,cAAc;IACpB,YAAY,EAAE,eAAe;IAC7B,SAAS,EAAE,MAAM;IACjB,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,KAAK;IACb,UAAU,EAAE,KAAK;IACjB,YAAY,EAAE;QACZ,OAAO,EAAE,IAAI;QACb,IAAI,EAAE,sBAAsB;KAC7B;CACF,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,6BAA6B,CAC3C,MAAyC;IAEzC,OAAO;QACL,GAAG,8BAA8B;QACjC,GAAG,MAAM;QACT,OAAO,EAAE;YACP,GAAG,8BAA8B,CAAC,OAAO;YACzC,GAAG,MAAM,EAAE,OAAO;SACnB;QACD,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,8BAA8B,CAAC,EAAG;QACpD,cAAc,EACZ,MAAM,EAAE,cAAc,IAAI,8BAA8B,CAAC,cAAe;QAC1E,EAAE,EAAE,MAAM,EAAE,EAAE,IAAI,8BAA8B,CAAC,EAAG;QACpD,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AAC;oBACE,OAAO,EAAE,IAAI;oBACb,MAAM,EAAE,GAAG,CAAC,aAAa,IAAI,GAAG,CAAC,kBAAkB;iBACpD;gBACH,CAAC,CAAC,SAAS,CAAC;KACU,CAAC;AAC/B,CAAC"}
@@ -1,62 +1,114 @@
1
1
  /**
2
- * draft-kya-http-02 delegation layer — Bearer retry verification.
2
+ * Presented-delegation pass-through for MCP requests.
3
3
  *
4
- * After a §8.1 challenge, a kya-capable caller retries the MCP request carrying the
5
- * minted delegation as a Bearer credential. This module turns that retry into the
6
- * adapter's existing `params.delegationToken` priority seam (adapter.ts:~458 — tested
7
- * by `adapter-delegation-priority.test.ts`), WITHOUT editing the adapter:
4
+ * A caller that holds a delegation presents it as `Authorization: Bearer <vc-jwt>`
5
+ * or in the `KYA-Delegation` header. This module moves that credential into the
6
+ * adapter's existing `params.delegationToken` priority seam (adapter.ts:~458 —
7
+ * tested by `adapter-delegation-priority.test.ts`), WITHOUT editing the adapter.
8
+ * It never verifies the credential and never answers an authorization decision:
9
+ * the Durable Object is the authority. Its delegation verification (org issuer,
10
+ * the routed host as audience, the signed status list, holder binding) and its
11
+ * request admission run for every `tools/call`, and a refusal comes back to the
12
+ * client as the delegation-required tool result, on every transport.
8
13
  *
9
14
  * - `extractDelegationVcJwt` accepts `Authorization: Bearer <jwt>` ONLY when the
10
15
  * decoded JWT payload carries a `vc` claim. An opaque OAuth bearer (no `vc`) is
11
16
  * left untouched (returns null) so existing OAuth clients pass through. When
12
17
  * `Authorization` is occupied by such a non-VC bearer, the `KYA-Delegation` header
13
18
  * is used as the fallback carrier.
14
- * - `applyBearerDelegation` verifies the VC-JWT fail-fast via `DelegationService`
15
- * (pinned issuer, accepted audience, signature, credential status) and, for
16
- * unsigned legacy requests, adds `params.delegationToken = vcJwt`.
17
- * An invalid chain → 403 `kyaos/chain-broken`; an expired credential → 401
18
- * `kyaos/expired`. Both error responses carry `Cache-Control: no-store`.
19
+ * - `applyBearerDelegation` adds `params.delegationToken = vcJwt` to an unsigned
20
+ * `tools/call` and passes every other request through unchanged.
19
21
  * - A request that carries a request proof (a card `_meta` carrier or an HTTP
20
22
  * message signature header) keeps its body byte for byte, because rewriting
21
23
  * it would break the proof; admission reads the credential from the transport
22
24
  * headers instead. The card keys come only from the validated card proof
23
25
  * support accessor: in an esbuild bundle the statically imported card
24
26
  * constants can stay undefined, which made every signed body look unsigned
25
- * and get rewritten.
26
- * - When that support cannot be validated, a worker with a native HTTP issuer
27
- * refuses the retry with 503 `proof_support_unavailable` (`no-store`) instead
28
- * of risking a signed call being handled as unsigned. Other workers leave
29
- * any proof-shaped body untouched and still rewrite bodies with no proof
30
- * shape at all, so unsigned legacy retries keep working.
27
+ * and get rewritten. When that support cannot be validated, the
28
+ * proof-shaped superset decides, so a proof-shaped body is left untouched.
29
+ * - `assessPresentedBearer` and `assessPresentedCredential` classify a
30
+ * presented delegation (none, valid, expired, invalid, refer, malformed)
31
+ * for the lazy-auth gate (./lazy-auth-gate). They are not part of the
32
+ * pass-through.
33
+ * - The one refusal left is a malformed presentation (an unparseable header
34
+ * presentation, or a `params.delegationToken` that differs from the header
35
+ * credential): `400 invalid_request` with `Cache-Control: no-store`. That is a
36
+ * malformed request, not an authorization decision.
31
37
  *
32
38
  * @module @kya-os/mcp-i-cloudflare/delegation-http/bearer-retry
33
39
  */
34
- import type { HttpChallengeConfig } from "../config";
35
40
  import { type CardProofSupportGetter } from "../security/card-proof-support";
41
+ import { type LocalVerificationCode } from "../services/delegation.service";
36
42
  import type { CloudflareEnv } from "../types";
37
43
  /** Identify the presented VC-JWT without treating it as verified authority. */
38
44
  export declare function extractDelegationVcJwt(request: Request): string | null;
39
45
  /**
40
- * Apply a presented delegation to the outgoing MCP request before it reaches the
41
- * adapter.
46
+ * How a presented delegation classifies at the edge.
42
47
  *
43
- * - No delegation VC-JWT present → pass the request through unchanged.
44
- * - Expired VC-JWT → `{ errorResponse }` 401 `kyaos/expired` (`no-store`).
45
- * - Invalid / unverifiable VC-JWT → `{ errorResponse }` 403 `kyaos/chain-broken`
48
+ * - `invalid`: the token's own validity failed (unparseable, bad signature,
49
+ * untrusted issuer, wrong audience, not yet valid).
50
+ * - `refer`: the refusal is an authority decision (revocation, status list,
51
+ * holder binding, delegation chain), left to the Durable Object.
52
+ */
53
+ export type BearerVerdict = {
54
+ kind: "none";
55
+ } | {
56
+ kind: "valid";
57
+ holderBound: boolean;
58
+ scopes: readonly string[];
59
+ } | {
60
+ kind: "expired";
61
+ } | {
62
+ kind: "invalid";
63
+ } | {
64
+ kind: "refer";
65
+ } | {
66
+ kind: "malformed";
67
+ };
68
+ /** The verdict a refused credential maps to, by the verifier's refusal code. */
69
+ type RefusalVerdict = Extract<BearerVerdict, {
70
+ kind: "expired" | "invalid" | "refer";
71
+ }>["kind"];
72
+ /**
73
+ * Every refusal code `verifyLocally` returns, and the edge verdict it maps to.
74
+ * Keyed by the code union, so a new code fails to compile until it is placed.
75
+ * `holder_proof_required` and `holder_mismatch` are never returned while the
76
+ * holder check is deferred; they are listed so the table stays exhaustive.
77
+ */
78
+ export declare const REFUSAL_VERDICTS: Readonly<Record<LocalVerificationCode, RefusalVerdict>>;
79
+ /**
80
+ * Classify a presented VC-JWT for an edge decision. It verifies locally
81
+ * (trusted issuer, the request URL's host as audience, the kid-named key, the
82
+ * signed status list) with the holder check deferred, and returns a verdict;
83
+ * it answers nothing itself. The Durable Object stays the authority, and
84
+ * Checkpoint is never asked.
85
+ */
86
+ export declare function assessPresentedCredential(vcJwt: string, request: Request, env: CloudflareEnv, nativeIssuerDid?: string): Promise<BearerVerdict>;
87
+ /**
88
+ * Classify the delegation a request presents in its headers: none, malformed,
89
+ * or the verdict on the credential (see {@link assessPresentedCredential}).
90
+ */
91
+ export declare function assessPresentedBearer(request: Request, env: CloudflareEnv, nativeIssuerDid?: string): Promise<BearerVerdict>;
92
+ /**
93
+ * Hand a presented delegation to the adapter before the request reaches it.
94
+ *
95
+ * - No delegation VC-JWT presented → `{ request }` unchanged.
96
+ * - A request proof (card `_meta` carrier, or `Signature`, `Signature-Input`
97
+ * or `KYA-OS-Delegation-Proof`) → `{ request }` unchanged.
98
+ * - An unsigned `tools/call` → `{ request }` whose body carries
99
+ * `params.delegationToken = vcJwt`.
100
+ * - Any other message or body → `{ request }` unchanged.
101
+ * - A malformed presentation → `{ errorResponse }` 400 `invalid_request`
46
102
  * (`no-store`).
47
- * - Valid VC-JWT → `{ request }` whose JSON-RPC body now carries
48
- * `params.delegationToken = vcJwt` for unsigned legacy calls. Signed calls
49
- * remain byte-for-byte intact for proof verification and header pickup.
50
- * - Valid VC-JWT, card proof support unavailable, and `cfg.native` set →
51
- * `{ errorResponse }` 503 `proof_support_unavailable` (`no-store`), whatever
52
- * the body carries.
53
- * - Valid VC-JWT but a non-JSON-RPC body the token cannot be injected into →
54
- * `{ errorResponse }` 400 `invalid_request` (`no-store`); we never silently drop
55
- * an accepted credential.
103
+ *
104
+ * The credential is never verified here, so an expired, invalid or
105
+ * holder-bound credential goes on like any other and is refused at the
106
+ * Durable Object.
56
107
  */
57
- export declare function applyBearerDelegation(request: Request, env: CloudflareEnv, cfg: Required<HttpChallengeConfig>, getProofSupport?: CardProofSupportGetter): Promise<{
108
+ export declare function applyBearerDelegation(request: Request, getProofSupport?: CardProofSupportGetter): Promise<{
58
109
  request: Request;
59
110
  } | {
60
111
  errorResponse: Response;
61
112
  }>;
113
+ export {};
62
114
  //# sourceMappingURL=bearer-retry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"bearer-retry.d.ts","sourceRoot":"","sources":["../../src/delegation-http/bearer-retry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgCG;AAEH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EACL,KAAK,sBAAsB,EAI5B,MAAM,gCAAgC,CAAC;AAQxC,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAiB9C,+EAA+E;AAC/E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AS,GAAG,SAAS,GAAG,OAAO,CAAA;CAAE,CAC1C,CAAC,MAAM,CAAC,CAAC;AAEV;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,QAAQ,CACrC,MAAM,CAAC,qBAAqB,EAAE,cAAc,CAAC,CAS9C,CAAC;AAYF;;;;;;GAMG;AACH,wBAAsB,yBAAyB,CAC7C,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,aAAa,EAClB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,aAAa,CAAC,CAexB;AAED;;;GAGG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,aAAa,EAClB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,aAAa,CAAC,CAUxB;AA8DD;;;;;;;;;;;;;;;GAeG;AACH,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,OAAO,EAChB,eAAe,GAAE,sBAA4C,GAC5D,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,aAAa,EAAE,QAAQ,CAAA;CAAE,CAAC,CAW7D"}
@@ -1,92 +1,139 @@
1
1
  /**
2
- * draft-kya-http-02 delegation layer — Bearer retry verification.
2
+ * Presented-delegation pass-through for MCP requests.
3
3
  *
4
- * After a §8.1 challenge, a kya-capable caller retries the MCP request carrying the
5
- * minted delegation as a Bearer credential. This module turns that retry into the
6
- * adapter's existing `params.delegationToken` priority seam (adapter.ts:~458 — tested
7
- * by `adapter-delegation-priority.test.ts`), WITHOUT editing the adapter:
4
+ * A caller that holds a delegation presents it as `Authorization: Bearer <vc-jwt>`
5
+ * or in the `KYA-Delegation` header. This module moves that credential into the
6
+ * adapter's existing `params.delegationToken` priority seam (adapter.ts:~458 —
7
+ * tested by `adapter-delegation-priority.test.ts`), WITHOUT editing the adapter.
8
+ * It never verifies the credential and never answers an authorization decision:
9
+ * the Durable Object is the authority. Its delegation verification (org issuer,
10
+ * the routed host as audience, the signed status list, holder binding) and its
11
+ * request admission run for every `tools/call`, and a refusal comes back to the
12
+ * client as the delegation-required tool result, on every transport.
8
13
  *
9
14
  * - `extractDelegationVcJwt` accepts `Authorization: Bearer <jwt>` ONLY when the
10
15
  * decoded JWT payload carries a `vc` claim. An opaque OAuth bearer (no `vc`) is
11
16
  * left untouched (returns null) so existing OAuth clients pass through. When
12
17
  * `Authorization` is occupied by such a non-VC bearer, the `KYA-Delegation` header
13
18
  * is used as the fallback carrier.
14
- * - `applyBearerDelegation` verifies the VC-JWT fail-fast via `DelegationService`
15
- * (pinned issuer, accepted audience, signature, credential status) and, for
16
- * unsigned legacy requests, adds `params.delegationToken = vcJwt`.
17
- * An invalid chain → 403 `kyaos/chain-broken`; an expired credential → 401
18
- * `kyaos/expired`. Both error responses carry `Cache-Control: no-store`.
19
+ * - `applyBearerDelegation` adds `params.delegationToken = vcJwt` to an unsigned
20
+ * `tools/call` and passes every other request through unchanged.
19
21
  * - A request that carries a request proof (a card `_meta` carrier or an HTTP
20
22
  * message signature header) keeps its body byte for byte, because rewriting
21
23
  * it would break the proof; admission reads the credential from the transport
22
24
  * headers instead. The card keys come only from the validated card proof
23
25
  * support accessor: in an esbuild bundle the statically imported card
24
26
  * constants can stay undefined, which made every signed body look unsigned
25
- * and get rewritten.
26
- * - When that support cannot be validated, a worker with a native HTTP issuer
27
- * refuses the retry with 503 `proof_support_unavailable` (`no-store`) instead
28
- * of risking a signed call being handled as unsigned. Other workers leave
29
- * any proof-shaped body untouched and still rewrite bodies with no proof
30
- * shape at all, so unsigned legacy retries keep working.
27
+ * and get rewritten. When that support cannot be validated, the
28
+ * proof-shaped superset decides, so a proof-shaped body is left untouched.
29
+ * - `assessPresentedBearer` and `assessPresentedCredential` classify a
30
+ * presented delegation (none, valid, expired, invalid, refer, malformed)
31
+ * for the lazy-auth gate (./lazy-auth-gate). They are not part of the
32
+ * pass-through.
33
+ * - The one refusal left is a malformed presentation (an unparseable header
34
+ * presentation, or a `params.delegationToken` that differs from the header
35
+ * credential): `400 invalid_request` with `Cache-Control: no-store`. That is a
36
+ * malformed request, not an authorization decision.
31
37
  *
32
38
  * @module @kya-os/mcp-i-cloudflare/delegation-http/bearer-retry
33
39
  */
34
- import { getCardProofSupport, isProofShapedMeta, PROOF_SUPPORT_UNAVAILABLE, } from "../security/card-proof-support";
35
- import { decodeJwtPayload, hasCardProofCarrier, InvalidDelegationPresentation, readHeaderDelegation, } from "../security/presented-delegation";
36
- import { DelegationService } from "../services/delegation.service";
37
- import { KYAOS_ERRORS } from "./constants";
40
+ import { getCardProofSupport, } from "../security/card-proof-support";
41
+ import { decodeJwtPayload, InvalidDelegationPresentation, readHeaderDelegation, } from "../security/presented-delegation";
42
+ import { DelegationService, } from "../services/delegation.service";
43
+ import { carriesRequestProof } from "./request-proof";
44
+ /** Identify the presented VC-JWT without treating it as verified authority. */
45
+ export function extractDelegationVcJwt(request) {
46
+ return readHeaderDelegation((name) => request.headers.get(name)) ?? null;
47
+ }
38
48
  /**
39
- * Whether the JWT is expired by its `exp` claim (seconds since epoch). A token with
40
- * no numeric `exp`, or one that cannot be decoded, is treated as NOT expired here —
41
- * the cryptographic verification path owns the invalid-vs-expired distinction for
42
- * those cases (and reports them as 403 chain-broken).
49
+ * Every refusal code `verifyLocally` returns, and the edge verdict it maps to.
50
+ * Keyed by the code union, so a new code fails to compile until it is placed.
51
+ * `holder_proof_required` and `holder_mismatch` are never returned while the
52
+ * holder check is deferred; they are listed so the table stays exhaustive.
43
53
  */
54
+ export const REFUSAL_VERDICTS = {
55
+ invalid_token: "invalid",
56
+ delegation_expired: "expired",
57
+ delegation_not_yet_valid: "invalid",
58
+ delegation_revoked: "refer",
59
+ revocation_check_failed: "refer",
60
+ holder_proof_required: "refer",
61
+ holder_mismatch: "refer",
62
+ };
63
+ /** Whether the JWT is expired by a numeric `exp` claim; undecodable or no `exp` is not. */
44
64
  function isVcJwtExpired(jwt) {
45
- const payload = decodeJwtPayload(jwt);
46
- if (!payload)
47
- return false;
48
- const exp = payload.exp;
49
- if (typeof exp !== "number" || !Number.isFinite(exp))
50
- return false;
51
- return exp < Math.floor(Date.now() / 1000);
65
+ const exp = decodeJwtPayload(jwt)?.exp;
66
+ return (typeof exp === "number" &&
67
+ Number.isFinite(exp) &&
68
+ exp < Math.floor(Date.now() / 1000));
52
69
  }
53
- /** Identify the presented VC-JWT without treating it as verified authority. */
54
- export function extractDelegationVcJwt(request) {
55
- return readHeaderDelegation((name) => request.headers.get(name)) ?? null;
70
+ /**
71
+ * Classify a presented VC-JWT for an edge decision. It verifies locally
72
+ * (trusted issuer, the request URL's host as audience, the kid-named key, the
73
+ * signed status list) with the holder check deferred, and returns a verdict;
74
+ * it answers nothing itself. The Durable Object stays the authority, and
75
+ * Checkpoint is never asked.
76
+ */
77
+ export async function assessPresentedCredential(vcJwt, request, env, nativeIssuerDid) {
78
+ if (isVcJwtExpired(vcJwt))
79
+ return { kind: "expired" };
80
+ const verified = await new DelegationService(env, undefined, {
81
+ trustedIssuers: [nativeIssuerDid],
82
+ routedHost: new URL(request.url).host,
83
+ }).verifyLocally(vcJwt, { deferHolderBinding: true });
84
+ if (verified.valid)
85
+ return {
86
+ kind: "valid",
87
+ holderBound: verified.holderBound === true,
88
+ scopes: verified.scopes ?? [],
89
+ };
90
+ // A refusal without a code is not the token's own validity to call.
91
+ return { kind: verified.code ? REFUSAL_VERDICTS[verified.code] : "refer" };
56
92
  }
57
93
  /**
58
- * Build a `kyaos/*` JSON error response with the mandated `Cache-Control: no-store`.
94
+ * Classify the delegation a request presents in its headers: none, malformed,
95
+ * or the verdict on the credential (see {@link assessPresentedCredential}).
59
96
  */
60
- function kyaosError(error, status) {
61
- return new Response(JSON.stringify({ error }), {
62
- status,
97
+ export async function assessPresentedBearer(request, env, nativeIssuerDid) {
98
+ let vcJwt;
99
+ try {
100
+ vcJwt = extractDelegationVcJwt(request);
101
+ }
102
+ catch (error) {
103
+ if (!(error instanceof InvalidDelegationPresentation))
104
+ throw error;
105
+ return { kind: "malformed" };
106
+ }
107
+ if (!vcJwt)
108
+ return { kind: "none" };
109
+ return assessPresentedCredential(vcJwt, request, env, nativeIssuerDid);
110
+ }
111
+ /** The malformed-presentation response: a bad request, not an authorization decision. */
112
+ function invalidRequest() {
113
+ return new Response(JSON.stringify({ error: "invalid_request" }), {
114
+ status: 400,
63
115
  headers: {
64
116
  "Content-Type": "application/json",
65
117
  "Cache-Control": "no-store",
66
118
  },
67
119
  });
68
120
  }
69
- /** Headers whose signature covers the body, so the body must not change. */
70
- const SIGNED_REQUEST_HEADERS = [
71
- "Signature",
72
- "Signature-Input",
73
- "KYA-OS-Delegation-Proof",
74
- ];
75
121
  /**
76
122
  * Clone `request` rewriting the JSON-RPC body so `params.delegationToken = vcJwt`.
77
- * Returns `null` when the body is not JSON-RPC-shaped JSON (so the caller can pass the
78
- * request through untouched rather than corrupt a non-JSON-RPC request).
123
+ * A call carrying a request proof is returned unchanged. A body that is not a
124
+ * JSON-RPC object is returned unchanged. Throws `InvalidDelegationPresentation`
125
+ * when the body already carries a different `params.delegationToken`.
79
126
  */
80
- async function rewriteDelegationToken(request, vcJwt, carriesRequestProof) {
127
+ async function rewriteDelegationToken(request, vcJwt, getProofSupport) {
81
128
  let body;
82
129
  try {
83
130
  body = await request.clone().json();
84
131
  }
85
132
  catch {
86
- return null;
133
+ return request;
87
134
  }
88
135
  if (!body || typeof body !== "object" || Array.isArray(body))
89
- return null;
136
+ return request;
90
137
  const rpc = body;
91
138
  const params = rpc.params && typeof rpc.params === "object"
92
139
  ? { ...rpc.params }
@@ -94,114 +141,52 @@ async function rewriteDelegationToken(request, vcJwt, carriesRequestProof) {
94
141
  if (Object.prototype.hasOwnProperty.call(params, "delegationToken") &&
95
142
  params.delegationToken !== vcJwt)
96
143
  throw new InvalidDelegationPresentation();
144
+ // Only a tool call reads the credential; every other message goes on as sent.
145
+ if (rpc.method !== "tools/call")
146
+ return request;
97
147
  // Re-serializing or adding fields would invalidate native or HTTP request
98
148
  // proofs. Admission receives the credential via transport request headers.
99
- // Proof presence is sufficient here: actual verification remains mandatory
100
- // downstream, including for malformed proof values.
101
- if (carriesRequestProof(params._meta) ||
102
- SIGNED_REQUEST_HEADERS.some((name) => request.headers.has(name)))
149
+ // Without validated card keys the proof-shaped superset decides: a false
150
+ // "signed" only withholds the body rewrite, a false "unsigned" breaks a proof
151
+ // (see ./request-proof).
152
+ if (await carriesRequestProof(request.headers, params._meta, getProofSupport))
103
153
  return request;
104
154
  params.delegationToken = vcJwt;
105
- const nextBody = { ...rpc, params };
106
155
  return new Request(request.url, {
107
156
  method: request.method,
108
157
  headers: request.headers,
109
- body: JSON.stringify(nextBody),
158
+ body: JSON.stringify({ ...rpc, params }),
110
159
  });
111
160
  }
112
161
  /**
113
- * Apply a presented delegation to the outgoing MCP request before it reaches the
114
- * adapter.
162
+ * Hand a presented delegation to the adapter before the request reaches it.
115
163
  *
116
- * - No delegation VC-JWT present → pass the request through unchanged.
117
- * - Expired VC-JWT → `{ errorResponse }` 401 `kyaos/expired` (`no-store`).
118
- * - Invalid / unverifiable VC-JWT → `{ errorResponse }` 403 `kyaos/chain-broken`
164
+ * - No delegation VC-JWT presented → `{ request }` unchanged.
165
+ * - A request proof (card `_meta` carrier, or `Signature`, `Signature-Input`
166
+ * or `KYA-OS-Delegation-Proof`) → `{ request }` unchanged.
167
+ * - An unsigned `tools/call` → `{ request }` whose body carries
168
+ * `params.delegationToken = vcJwt`.
169
+ * - Any other message or body → `{ request }` unchanged.
170
+ * - A malformed presentation → `{ errorResponse }` 400 `invalid_request`
119
171
  * (`no-store`).
120
- * - Valid VC-JWT → `{ request }` whose JSON-RPC body now carries
121
- * `params.delegationToken = vcJwt` for unsigned legacy calls. Signed calls
122
- * remain byte-for-byte intact for proof verification and header pickup.
123
- * - Valid VC-JWT, card proof support unavailable, and `cfg.native` set →
124
- * `{ errorResponse }` 503 `proof_support_unavailable` (`no-store`), whatever
125
- * the body carries.
126
- * - Valid VC-JWT but a non-JSON-RPC body the token cannot be injected into →
127
- * `{ errorResponse }` 400 `invalid_request` (`no-store`); we never silently drop
128
- * an accepted credential.
172
+ *
173
+ * The credential is never verified here, so an expired, invalid or
174
+ * holder-bound credential goes on like any other and is refused at the
175
+ * Durable Object.
129
176
  */
130
- export async function applyBearerDelegation(request, env, cfg, getProofSupport = getCardProofSupport) {
131
- let vcJwt;
132
- try {
133
- vcJwt = extractDelegationVcJwt(request);
134
- }
135
- catch (error) {
136
- if (!(error instanceof InvalidDelegationPresentation))
137
- throw error;
138
- return { errorResponse: kyaosError("invalid_request", 400) };
139
- }
140
- if (!vcJwt) {
141
- return { request };
142
- }
143
- // Fail-fast expiry check before verification so we can emit the precise 401.
144
- if (isVcJwtExpired(vcJwt)) {
145
- return { errorResponse: kyaosError(KYAOS_ERRORS.expired, 401) };
146
- }
147
- // The native issuer (code config or the provisioned binding) is
148
- // deployment-owned: its org DID is a pinned issuer. The expected audience is
149
- // did:web:<this request's own Host>, which must be one of this worker's
150
- // resources. The host is the URL the edge delivered (WfP dispatch forwards
151
- // the original request); no forwarding header is read.
152
- const native = cfg.native ?? undefined;
153
- const isValid = await new DelegationService(env, undefined, {
154
- trustedIssuers: [native?.issuerDid],
155
- routedHost: new URL(request.url).host,
156
- }).verifyDelegation(vcJwt);
157
- if (!isValid) {
158
- // verifyDelegation also rejects expired tokens; re-check so an expiry that the
159
- // pre-check missed (e.g. exp encoded unusually) still maps to 401 not 403.
160
- if (isVcJwtExpired(vcJwt)) {
161
- return { errorResponse: kyaosError(KYAOS_ERRORS.expired, 401) };
162
- }
163
- return { errorResponse: kyaosError(KYAOS_ERRORS.chainBroken, 403) };
164
- }
165
- // Resolved only once a credential has verified, so a retry-free request
166
- // never waits on the card module.
167
- const proofSupport = await getProofSupport();
168
- if (!proofSupport.ok && cfg.native) {
169
- // A native issuer serves callers that sign their calls. Without the card
170
- // keys a signed body cannot be told apart reliably, and handling it as
171
- // unsigned would admit it without its holder, so refuse the retry.
172
- return { errorResponse: kyaosError(PROOF_SUPPORT_UNAVAILABLE, 503) };
173
- }
174
- // Without validated keys, the card-independent superset decides: a false
175
- // "signed" only withholds the body rewrite, a false "unsigned" breaks a proof.
176
- // Presence under a validated card key, including a malformed value, counts
177
- // as signed: verification stays mandatory downstream, and a null carrier
178
- // must not turn a signed call into an unsigned one.
179
- const carriesRequestProof = proofSupport.ok
180
- ? (meta) => hasCardProofCarrier(meta, proofSupport.support)
181
- : (meta) => isProofShapedMeta(meta);
182
- let rewritten;
177
+ export async function applyBearerDelegation(request, getProofSupport = getCardProofSupport) {
183
178
  try {
184
- rewritten = await rewriteDelegationToken(request, vcJwt, carriesRequestProof);
179
+ const vcJwt = extractDelegationVcJwt(request);
180
+ if (!vcJwt)
181
+ return { request };
182
+ return {
183
+ request: await rewriteDelegationToken(request, vcJwt, getProofSupport),
184
+ };
185
185
  }
186
186
  catch (error) {
187
187
  if (!(error instanceof InvalidDelegationPresentation))
188
188
  throw error;
189
- return { errorResponse: kyaosError("invalid_request", 400) };
190
- }
191
- if (!rewritten) {
192
- // The delegation verified, but the request body is not a JSON-RPC object we can
193
- // augment with params.delegationToken. Fail explicitly with 400: silently
194
- // forwarding the original request would drop the ACCEPTED credential, and the
195
- // adapter would then treat the call as unauthorized — masking the acceptance.
196
- // (A real /mcp POST always carries a JSON-RPC object, so this is a
197
- // malformed-request guard, not a normal path.)
198
- //
199
- // `invalid_request`/400 is deliberately OUT-OF-BAND from the §9 `kyaos/*` registry:
200
- // this is a transport-level malformed-body error, not a delegation-chain verdict.
201
- // Reusing a `kyaos/*` 401/403 here would mislead the caller into a retry/challenge
202
- // loop, and the registry (vendored error-codes.json) has no malformed-body code.
203
- return { errorResponse: kyaosError("invalid_request", 400) };
189
+ return { errorResponse: invalidRequest() };
204
190
  }
205
- return { request: rewritten };
206
191
  }
207
192
  //# sourceMappingURL=bearer-retry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bearer-retry.js","sourceRoot":"","sources":["../../src/delegation-http/b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AC7C,CAAC;AACH,CAAC"}
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Connection auth at the edge: ordinary MCP Authorization.
3
+ *
4
+ * When a deployment turns on `requireTokenToConnect` (config) or
5
+ * `MCPI_REQUIRE_TOKEN_TO_CONNECT` (env), every MCP request needs a valid
6
+ * Bearer credential for this resource. Without one the edge answers the
7
+ * connect-time 401 that sends an OAuth client to the protected-resource
8
+ * metadata. The decision is made on the request headers alone, before the
9
+ * request reaches the agent.
10
+ *
11
+ * It is off unless the deployment turns it on; when off, nothing changes. The
12
+ * per-tool lazy auth gate (./lazy-auth-gate) is separate and unchanged.
13
+ *
14
+ * It applies to every caller, KYA-OS native ones included: requiring a token
15
+ * to connect is the deployment's choice. Per-tool refusals stay tool results.
16
+ *
17
+ * Verdicts:
18
+ * - none or malformed: 401;
19
+ * - expired or invalid (the token's own validity): 401 `invalid_token`;
20
+ * - valid: pass;
21
+ * - refer (revocation, status list, holder binding): pass. The edge cannot
22
+ * decide these; the Durable Object decides them per tool.
23
+ *
24
+ * A verification that cannot run fails closed with 503 and `Retry-After`:
25
+ * the deployment chose to require a token, so a request that could not be
26
+ * checked is not let through.
27
+ *
28
+ * @module @kya-os/mcp-i-cloudflare/delegation-http/connect-gate
29
+ */
30
+ import type { CloudflareRuntimeConfig } from "../config";
31
+ import type { CloudflareEnv } from "../types";
32
+ import { type BearerVerdict } from "./bearer-retry";
33
+ import { type LazyAuthAction } from "./lazy-auth-gate";
34
+ /**
35
+ * Whether the deployment requires a token to connect: the config flag, or the
36
+ * env var set to "true" or "1". Either turns it on; neither turns it off.
37
+ */
38
+ export declare function requiresTokenToConnect(env: Pick<CloudflareEnv, "MCPI_REQUIRE_TOKEN_TO_CONNECT">, runtimeConfig: Pick<CloudflareRuntimeConfig, "requireTokenToConnect">): boolean;
39
+ /** The connect decision for a verdict. Pure. */
40
+ export declare function decideConnect(verdict: BearerVerdict): LazyAuthAction;
41
+ /**
42
+ * Decide a request at the edge. Returns the 401 (or 503) response, or null
43
+ * when the request goes on to the agent. The credential comes from the
44
+ * request headers only.
45
+ */
46
+ export declare function applyConnectGate(request: Request, env: CloudflareEnv): Promise<Response | null>;
47
+ //# sourceMappingURL=connect-gate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"connect-gate.d.ts","sourceRoot":"","sources":["../../src/delegation-http/connect-gate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAEzD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,KAAK,cAAc,EAAoB,MAAM,kBAAkB,CAAC;AAEzE;;;GAGG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,IAAI,CAAC,aAAa,EAAE,+BAA+B,CAAC,EACzD,aAAa,EAAE,IAAI,CAAC,uBAAuB,EAAE,uBAAuB,CAAC,GACpE,OAAO,CAMT;AAED,gDAAgD;AAChD,wBAAgB,aAAa,CAAC,OAAO,EAAE,aAAa,GAAG,cAAc,CA2BpE;AAmBD;;;;GAIG;AACH,wBAAsB,gBAAgB,CACpC,OAAO,EAAE,OAAO,EAChB,GAAG,EAAE,aAAa,GACjB,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,CAa1B"}