@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool-security-schemes.d.ts","sourceRoot":"","sources":["../../src/utils/tool-security-schemes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAQzE,gEAAgE;AAChE,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,kBAAkB,CAAC,EAAE,OAAO,CAAC;IACtC,QAAQ,CAAC,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7C;AAED,0EAA0E;AAC1E,MAAM,MAAM,iBAAiB,GAAG,QAAQ,CACtC,MAAM,CAAC,MAAM,EAAE,oBAAoB,GAAG,SAAS,CAAC,CACjD,CAAC;AAEF,2EAA2E;AAC3E,MAAM,WAAW,wBAAwB;IACvC,GAAG,IAAI,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,CAAC;IAC9C,GAAG,CAAC,WAAW,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpD;AAOD,kEAAkE;AAClE,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,iBAAiB,GAC7B,KAAK,CAAC;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,CAAC,CAQlE;AAgDD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,EAAE,EAAE,WAAW,EACf,GAAG,EAAE,MAAM,GACV,wBAAwB,CAW1B;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,SAAS,EACjB,OAAO,EAAE,MAAM,OAAO,CAAC,iBAAiB,GAAG,SAAS,CAAC,EACrD,aAAa,CAAC,EAAE,wBAAwB,GACvC,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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Aa,CAAC,GAAG,EAAE,CAAC;gBAC1C,CAAC;gBAAC,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.18.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",
@@ -33,9 +32,9 @@
33
32
  "dependencies": {
34
33
  "@kya-os/consent": "^0.2.0",
35
34
  "@kya-os/contracts": "^1.14.0",
36
- "@kya-os/mcp": "1.16.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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