effect 4.0.7 → 4.1.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 (863) hide show
  1. package/README.md +31 -1
  2. package/THIRD_PARTY_NOTICES.md +62 -0
  3. package/dist/BigDecimal.d.ts +139 -7
  4. package/dist/BigDecimal.d.ts.map +1 -1
  5. package/dist/BigDecimal.js +86 -14
  6. package/dist/BigDecimal.js.map +1 -1
  7. package/dist/Channel.d.ts +12 -6
  8. package/dist/Channel.d.ts.map +1 -1
  9. package/dist/Channel.js +9 -3
  10. package/dist/Channel.js.map +1 -1
  11. package/dist/Config.d.ts +7 -1
  12. package/dist/Config.d.ts.map +1 -1
  13. package/dist/Config.js.map +1 -1
  14. package/dist/Context.d.ts +18 -1
  15. package/dist/Context.d.ts.map +1 -1
  16. package/dist/Context.js +27 -8
  17. package/dist/Context.js.map +1 -1
  18. package/dist/Cron.d.ts +81 -11
  19. package/dist/Cron.d.ts.map +1 -1
  20. package/dist/Cron.js +101 -26
  21. package/dist/Cron.js.map +1 -1
  22. package/dist/Duration.d.ts +78 -0
  23. package/dist/Duration.d.ts.map +1 -1
  24. package/dist/Duration.js +123 -0
  25. package/dist/Duration.js.map +1 -1
  26. package/dist/Effect.d.ts +164 -7
  27. package/dist/Effect.d.ts.map +1 -1
  28. package/dist/Effect.js +11 -1
  29. package/dist/Effect.js.map +1 -1
  30. package/dist/Equal.d.ts +2 -2
  31. package/dist/Equal.d.ts.map +1 -1
  32. package/dist/Equal.js +3 -3
  33. package/dist/Equal.js.map +1 -1
  34. package/dist/FileSystem.d.ts +59 -4
  35. package/dist/FileSystem.d.ts.map +1 -1
  36. package/dist/FileSystem.js +9 -2
  37. package/dist/FileSystem.js.map +1 -1
  38. package/dist/Glob.d.ts +165 -0
  39. package/dist/Glob.d.ts.map +1 -0
  40. package/dist/Glob.js +127 -0
  41. package/dist/Glob.js.map +1 -0
  42. package/dist/Hash.d.ts +3 -2
  43. package/dist/Hash.d.ts.map +1 -1
  44. package/dist/Hash.js +5 -4
  45. package/dist/Hash.js.map +1 -1
  46. package/dist/Iterable.d.ts.map +1 -1
  47. package/dist/Iterable.js +11 -8
  48. package/dist/Iterable.js.map +1 -1
  49. package/dist/Match.d.ts +86 -0
  50. package/dist/Match.d.ts.map +1 -1
  51. package/dist/Match.js +72 -0
  52. package/dist/Match.js.map +1 -1
  53. package/dist/Path.d.ts.map +1 -1
  54. package/dist/Path.js +5 -1
  55. package/dist/Path.js.map +1 -1
  56. package/dist/Pool.d.ts +51 -0
  57. package/dist/Pool.d.ts.map +1 -1
  58. package/dist/Pool.js +61 -10
  59. package/dist/Pool.js.map +1 -1
  60. package/dist/Random.d.ts.map +1 -1
  61. package/dist/Random.js +3 -3
  62. package/dist/Random.js.map +1 -1
  63. package/dist/RcMap.d.ts.map +1 -1
  64. package/dist/RcMap.js +8 -2
  65. package/dist/RcMap.js.map +1 -1
  66. package/dist/Schedule.d.ts +18 -1
  67. package/dist/Schedule.d.ts.map +1 -1
  68. package/dist/Schedule.js +7 -2
  69. package/dist/Schedule.js.map +1 -1
  70. package/dist/Schema.d.ts +668 -42
  71. package/dist/Schema.d.ts.map +1 -1
  72. package/dist/Schema.js +652 -1
  73. package/dist/Schema.js.map +1 -1
  74. package/dist/SchemaGetter.d.ts +6 -1
  75. package/dist/SchemaGetter.d.ts.map +1 -1
  76. package/dist/SchemaGetter.js +22 -11
  77. package/dist/SchemaGetter.js.map +1 -1
  78. package/dist/SchemaRepresentation.d.ts +18 -2
  79. package/dist/SchemaRepresentation.d.ts.map +1 -1
  80. package/dist/SchemaRepresentation.js +20 -2
  81. package/dist/SchemaRepresentation.js.map +1 -1
  82. package/dist/SchemaTransformation.d.ts +10 -5
  83. package/dist/SchemaTransformation.d.ts.map +1 -1
  84. package/dist/SchemaTransformation.js +8 -5
  85. package/dist/SchemaTransformation.js.map +1 -1
  86. package/dist/ScopedCache.d.ts.map +1 -1
  87. package/dist/ScopedCache.js +5 -7
  88. package/dist/ScopedCache.js.map +1 -1
  89. package/dist/Semaphore.d.ts +130 -0
  90. package/dist/Semaphore.d.ts.map +1 -1
  91. package/dist/Semaphore.js +40 -0
  92. package/dist/Semaphore.js.map +1 -1
  93. package/dist/Stream.d.ts +13 -4
  94. package/dist/Stream.d.ts.map +1 -1
  95. package/dist/Stream.js +9 -0
  96. package/dist/Stream.js.map +1 -1
  97. package/dist/Terminal.d.ts +18 -1
  98. package/dist/Terminal.d.ts.map +1 -1
  99. package/dist/Terminal.js +1 -1
  100. package/dist/Terminal.js.map +1 -1
  101. package/dist/ai/AiError.d.ts +43 -116
  102. package/dist/ai/AiError.d.ts.map +1 -1
  103. package/dist/ai/AiError.js +53 -72
  104. package/dist/ai/AiError.js.map +1 -1
  105. package/dist/ai/Decision.d.ts +196 -15
  106. package/dist/ai/Decision.d.ts.map +1 -1
  107. package/dist/ai/Decision.js +130 -0
  108. package/dist/ai/Decision.js.map +1 -1
  109. package/dist/ai/DecisionModel.d.ts +54 -13
  110. package/dist/ai/DecisionModel.d.ts.map +1 -1
  111. package/dist/ai/DecisionModel.js +123 -12
  112. package/dist/ai/DecisionModel.js.map +1 -1
  113. package/dist/ai/McpClient.d.ts +171 -19
  114. package/dist/ai/McpClient.d.ts.map +1 -1
  115. package/dist/ai/McpClient.js +277 -66
  116. package/dist/ai/McpClient.js.map +1 -1
  117. package/dist/ai/McpSchema.d.ts +108 -0
  118. package/dist/ai/McpSchema.d.ts.map +1 -1
  119. package/dist/ai/McpSchema.js +99 -0
  120. package/dist/ai/McpSchema.js.map +1 -1
  121. package/dist/ai/McpServer.d.ts +744 -29
  122. package/dist/ai/McpServer.d.ts.map +1 -1
  123. package/dist/ai/McpServer.js +763 -136
  124. package/dist/ai/McpServer.js.map +1 -1
  125. package/dist/ai/McpTest.d.ts +130 -0
  126. package/dist/ai/McpTest.d.ts.map +1 -0
  127. package/dist/ai/McpTest.js +237 -0
  128. package/dist/ai/McpTest.js.map +1 -0
  129. package/dist/ai/Prompt.d.ts.map +1 -1
  130. package/dist/ai/Prompt.js +20 -11
  131. package/dist/ai/Prompt.js.map +1 -1
  132. package/dist/ai/Response.d.ts +1 -25
  133. package/dist/ai/Response.d.ts.map +1 -1
  134. package/dist/ai/Response.js +1 -10
  135. package/dist/ai/Response.js.map +1 -1
  136. package/dist/ai/Tool.d.ts +19 -1
  137. package/dist/ai/Tool.d.ts.map +1 -1
  138. package/dist/ai/Tool.js +5 -7
  139. package/dist/ai/Tool.js.map +1 -1
  140. package/dist/ai/index.d.ts +5 -0
  141. package/dist/ai/index.d.ts.map +1 -1
  142. package/dist/ai/index.js +5 -0
  143. package/dist/ai/index.js.map +1 -1
  144. package/dist/ai/internal/mcpCore.js +89 -15
  145. package/dist/ai/internal/mcpCore.js.map +1 -1
  146. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +7 -6
  147. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  148. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +7 -6
  149. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  150. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +7 -6
  151. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  152. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +7 -6
  153. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  154. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +60 -17
  155. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  156. package/dist/ai/internal/mcpProtocol.js +25 -0
  157. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  158. package/dist/ai/internal/mcpRuntime.js +8 -6
  159. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  160. package/dist/ai/internal/mcpSkills.d.ts +2 -0
  161. package/dist/ai/internal/mcpSkills.d.ts.map +1 -0
  162. package/dist/ai/internal/mcpSkills.js +428 -0
  163. package/dist/ai/internal/mcpSkills.js.map +1 -0
  164. package/dist/ai/internal/mcpStatefulRuntime.js +6 -1
  165. package/dist/ai/internal/mcpStatefulRuntime.js.map +1 -1
  166. package/dist/cli/Argument.d.ts +6 -0
  167. package/dist/cli/Argument.d.ts.map +1 -1
  168. package/dist/cli/Argument.js +2 -0
  169. package/dist/cli/Argument.js.map +1 -1
  170. package/dist/cli/CliOutput.d.ts +65 -1
  171. package/dist/cli/CliOutput.d.ts.map +1 -1
  172. package/dist/cli/CliOutput.js +94 -37
  173. package/dist/cli/CliOutput.js.map +1 -1
  174. package/dist/cli/Command.d.ts +23 -0
  175. package/dist/cli/Command.d.ts.map +1 -1
  176. package/dist/cli/Command.js +8 -0
  177. package/dist/cli/Command.js.map +1 -1
  178. package/dist/cli/Flag.d.ts +107 -0
  179. package/dist/cli/Flag.d.ts.map +1 -1
  180. package/dist/cli/Flag.js +37 -0
  181. package/dist/cli/Flag.js.map +1 -1
  182. package/dist/cli/HelpDoc.d.ts +15 -1
  183. package/dist/cli/HelpDoc.d.ts.map +1 -1
  184. package/dist/cli/Param.d.ts +6 -0
  185. package/dist/cli/Param.d.ts.map +1 -1
  186. package/dist/cli/Param.js +2 -0
  187. package/dist/cli/Param.js.map +1 -1
  188. package/dist/cli/Primitive.d.ts +14 -0
  189. package/dist/cli/Primitive.d.ts.map +1 -1
  190. package/dist/cli/Primitive.js +15 -1
  191. package/dist/cli/Primitive.js.map +1 -1
  192. package/dist/cli/Prompt.d.ts +1 -0
  193. package/dist/cli/Prompt.d.ts.map +1 -1
  194. package/dist/cli/Prompt.js +1 -0
  195. package/dist/cli/Prompt.js.map +1 -1
  196. package/dist/cli/internal/help.d.ts.map +1 -1
  197. package/dist/cli/internal/help.js +17 -10
  198. package/dist/cli/internal/help.js.map +1 -1
  199. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  200. package/dist/cluster/ClusterWorkflowEngine.js +15 -5
  201. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  202. package/dist/cluster/Reply.d.ts +1 -1
  203. package/dist/cluster/Reply.d.ts.map +1 -1
  204. package/dist/cluster/Reply.js.map +1 -1
  205. package/dist/cluster/Sharding.d.ts.map +1 -1
  206. package/dist/cluster/Sharding.js +93 -28
  207. package/dist/cluster/Sharding.js.map +1 -1
  208. package/dist/cluster/ShardingConfig.d.ts +72 -6
  209. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  210. package/dist/cluster/ShardingConfig.js +4 -0
  211. package/dist/cluster/ShardingConfig.js.map +1 -1
  212. package/dist/cluster/SingleRunner.d.ts +3 -3
  213. package/dist/cluster/SingleRunner.d.ts.map +1 -1
  214. package/dist/cluster/SingleRunner.js +1 -1
  215. package/dist/cluster/SqlMessageStorage.d.ts +37 -6
  216. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  217. package/dist/cluster/SqlMessageStorage.js +34 -7
  218. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  219. package/dist/cluster/SqlRunnerStorage.d.ts.map +1 -1
  220. package/dist/cluster/SqlRunnerStorage.js +23 -8
  221. package/dist/cluster/SqlRunnerStorage.js.map +1 -1
  222. package/dist/cluster/internal/entityManager.js +15 -7
  223. package/dist/cluster/internal/entityManager.js.map +1 -1
  224. package/dist/crypto/Aead.d.ts +323 -0
  225. package/dist/crypto/Aead.d.ts.map +1 -0
  226. package/dist/crypto/Aead.js +331 -0
  227. package/dist/crypto/Aead.js.map +1 -0
  228. package/dist/crypto/Cipher.d.ts +236 -0
  229. package/dist/crypto/Cipher.d.ts.map +1 -0
  230. package/dist/crypto/Cipher.js +233 -0
  231. package/dist/crypto/Cipher.js.map +1 -0
  232. package/dist/crypto/CryptoError.d.ts +212 -0
  233. package/dist/crypto/CryptoError.d.ts.map +1 -0
  234. package/dist/crypto/CryptoError.js +202 -0
  235. package/dist/crypto/CryptoError.js.map +1 -0
  236. package/dist/crypto/Digest.d.ts +143 -0
  237. package/dist/crypto/Digest.d.ts.map +1 -0
  238. package/dist/crypto/Digest.js +146 -0
  239. package/dist/crypto/Digest.js.map +1 -0
  240. package/dist/crypto/Kdf.d.ts +220 -0
  241. package/dist/crypto/Kdf.d.ts.map +1 -0
  242. package/dist/crypto/Kdf.js +212 -0
  243. package/dist/crypto/Kdf.js.map +1 -0
  244. package/dist/crypto/KeyAgreement.d.ts +324 -0
  245. package/dist/crypto/KeyAgreement.d.ts.map +1 -0
  246. package/dist/crypto/KeyAgreement.js +303 -0
  247. package/dist/crypto/KeyAgreement.js.map +1 -0
  248. package/dist/crypto/KeyFormat.d.ts +341 -0
  249. package/dist/crypto/KeyFormat.d.ts.map +1 -0
  250. package/dist/crypto/KeyFormat.js +556 -0
  251. package/dist/crypto/KeyFormat.js.map +1 -0
  252. package/dist/crypto/KeyWrap.d.ts +390 -0
  253. package/dist/crypto/KeyWrap.d.ts.map +1 -0
  254. package/dist/crypto/KeyWrap.js +381 -0
  255. package/dist/crypto/KeyWrap.js.map +1 -0
  256. package/dist/crypto/Mac.d.ts +278 -0
  257. package/dist/crypto/Mac.d.ts.map +1 -0
  258. package/dist/crypto/Mac.js +288 -0
  259. package/dist/crypto/Mac.js.map +1 -0
  260. package/dist/crypto/SecureRandom.d.ts +340 -0
  261. package/dist/crypto/SecureRandom.d.ts.map +1 -0
  262. package/dist/crypto/SecureRandom.js +257 -0
  263. package/dist/crypto/SecureRandom.js.map +1 -0
  264. package/dist/crypto/Signature.d.ts +449 -0
  265. package/dist/crypto/Signature.d.ts.map +1 -0
  266. package/dist/crypto/Signature.js +484 -0
  267. package/dist/crypto/Signature.js.map +1 -0
  268. package/dist/crypto/WebCrypto.d.ts +80 -0
  269. package/dist/crypto/WebCrypto.d.ts.map +1 -0
  270. package/dist/crypto/WebCrypto.js +63 -0
  271. package/dist/crypto/WebCrypto.js.map +1 -0
  272. package/dist/crypto/index.d.ts +65 -0
  273. package/dist/crypto/index.d.ts.map +1 -0
  274. package/dist/crypto/index.js +66 -0
  275. package/dist/crypto/index.js.map +1 -0
  276. package/dist/crypto/internal/asymmetric.d.ts +2 -0
  277. package/dist/crypto/internal/asymmetric.d.ts.map +1 -0
  278. package/dist/crypto/internal/asymmetric.js +210 -0
  279. package/dist/crypto/internal/asymmetric.js.map +1 -0
  280. package/dist/crypto/internal/chacha.d.ts +46 -0
  281. package/dist/crypto/internal/chacha.d.ts.map +1 -0
  282. package/dist/crypto/internal/chacha.js +885 -0
  283. package/dist/crypto/internal/chacha.js.map +1 -0
  284. package/dist/crypto/internal/der.d.ts +6 -0
  285. package/dist/crypto/internal/der.d.ts.map +1 -0
  286. package/dist/crypto/internal/der.js +86 -0
  287. package/dist/crypto/internal/der.js.map +1 -0
  288. package/dist/crypto/internal/digest.d.ts +2 -0
  289. package/dist/crypto/internal/digest.d.ts.map +1 -0
  290. package/dist/crypto/internal/digest.js +15 -0
  291. package/dist/crypto/internal/digest.js.map +1 -0
  292. package/dist/crypto/internal/key.d.ts +2 -0
  293. package/dist/crypto/internal/key.d.ts.map +1 -0
  294. package/dist/crypto/internal/key.js +171 -0
  295. package/dist/crypto/internal/key.js.map +1 -0
  296. package/dist/crypto/internal/md5.d.ts +39 -0
  297. package/dist/crypto/internal/md5.d.ts.map +1 -0
  298. package/dist/crypto/internal/md5.js +179 -0
  299. package/dist/crypto/internal/md5.js.map +1 -0
  300. package/dist/crypto/internal/webCrypto.d.ts +2 -0
  301. package/dist/crypto/internal/webCrypto.d.ts.map +1 -0
  302. package/dist/crypto/internal/webCrypto.js +111 -0
  303. package/dist/crypto/internal/webCrypto.js.map +1 -0
  304. package/dist/encoding/Base64Url.d.ts.map +1 -1
  305. package/dist/encoding/Base64Url.js +29 -5
  306. package/dist/encoding/Base64Url.js.map +1 -1
  307. package/dist/encoding/Csv.d.ts +608 -0
  308. package/dist/encoding/Csv.d.ts.map +1 -0
  309. package/dist/encoding/Csv.js +718 -0
  310. package/dist/encoding/Csv.js.map +1 -0
  311. package/dist/encoding/Hex.d.ts +3 -2
  312. package/dist/encoding/Hex.d.ts.map +1 -1
  313. package/dist/encoding/Hex.js +3 -2
  314. package/dist/encoding/Hex.js.map +1 -1
  315. package/dist/encoding/Ndjson.d.ts +5 -4
  316. package/dist/encoding/Ndjson.d.ts.map +1 -1
  317. package/dist/encoding/Ndjson.js +6 -5
  318. package/dist/encoding/Ndjson.js.map +1 -1
  319. package/dist/encoding/SchemaBinary.d.ts.map +1 -1
  320. package/dist/encoding/SchemaBinary.js +42 -4
  321. package/dist/encoding/SchemaBinary.js.map +1 -1
  322. package/dist/encoding/Sse.d.ts +3 -1
  323. package/dist/encoding/Sse.d.ts.map +1 -1
  324. package/dist/encoding/Sse.js +5 -3
  325. package/dist/encoding/Sse.js.map +1 -1
  326. package/dist/encoding/Toml.d.ts +17 -3
  327. package/dist/encoding/Toml.d.ts.map +1 -1
  328. package/dist/encoding/Toml.js +104 -16
  329. package/dist/encoding/Toml.js.map +1 -1
  330. package/dist/encoding/Yaml.d.ts +8 -1
  331. package/dist/encoding/Yaml.d.ts.map +1 -1
  332. package/dist/encoding/Yaml.js +54 -18
  333. package/dist/encoding/Yaml.js.map +1 -1
  334. package/dist/encoding/index.d.ts +5 -0
  335. package/dist/encoding/index.d.ts.map +1 -1
  336. package/dist/encoding/index.js +5 -0
  337. package/dist/encoding/index.js.map +1 -1
  338. package/dist/eventlog/EventJournal.d.ts.map +1 -1
  339. package/dist/eventlog/EventJournal.js +6 -3
  340. package/dist/eventlog/EventJournal.js.map +1 -1
  341. package/dist/eventlog/EventLog.d.ts +126 -4
  342. package/dist/eventlog/EventLog.d.ts.map +1 -1
  343. package/dist/eventlog/EventLog.js +207 -12
  344. package/dist/eventlog/EventLog.js.map +1 -1
  345. package/dist/eventlog/EventLogEncryption.d.ts +41 -4
  346. package/dist/eventlog/EventLogEncryption.d.ts.map +1 -1
  347. package/dist/eventlog/EventLogEncryption.js +83 -64
  348. package/dist/eventlog/EventLogEncryption.js.map +1 -1
  349. package/dist/eventlog/EventLogMessage.d.ts +279 -0
  350. package/dist/eventlog/EventLogMessage.d.ts.map +1 -1
  351. package/dist/eventlog/EventLogMessage.js +217 -1
  352. package/dist/eventlog/EventLogMessage.js.map +1 -1
  353. package/dist/eventlog/EventLogRemote.d.ts +200 -28
  354. package/dist/eventlog/EventLogRemote.d.ts.map +1 -1
  355. package/dist/eventlog/EventLogRemote.js +186 -16
  356. package/dist/eventlog/EventLogRemote.js.map +1 -1
  357. package/dist/eventlog/EventLogServer.d.ts +10 -1
  358. package/dist/eventlog/EventLogServer.d.ts.map +1 -1
  359. package/dist/eventlog/EventLogServer.js +45 -22
  360. package/dist/eventlog/EventLogServer.js.map +1 -1
  361. package/dist/eventlog/EventLogServerEncrypted.d.ts +336 -5
  362. package/dist/eventlog/EventLogServerEncrypted.d.ts.map +1 -1
  363. package/dist/eventlog/EventLogServerEncrypted.js +769 -14
  364. package/dist/eventlog/EventLogServerEncrypted.js.map +1 -1
  365. package/dist/eventlog/EventLogServerUnencrypted.d.ts +17 -0
  366. package/dist/eventlog/EventLogServerUnencrypted.d.ts.map +1 -1
  367. package/dist/eventlog/EventLogServerUnencrypted.js +14 -2
  368. package/dist/eventlog/EventLogServerUnencrypted.js.map +1 -1
  369. package/dist/eventlog/EventLogSessionAuth.d.ts +26 -3
  370. package/dist/eventlog/EventLogSessionAuth.d.ts.map +1 -1
  371. package/dist/eventlog/EventLogSessionAuth.js +63 -64
  372. package/dist/eventlog/EventLogSessionAuth.js.map +1 -1
  373. package/dist/eventlog/EventRow.d.ts +4 -0
  374. package/dist/eventlog/EventRow.d.ts.map +1 -1
  375. package/dist/eventlog/EventRow.js +12 -2
  376. package/dist/eventlog/EventRow.js.map +1 -1
  377. package/dist/eventlog/SqlEventJournal.js +2 -2
  378. package/dist/eventlog/SqlEventJournal.js.map +1 -1
  379. package/dist/eventlog/SqlEventLogServerEncrypted.d.ts +21 -5
  380. package/dist/eventlog/SqlEventLogServerEncrypted.d.ts.map +1 -1
  381. package/dist/eventlog/SqlEventLogServerEncrypted.js +1048 -113
  382. package/dist/eventlog/SqlEventLogServerEncrypted.js.map +1 -1
  383. package/dist/eventlog/SqlEventLogServerUnencrypted.js +2 -2
  384. package/dist/eventlog/SqlEventLogServerUnencrypted.js.map +1 -1
  385. package/dist/eventlog/internal/batches.d.ts +12 -0
  386. package/dist/eventlog/internal/batches.d.ts.map +1 -0
  387. package/dist/eventlog/internal/batches.js +26 -0
  388. package/dist/eventlog/internal/batches.js.map +1 -0
  389. package/dist/eventlog/internal/compaction.d.ts +38 -0
  390. package/dist/eventlog/internal/compaction.d.ts.map +1 -0
  391. package/dist/eventlog/internal/compaction.js +33 -0
  392. package/dist/eventlog/internal/compaction.js.map +1 -0
  393. package/dist/eventlog/internal/identityRootSecretDerivation.js +66 -67
  394. package/dist/eventlog/internal/identityRootSecretDerivation.js.map +1 -1
  395. package/dist/eventlog/internal/remoteCompaction.d.ts +31 -0
  396. package/dist/eventlog/internal/remoteCompaction.d.ts.map +1 -0
  397. package/dist/eventlog/internal/remoteCompaction.js +76 -0
  398. package/dist/eventlog/internal/remoteCompaction.js.map +1 -0
  399. package/dist/graphql/GraphQLClient.d.ts +3 -1
  400. package/dist/graphql/GraphQLClient.d.ts.map +1 -1
  401. package/dist/graphql/GraphQLClient.js.map +1 -1
  402. package/dist/graphql/GraphQLClientError.d.ts +14 -9
  403. package/dist/graphql/GraphQLClientError.d.ts.map +1 -1
  404. package/dist/graphql/GraphQLClientError.js +14 -21
  405. package/dist/graphql/GraphQLClientError.js.map +1 -1
  406. package/dist/graphql/GraphQLProtocol.d.ts +12 -3
  407. package/dist/graphql/GraphQLProtocol.d.ts.map +1 -1
  408. package/dist/graphql/GraphQLProtocol.js +4 -1
  409. package/dist/graphql/GraphQLProtocol.js.map +1 -1
  410. package/dist/http/Cookies.d.ts +172 -0
  411. package/dist/http/Cookies.d.ts.map +1 -1
  412. package/dist/http/Cookies.js +143 -1
  413. package/dist/http/Cookies.js.map +1 -1
  414. package/dist/http/FetchHttpClient.d.ts +26 -2
  415. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  416. package/dist/http/FetchHttpClient.js +78 -15
  417. package/dist/http/FetchHttpClient.js.map +1 -1
  418. package/dist/http/HttpClient.d.ts +268 -15
  419. package/dist/http/HttpClient.d.ts.map +1 -1
  420. package/dist/http/HttpClient.js +140 -7
  421. package/dist/http/HttpClient.js.map +1 -1
  422. package/dist/http/HttpClientRequest.d.ts +9 -5
  423. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  424. package/dist/http/HttpClientRequest.js +2 -3
  425. package/dist/http/HttpClientRequest.js.map +1 -1
  426. package/dist/http/HttpClientResponse.d.ts.map +1 -1
  427. package/dist/http/HttpClientResponse.js +3 -2
  428. package/dist/http/HttpClientResponse.js.map +1 -1
  429. package/dist/http/HttpMethod.d.ts +7 -1
  430. package/dist/http/HttpMethod.d.ts.map +1 -1
  431. package/dist/http/HttpMethod.js +3 -8
  432. package/dist/http/HttpMethod.js.map +1 -1
  433. package/dist/http/HttpServerRequest.d.ts +5 -2
  434. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  435. package/dist/http/HttpServerRequest.js +44 -39
  436. package/dist/http/HttpServerRequest.js.map +1 -1
  437. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  438. package/dist/http/HttpServerResponse.js +3 -2
  439. package/dist/http/HttpServerResponse.js.map +1 -1
  440. package/dist/http/HttpTraceContext.d.ts +2 -1
  441. package/dist/http/HttpTraceContext.d.ts.map +1 -1
  442. package/dist/http/HttpTraceContext.js +7 -5
  443. package/dist/http/HttpTraceContext.js.map +1 -1
  444. package/dist/http/ProblemDetails.d.ts +96 -0
  445. package/dist/http/ProblemDetails.d.ts.map +1 -0
  446. package/dist/http/ProblemDetails.js +98 -0
  447. package/dist/http/ProblemDetails.js.map +1 -0
  448. package/dist/http/index.d.ts +5 -0
  449. package/dist/http/index.d.ts.map +1 -1
  450. package/dist/http/index.js +5 -0
  451. package/dist/http/index.js.map +1 -1
  452. package/dist/http/internal/decompression.js +3 -2
  453. package/dist/http/internal/decompression.js.map +1 -1
  454. package/dist/http/internal/mimeTypes.d.ts +4 -1
  455. package/dist/http/internal/mimeTypes.d.ts.map +1 -1
  456. package/dist/http/internal/mimeTypes.js +4 -1
  457. package/dist/http/internal/mimeTypes.js.map +1 -1
  458. package/dist/http/internal/urlParams.js +8 -0
  459. package/dist/http/internal/urlParams.js.map +1 -1
  460. package/dist/http-api/HttpApiBuilder.js +19 -5
  461. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  462. package/dist/http-api/HttpApiClient.d.ts +63 -0
  463. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  464. package/dist/http-api/HttpApiClient.js +51 -0
  465. package/dist/http-api/HttpApiClient.js.map +1 -1
  466. package/dist/http-api/HttpApiEndpoint.d.ts.map +1 -1
  467. package/dist/http-api/HttpApiEndpoint.js +14 -5
  468. package/dist/http-api/HttpApiEndpoint.js.map +1 -1
  469. package/dist/http-api/HttpApiError.d.ts +185 -13
  470. package/dist/http-api/HttpApiError.d.ts.map +1 -1
  471. package/dist/http-api/HttpApiError.js +128 -0
  472. package/dist/http-api/HttpApiError.js.map +1 -1
  473. package/dist/http-api/HttpApiMiddleware.d.ts +64 -17
  474. package/dist/http-api/HttpApiMiddleware.d.ts.map +1 -1
  475. package/dist/http-api/HttpApiMiddleware.js +85 -1
  476. package/dist/http-api/HttpApiMiddleware.js.map +1 -1
  477. package/dist/http-api/HttpApiSchema.d.ts +76 -14
  478. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  479. package/dist/http-api/HttpApiSchema.js +54 -1
  480. package/dist/http-api/HttpApiSchema.js.map +1 -1
  481. package/dist/index.d.ts +5 -5
  482. package/dist/index.d.ts.map +1 -1
  483. package/dist/index.js +5 -5
  484. package/dist/index.js.map +1 -1
  485. package/dist/internal/dateTime.js +49 -24
  486. package/dist/internal/dateTime.js.map +1 -1
  487. package/dist/internal/effect.js +35 -14
  488. package/dist/internal/effect.js.map +1 -1
  489. package/dist/internal/glob.d.ts +2 -0
  490. package/dist/internal/glob.d.ts.map +1 -0
  491. package/dist/internal/glob.js +808 -0
  492. package/dist/internal/glob.js.map +1 -0
  493. package/dist/internal/graphql.js +21 -7
  494. package/dist/internal/graphql.js.map +1 -1
  495. package/dist/internal/graphqlHeaders.d.ts +7 -0
  496. package/dist/internal/graphqlHeaders.d.ts.map +1 -1
  497. package/dist/internal/graphqlHeaders.js +11 -0
  498. package/dist/internal/graphqlHeaders.js.map +1 -1
  499. package/dist/internal/matcher.js +10 -0
  500. package/dist/internal/matcher.js.map +1 -1
  501. package/dist/internal/persistence.js +9 -0
  502. package/dist/internal/persistence.js.map +1 -1
  503. package/dist/internal/rcRef.js +4 -1
  504. package/dist/internal/rcRef.js.map +1 -1
  505. package/dist/internal/request.js +29 -42
  506. package/dist/internal/request.js.map +1 -1
  507. package/dist/internal/schema/fromJsonSchemaDocument.js +7 -8
  508. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  509. package/dist/internal/schema/toCodeDocument.js +6 -3
  510. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  511. package/dist/internal/trie.js +42 -13
  512. package/dist/internal/trie.js.map +1 -1
  513. package/dist/internal/ulid.js +41 -0
  514. package/dist/internal/ulid.js.map +1 -1
  515. package/dist/internal/uuid.js +52 -8
  516. package/dist/internal/uuid.js.map +1 -1
  517. package/dist/internal/version.js +1 -1
  518. package/dist/jose/JoseError.d.ts +285 -0
  519. package/dist/jose/JoseError.d.ts.map +1 -0
  520. package/dist/jose/JoseError.js +269 -0
  521. package/dist/jose/JoseError.js.map +1 -0
  522. package/dist/jose/Jwe.d.ts +128 -0
  523. package/dist/jose/Jwe.d.ts.map +1 -0
  524. package/dist/jose/Jwe.js +134 -0
  525. package/dist/jose/Jwe.js.map +1 -0
  526. package/dist/jose/Jwk.d.ts +597 -0
  527. package/dist/jose/Jwk.d.ts.map +1 -0
  528. package/dist/jose/Jwk.js +503 -0
  529. package/dist/jose/Jwk.js.map +1 -0
  530. package/dist/jose/Jwks.d.ts +236 -0
  531. package/dist/jose/Jwks.d.ts.map +1 -0
  532. package/dist/jose/Jwks.js +306 -0
  533. package/dist/jose/Jwks.js.map +1 -0
  534. package/dist/jose/Jws.d.ts +177 -0
  535. package/dist/jose/Jws.d.ts.map +1 -0
  536. package/dist/jose/Jws.js +183 -0
  537. package/dist/jose/Jws.js.map +1 -0
  538. package/dist/jose/Jwt.d.ts +270 -0
  539. package/dist/jose/Jwt.d.ts.map +1 -0
  540. package/dist/jose/Jwt.js +293 -0
  541. package/dist/jose/Jwt.js.map +1 -0
  542. package/dist/jose/index.d.ts +51 -0
  543. package/dist/jose/index.d.ts.map +1 -0
  544. package/dist/jose/index.js +52 -0
  545. package/dist/jose/index.js.map +1 -0
  546. package/dist/jose/internal/compact.d.ts +2 -0
  547. package/dist/jose/internal/compact.d.ts.map +1 -0
  548. package/dist/jose/internal/compact.js +179 -0
  549. package/dist/jose/internal/compact.js.map +1 -0
  550. package/dist/net/Host.d.ts.map +1 -1
  551. package/dist/net/Host.js +5 -10
  552. package/dist/net/Host.js.map +1 -1
  553. package/dist/observability/Otlp.d.ts +15 -4
  554. package/dist/observability/Otlp.d.ts.map +1 -1
  555. package/dist/observability/Otlp.js +10 -0
  556. package/dist/observability/Otlp.js.map +1 -1
  557. package/dist/observability/OtlpResource.d.ts +7 -0
  558. package/dist/observability/OtlpResource.d.ts.map +1 -1
  559. package/dist/observability/OtlpResource.js +11 -1
  560. package/dist/observability/OtlpResource.js.map +1 -1
  561. package/dist/observability/OtlpSerialization.d.ts +1 -1
  562. package/dist/observability/OtlpSerialization.d.ts.map +1 -1
  563. package/dist/observability/OtlpSerialization.js +10 -4
  564. package/dist/observability/OtlpSerialization.js.map +1 -1
  565. package/dist/observability/internal/otlpProtobuf.js +3 -3
  566. package/dist/observability/internal/otlpProtobuf.js.map +1 -1
  567. package/dist/observability/internal/protobuf.js +6 -0
  568. package/dist/observability/internal/protobuf.js.map +1 -1
  569. package/dist/persistence/CircuitBreaker.d.ts +98 -38
  570. package/dist/persistence/CircuitBreaker.d.ts.map +1 -1
  571. package/dist/persistence/CircuitBreaker.js +67 -29
  572. package/dist/persistence/CircuitBreaker.js.map +1 -1
  573. package/dist/persistence/KeyValueStore.d.ts +47 -2
  574. package/dist/persistence/KeyValueStore.d.ts.map +1 -1
  575. package/dist/persistence/KeyValueStore.js +129 -18
  576. package/dist/persistence/KeyValueStore.js.map +1 -1
  577. package/dist/persistence/PersistedQueue.d.ts +9 -0
  578. package/dist/persistence/PersistedQueue.d.ts.map +1 -1
  579. package/dist/persistence/PersistedQueue.js +94 -52
  580. package/dist/persistence/PersistedQueue.js.map +1 -1
  581. package/dist/persistence/Persistence.d.ts +10 -4
  582. package/dist/persistence/Persistence.d.ts.map +1 -1
  583. package/dist/persistence/Persistence.js +18 -11
  584. package/dist/persistence/Persistence.js.map +1 -1
  585. package/dist/persistence/RateLimiter.d.ts +8 -0
  586. package/dist/persistence/RateLimiter.d.ts.map +1 -1
  587. package/dist/persistence/RateLimiter.js +63 -12
  588. package/dist/persistence/RateLimiter.js.map +1 -1
  589. package/dist/persistence/index.d.ts +1 -1
  590. package/dist/persistence/index.js +1 -1
  591. package/dist/process/ChildProcess.d.ts +207 -67
  592. package/dist/process/ChildProcess.d.ts.map +1 -1
  593. package/dist/process/ChildProcess.js +56 -158
  594. package/dist/process/ChildProcess.js.map +1 -1
  595. package/dist/process/ChildProcessSpawner.d.ts +5 -0
  596. package/dist/process/ChildProcessSpawner.d.ts.map +1 -1
  597. package/dist/process/ChildProcessSpawner.js.map +1 -1
  598. package/dist/process/CommandLine.d.ts +294 -0
  599. package/dist/process/CommandLine.d.ts.map +1 -0
  600. package/dist/process/CommandLine.js +481 -0
  601. package/dist/process/CommandLine.js.map +1 -0
  602. package/dist/process/index.d.ts +5 -0
  603. package/dist/process/index.d.ts.map +1 -1
  604. package/dist/process/index.js +5 -0
  605. package/dist/process/index.js.map +1 -1
  606. package/dist/reactivity/Atom.d.ts +2 -1
  607. package/dist/reactivity/Atom.d.ts.map +1 -1
  608. package/dist/reactivity/Atom.js +3 -4
  609. package/dist/reactivity/Atom.js.map +1 -1
  610. package/dist/reactivity/AtomRegistry.js +17 -7
  611. package/dist/reactivity/AtomRegistry.js.map +1 -1
  612. package/dist/rpc/Rpc.d.ts +1 -1
  613. package/dist/rpc/Rpc.d.ts.map +1 -1
  614. package/dist/rpc/Rpc.js.map +1 -1
  615. package/dist/rpc/RpcClient.d.ts +28 -1
  616. package/dist/rpc/RpcClient.d.ts.map +1 -1
  617. package/dist/rpc/RpcClient.js +78 -27
  618. package/dist/rpc/RpcClient.js.map +1 -1
  619. package/dist/rpc/RpcMessage.d.ts +13 -3
  620. package/dist/rpc/RpcMessage.d.ts.map +1 -1
  621. package/dist/rpc/RpcMessage.js +1 -0
  622. package/dist/rpc/RpcMessage.js.map +1 -1
  623. package/dist/rpc/RpcSerialization.d.ts.map +1 -1
  624. package/dist/rpc/RpcSerialization.js +6 -0
  625. package/dist/rpc/RpcSerialization.js.map +1 -1
  626. package/dist/rpc/RpcServer.d.ts +31 -0
  627. package/dist/rpc/RpcServer.d.ts.map +1 -1
  628. package/dist/rpc/RpcServer.js +139 -66
  629. package/dist/rpc/RpcServer.js.map +1 -1
  630. package/dist/schema/Model.d.ts +14 -0
  631. package/dist/schema/Model.d.ts.map +1 -1
  632. package/dist/schema/Model.js +18 -3
  633. package/dist/schema/Model.js.map +1 -1
  634. package/dist/sql/Migrator.d.ts +9 -20
  635. package/dist/sql/Migrator.d.ts.map +1 -1
  636. package/dist/sql/Migrator.js +20 -53
  637. package/dist/sql/Migrator.js.map +1 -1
  638. package/dist/sql/MigratorFileSystem.d.ts +21 -0
  639. package/dist/sql/MigratorFileSystem.d.ts.map +1 -0
  640. package/dist/sql/MigratorFileSystem.js +57 -0
  641. package/dist/sql/MigratorFileSystem.js.map +1 -0
  642. package/dist/sql/SqlClient.d.ts +38 -3
  643. package/dist/sql/SqlClient.d.ts.map +1 -1
  644. package/dist/sql/SqlClient.js +9 -12
  645. package/dist/sql/SqlClient.js.map +1 -1
  646. package/dist/sql/Statement.d.ts +61 -9
  647. package/dist/sql/Statement.d.ts.map +1 -1
  648. package/dist/sql/Statement.js +24 -33
  649. package/dist/sql/Statement.js.map +1 -1
  650. package/dist/sql/index.js +1 -1
  651. package/dist/testing/index.d.ts +0 -5
  652. package/dist/testing/index.d.ts.map +1 -1
  653. package/dist/testing/index.js +0 -5
  654. package/dist/testing/index.js.map +1 -1
  655. package/dist/workflow/Workflow.d.ts +4 -0
  656. package/dist/workflow/Workflow.d.ts.map +1 -1
  657. package/dist/workflow/Workflow.js.map +1 -1
  658. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  659. package/dist/workflow/WorkflowEngine.js +5 -0
  660. package/dist/workflow/WorkflowEngine.js.map +1 -1
  661. package/dist/workflow/internal/crypto.js +9 -8
  662. package/dist/workflow/internal/crypto.js.map +1 -1
  663. package/package.json +7 -1
  664. package/src/BigDecimal.ts +173 -16
  665. package/src/Channel.ts +17 -11
  666. package/src/Config.ts +7 -1
  667. package/src/Context.ts +34 -10
  668. package/src/Cron.ts +178 -29
  669. package/src/Duration.ts +140 -0
  670. package/src/Effect.ts +914 -85
  671. package/src/Equal.ts +3 -3
  672. package/src/FileSystem.ts +65 -4
  673. package/src/Glob.ts +205 -0
  674. package/src/Hash.ts +5 -4
  675. package/src/Iterable.ts +8 -5
  676. package/src/Match.ts +127 -0
  677. package/src/Path.ts +6 -1
  678. package/src/Pool.ts +75 -16
  679. package/src/Random.ts +3 -3
  680. package/src/RcMap.ts +5 -1
  681. package/src/Schedule.ts +26 -3
  682. package/src/Schema.ts +1191 -63
  683. package/src/SchemaGetter.ts +27 -11
  684. package/src/SchemaRepresentation.ts +23 -2
  685. package/src/SchemaTransformation.ts +10 -5
  686. package/src/ScopedCache.ts +5 -9
  687. package/src/Semaphore.ts +141 -0
  688. package/src/Stream.ts +15 -6
  689. package/src/Terminal.ts +19 -1
  690. package/src/ai/AiError.ts +56 -80
  691. package/src/ai/Decision.ts +257 -6
  692. package/src/ai/DecisionModel.ts +171 -28
  693. package/src/ai/McpClient.ts +488 -91
  694. package/src/ai/McpSchema.ts +119 -0
  695. package/src/ai/McpServer.ts +1525 -319
  696. package/src/ai/McpTest.ts +380 -0
  697. package/src/ai/Prompt.ts +16 -11
  698. package/src/ai/Response.ts +2 -22
  699. package/src/ai/Tool.ts +32 -18
  700. package/src/ai/index.ts +6 -0
  701. package/src/ai/internal/mcpCore.ts +243 -56
  702. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +7 -8
  703. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +7 -8
  704. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +7 -8
  705. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +7 -8
  706. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +56 -17
  707. package/src/ai/internal/mcpProtocol.ts +44 -0
  708. package/src/ai/internal/mcpRuntime.ts +15 -8
  709. package/src/ai/internal/mcpSkills.ts +480 -0
  710. package/src/ai/internal/mcpStatefulRuntime.ts +14 -2
  711. package/src/cli/Argument.ts +6 -0
  712. package/src/cli/CliOutput.ts +117 -49
  713. package/src/cli/Command.ts +23 -0
  714. package/src/cli/Flag.ts +107 -0
  715. package/src/cli/HelpDoc.ts +18 -1
  716. package/src/cli/Param.ts +6 -0
  717. package/src/cli/Primitive.ts +16 -1
  718. package/src/cli/Prompt.ts +1 -0
  719. package/src/cli/internal/help.ts +21 -9
  720. package/src/cluster/ClusterWorkflowEngine.ts +22 -8
  721. package/src/cluster/Reply.ts +1 -1
  722. package/src/cluster/Sharding.ts +96 -26
  723. package/src/cluster/ShardingConfig.ts +41 -3
  724. package/src/cluster/SingleRunner.ts +3 -3
  725. package/src/cluster/SqlMessageStorage.ts +49 -17
  726. package/src/cluster/SqlRunnerStorage.ts +37 -27
  727. package/src/cluster/internal/entityManager.ts +24 -10
  728. package/src/crypto/Aead.ts +517 -0
  729. package/src/crypto/Cipher.ts +326 -0
  730. package/src/crypto/CryptoError.ts +242 -0
  731. package/src/crypto/Digest.ts +167 -0
  732. package/src/crypto/Kdf.ts +315 -0
  733. package/src/crypto/KeyAgreement.ts +489 -0
  734. package/src/crypto/KeyFormat.ts +741 -0
  735. package/src/crypto/KeyWrap.ts +639 -0
  736. package/src/crypto/Mac.ts +386 -0
  737. package/src/crypto/SecureRandom.ts +459 -0
  738. package/src/crypto/Signature.ts +673 -0
  739. package/src/crypto/WebCrypto.ts +84 -0
  740. package/src/crypto/index.ts +78 -0
  741. package/src/crypto/internal/asymmetric.ts +330 -0
  742. package/src/crypto/internal/chacha.ts +1088 -0
  743. package/src/crypto/internal/der.ts +110 -0
  744. package/src/crypto/internal/digest.ts +16 -0
  745. package/src/crypto/internal/key.ts +242 -0
  746. package/src/crypto/internal/md5.ts +170 -0
  747. package/src/crypto/internal/webCrypto.ts +150 -0
  748. package/src/encoding/Base64Url.ts +32 -5
  749. package/src/encoding/Csv.ts +1298 -0
  750. package/src/encoding/Hex.ts +3 -2
  751. package/src/encoding/Ndjson.ts +6 -5
  752. package/src/encoding/SchemaBinary.ts +40 -4
  753. package/src/encoding/Sse.ts +5 -3
  754. package/src/encoding/Toml.ts +85 -20
  755. package/src/encoding/Yaml.ts +61 -18
  756. package/src/encoding/index.ts +6 -0
  757. package/src/eventlog/EventJournal.ts +4 -3
  758. package/src/eventlog/EventLog.ts +347 -15
  759. package/src/eventlog/EventLogEncryption.ts +118 -110
  760. package/src/eventlog/EventLogMessage.ts +273 -1
  761. package/src/eventlog/EventLogRemote.ts +367 -23
  762. package/src/eventlog/EventLogServer.ts +54 -20
  763. package/src/eventlog/EventLogServerEncrypted.ts +1135 -67
  764. package/src/eventlog/EventLogServerUnencrypted.ts +19 -2
  765. package/src/eventlog/EventLogSessionAuth.ts +82 -70
  766. package/src/eventlog/EventRow.ts +12 -3
  767. package/src/eventlog/SqlEventJournal.ts +2 -2
  768. package/src/eventlog/SqlEventLogServerEncrypted.ts +1244 -136
  769. package/src/eventlog/SqlEventLogServerUnencrypted.ts +2 -2
  770. package/src/eventlog/internal/batches.ts +30 -0
  771. package/src/eventlog/internal/compaction.ts +64 -0
  772. package/src/eventlog/internal/identityRootSecretDerivation.ts +93 -123
  773. package/src/eventlog/internal/remoteCompaction.ts +92 -0
  774. package/src/graphql/GraphQLClient.ts +3 -1
  775. package/src/graphql/GraphQLClientError.ts +15 -22
  776. package/src/graphql/GraphQLProtocol.ts +12 -3
  777. package/src/http/Cookies.ts +281 -1
  778. package/src/http/FetchHttpClient.ts +88 -16
  779. package/src/http/HttpClient.ts +299 -33
  780. package/src/http/HttpClientRequest.ts +12 -9
  781. package/src/http/HttpClientResponse.ts +3 -2
  782. package/src/http/HttpMethod.ts +10 -2
  783. package/src/http/HttpServerRequest.ts +76 -53
  784. package/src/http/HttpServerResponse.ts +3 -2
  785. package/src/http/HttpTraceContext.ts +7 -4
  786. package/src/http/ProblemDetails.ts +149 -0
  787. package/src/http/index.ts +6 -0
  788. package/src/http/internal/decompression.ts +4 -4
  789. package/src/http/internal/mimeTypes.ts +4 -1
  790. package/src/http/internal/urlParams.ts +8 -0
  791. package/src/http-api/HttpApiBuilder.ts +24 -12
  792. package/src/http-api/HttpApiClient.ts +67 -1
  793. package/src/http-api/HttpApiEndpoint.ts +14 -5
  794. package/src/http-api/HttpApiError.ts +250 -0
  795. package/src/http-api/HttpApiMiddleware.ts +95 -1
  796. package/src/http-api/HttpApiSchema.ts +106 -15
  797. package/src/index.ts +6 -6
  798. package/src/internal/dateTime.ts +54 -24
  799. package/src/internal/effect.ts +40 -18
  800. package/src/internal/glob.ts +952 -0
  801. package/src/internal/graphql.ts +27 -9
  802. package/src/internal/graphqlHeaders.ts +13 -0
  803. package/src/internal/matcher.ts +17 -0
  804. package/src/internal/persistence.ts +11 -0
  805. package/src/internal/rcRef.ts +4 -1
  806. package/src/internal/request.ts +51 -58
  807. package/src/internal/schema/fromJsonSchemaDocument.ts +11 -10
  808. package/src/internal/schema/toCodeDocument.ts +7 -3
  809. package/src/internal/trie.ts +43 -14
  810. package/src/internal/ulid.ts +44 -0
  811. package/src/internal/uuid.ts +57 -16
  812. package/src/internal/version.ts +1 -1
  813. package/src/jose/JoseError.ts +329 -0
  814. package/src/jose/Jwe.ts +196 -0
  815. package/src/jose/Jwk.ts +777 -0
  816. package/src/jose/Jwks.ts +418 -0
  817. package/src/jose/Jws.ts +312 -0
  818. package/src/jose/Jwt.ts +493 -0
  819. package/src/jose/index.ts +58 -0
  820. package/src/jose/internal/compact.ts +195 -0
  821. package/src/net/Host.ts +5 -10
  822. package/src/observability/Otlp.ts +21 -4
  823. package/src/observability/OtlpResource.ts +9 -1
  824. package/src/observability/OtlpSerialization.ts +13 -5
  825. package/src/observability/internal/otlpProtobuf.ts +6 -6
  826. package/src/observability/internal/protobuf.ts +10 -0
  827. package/src/persistence/CircuitBreaker.ts +113 -48
  828. package/src/persistence/KeyValueStore.ts +219 -22
  829. package/src/persistence/PersistedQueue.ts +128 -59
  830. package/src/persistence/Persistence.ts +20 -13
  831. package/src/persistence/RateLimiter.ts +84 -15
  832. package/src/persistence/index.ts +1 -1
  833. package/src/process/ChildProcess.ts +255 -260
  834. package/src/process/ChildProcessSpawner.ts +5 -0
  835. package/src/process/CommandLine.ts +630 -0
  836. package/src/process/index.ts +6 -0
  837. package/src/reactivity/Atom.ts +5 -5
  838. package/src/reactivity/AtomRegistry.ts +20 -9
  839. package/src/rpc/Rpc.ts +3 -1
  840. package/src/rpc/RpcClient.ts +94 -38
  841. package/src/rpc/RpcMessage.ts +13 -3
  842. package/src/rpc/RpcSerialization.ts +3 -0
  843. package/src/rpc/RpcServer.ts +176 -78
  844. package/src/schema/Model.ts +26 -3
  845. package/src/sql/Migrator.ts +38 -80
  846. package/src/sql/MigratorFileSystem.ts +71 -0
  847. package/src/sql/SqlClient.ts +45 -24
  848. package/src/sql/Statement.ts +60 -29
  849. package/src/sql/index.ts +1 -1
  850. package/src/testing/index.ts +0 -6
  851. package/src/workflow/Workflow.ts +4 -0
  852. package/src/workflow/WorkflowEngine.ts +5 -0
  853. package/src/workflow/internal/crypto.ts +15 -11
  854. package/dist/Crypto.d.ts +0 -244
  855. package/dist/Crypto.d.ts.map +0 -1
  856. package/dist/Crypto.js +0 -139
  857. package/dist/Crypto.js.map +0 -1
  858. package/dist/testing/TestCrypto.d.ts +0 -73
  859. package/dist/testing/TestCrypto.d.ts.map +0 -1
  860. package/dist/testing/TestCrypto.js +0 -87
  861. package/dist/testing/TestCrypto.js.map +0 -1
  862. package/src/Crypto.ts +0 -347
  863. package/src/testing/TestCrypto.ts +0 -94
@@ -14,8 +14,10 @@
14
14
  import * as Arr from "../Array.js";
15
15
  import * as Cause from "../Cause.js";
16
16
  import * as Context from "../Context.js";
17
+ import * as Digest from "../crypto/Digest.js";
17
18
  import * as Data from "../Data.js";
18
19
  import * as Deferred from "../Deferred.js";
20
+ import * as Duration from "../Duration.js";
19
21
  import * as Effect from "../Effect.js";
20
22
  import * as ErrorReporter from "../ErrorReporter.js";
21
23
  import * as Exit from "../Exit.js";
@@ -43,10 +45,12 @@ import * as Schema from "../Schema.js";
43
45
  import * as SchemaAST from "../SchemaAST.js";
44
46
  import * as Scope from "../Scope.js";
45
47
  import * as Stream from "../Stream.js";
48
+ import * as Tracer from "../Tracer.js";
46
49
  import * as AiError from "./AiError.js";
47
50
  import * as McpCore from "./internal/mcpCore.js";
48
51
  import * as McpProtocolInternal from "./internal/mcpProtocol.js";
49
52
  import * as McpRuntime from "./internal/mcpRuntime.js";
53
+ import * as McpSkills from "./internal/mcpSkills.js";
50
54
  import * as InternalStructuredOutput from "./internal/structured-output.js";
51
55
  import * as McpSchema from "./McpSchema.js";
52
56
  import { CallToolResult, ElicitationDeclined, EnabledWhen, GetPromptResult, InternalError, InvalidParams, InvalidRequest, isParam, McpRequestContext, McpServerClient, McpServerClientMiddleware, MethodNotFound, Prompt, Resource, ResourceTemplate, ServerNotificationRpcs, TextContent, Tool as McpTool, ToolJson } from "./McpSchema.js";
@@ -106,8 +110,18 @@ const toInternalServerNotification = message => {
106
110
  return undefined;
107
111
  }
108
112
  };
109
- // Request services must come from the invocation, including when a handler is registered during a request.
110
- const omitRequestServices = /*#__PURE__*/Context.omit(McpRequestContext, McpServerClient, HttpServerRequest.HttpServerRequest, CurrentLogLevel);
113
+ const middlewareKeyPrefix = "effect/ai/McpServer/Middleware-";
114
+ // Do not capture request services or middleware stacks at registration.
115
+ const requestServiceKeys = /*#__PURE__*/new Set([McpRequestContext.key, McpServerClient.key, HttpServerRequest.HttpServerRequest.key, HttpServerRequest.ParsedSearchParams.key, HttpRouter.RouteContext.key, CurrentLogLevel.key, Scope.Scope.key, Tracer.ParentSpan.key]);
116
+ const omitRequestServices = context => {
117
+ const services = new Map();
118
+ for (const [key, value] of context.mapUnsafe) {
119
+ if (!requestServiceKeys.has(key) && !key.startsWith(middlewareKeyPrefix)) {
120
+ services.set(key, value);
121
+ }
122
+ }
123
+ return Context.makeUnsafe(services);
124
+ };
111
125
  const provideInvocationContext = (effect, invocation) => {
112
126
  let provided = Effect.provideService(effect, McpRequestContext, invocation.requestContext);
113
127
  const requestMetadata = invocation.requestContext.requestMetadata;
@@ -117,6 +131,333 @@ const provideInvocationContext = (effect, invocation) => {
117
131
  }
118
132
  return invocation.serverClient === undefined ? provided : Effect.provideService(provided, McpServerClient, invocation.serverClient);
119
133
  };
134
+ const MiddlewareTypeId = "~effect/ai/McpServer/Middleware";
135
+ /**
136
+ * Creates MCP middleware that runs around `tools/call`, `resources/read`,
137
+ * `prompts/get` and `completion/complete` requests.
138
+ *
139
+ * **Details**
140
+ *
141
+ * Middleware is how request-level dependencies are satisfied: declare the
142
+ * services it provides with `middleware<{ provides: S }>()` and provide them to
143
+ * the handler effect. It receives the request headers, session id and request
144
+ * context, so it can resolve the current user per request.
145
+ *
146
+ * Pass a function, or an Effect that builds the function. Services the Effect
147
+ * reads are requirements of the middleware layer. Services the function reads
148
+ * per request, other than `McpRequestContext`, are per-request requirements
149
+ * of the result; see {@link Middleware} for how they are met.
150
+ *
151
+ * Failures must be `McpErrorBase` values. A middleware failure is sent as a
152
+ * JSON-RPC error with its `code`, `message` and `data`, never as a tool
153
+ * result. Pick custom codes from the implementation-defined range
154
+ * (-32000 to -32019): any numeric `code` is sent as is. Defects are logged,
155
+ * reported to the `ErrorReporter` and sent as `InternalError("Internal error")`.
156
+ * Interruption propagates.
157
+ *
158
+ * Local middleware runs inside global middleware, and middleware provided both
159
+ * locally and globally runs once. Middleware never runs for `initialize`. It
160
+ * runs for list requests only when it wraps a {@link visibility}, so that the
161
+ * visibility check can read the services it provides.
162
+ *
163
+ * **Example** (Resolving the current user per request)
164
+ *
165
+ * ```ts
166
+ * import { Context, Effect, Layer, Schema } from "effect"
167
+ * import { McpSchema, McpServer, Tool, Toolkit } from "effect/ai"
168
+ *
169
+ * class CurrentUser extends Context.Service<CurrentUser, { readonly id: string }>()("CurrentUser") {}
170
+ *
171
+ * class Unauthorized extends Schema.Error<Unauthorized>("Unauthorized")({
172
+ * ...McpSchema.McpErrorBase.fields,
173
+ * _tag: Schema.tag("Unauthorized"),
174
+ * code: Schema.tag(-32001)
175
+ * }) {}
176
+ *
177
+ * const WhoAmI = Tool.make("WhoAmI", { success: Schema.String, dependencies: [CurrentUser] })
178
+ * const Tools = Toolkit.make(WhoAmI)
179
+ *
180
+ * const Auth = McpServer.middleware<{ provides: CurrentUser }>()((effect, { headers }) => {
181
+ * const token = headers["authorization"]
182
+ * return token === undefined
183
+ * ? Effect.fail(new Unauthorized({ message: "Missing credentials" }))
184
+ * : Effect.provideService(effect, CurrentUser, { id: token })
185
+ * })
186
+ *
187
+ * const Registrations = McpServer.toolkit(Tools).pipe(
188
+ * Layer.provide(Auth.layer),
189
+ * Layer.provide(Tools.toLayer({
190
+ * WhoAmI: () => Effect.map(CurrentUser, (user) => user.id)
191
+ * }))
192
+ * )
193
+ * ```
194
+ *
195
+ * @stability unstable
196
+ * @category middleware
197
+ * @since 4.0.0
198
+ */
199
+ export const middleware = function () {
200
+ if (arguments.length === 0) {
201
+ return makeMiddleware;
202
+ }
203
+ return makeMiddleware(arguments[0], arguments[1]);
204
+ };
205
+ /**
206
+ * Creates middleware that hides registrations per request.
207
+ *
208
+ * **Details**
209
+ *
210
+ * The check runs for every registration the middleware is provided to, on list
211
+ * requests and on calls, reads, gets and completions. When it returns `false`
212
+ * the registration is left out of list results, and requests for it fail as if
213
+ * it was not registered.
214
+ *
215
+ * The result is a `Middleware` and composes like one. The check receives the
216
+ * same {@link MiddlewareOptions} as middleware, and services it reads per
217
+ * request, other than `McpRequestContext`, are met the same way. Scope a
218
+ * visibility to some tools by providing its layer to their toolkit only, or
219
+ * branch on `target`.
220
+ *
221
+ * On a list request, the check and the middleware outside the innermost
222
+ * visibility run once for each registration. Middleware inside it does not
223
+ * run. A failure of that middleware or of a check fails the whole list
224
+ * request. It never hides a registration.
225
+ *
226
+ * Unlike `EnabledWhen`, a visibility runs the middleware around it on list
227
+ * requests, and middleware sees requests for hidden registrations.
228
+ *
229
+ * **Example** (Hiding admin tools from other users)
230
+ *
231
+ * ```ts
232
+ * import { Context, Effect, Layer, Schema } from "effect"
233
+ * import { McpServer, Tool, Toolkit } from "effect/ai"
234
+ *
235
+ * class CurrentUser extends Context.Service<CurrentUser, { readonly isAdmin: boolean }>()("CurrentUser") {}
236
+ *
237
+ * const AdminTools = Toolkit.make(Tool.make("DeleteUser", { success: Schema.String }))
238
+ *
239
+ * const Auth = McpServer.middleware<{ provides: CurrentUser }>()((effect, { headers }) =>
240
+ * Effect.provideService(effect, CurrentUser, { isAdmin: headers["x-role"] === "admin" })
241
+ * )
242
+ * const AdminOnly = McpServer.visibility(() => Effect.map(CurrentUser, (user) => user.isAdmin))
243
+ *
244
+ * const Registrations = McpServer.toolkit(AdminTools).pipe(
245
+ * Layer.provide(AdminOnly.combine(Auth).layer),
246
+ * Layer.provide(AdminTools.toLayer({ DeleteUser: () => Effect.succeed("deleted") }))
247
+ * )
248
+ * ```
249
+ *
250
+ * @see {@link middleware} for providing the services a check reads
251
+ *
252
+ * @stability unstable
253
+ * @category middleware
254
+ * @since 4.0.0
255
+ */
256
+ export const visibility = (check, options) => makeMiddleware(Effect.isEffect(check) ? Effect.map(check, makeGate) : makeGate(check), options);
257
+ // Raised by a visibility gate. It is left out of the types because `makeInvoke`
258
+ // replaces it with the not-found error of the request. It still has the shape
259
+ // of an MCP error, since middleware outside the gate sees it as one.
260
+ class Hidden extends /*#__PURE__*/Data.TaggedError("effect/ai/McpServer/Hidden") {}
261
+ const failHidden = /*#__PURE__*/Effect.fail(/*#__PURE__*/new Hidden({
262
+ code: McpSchema.INVALID_PARAMS_ERROR_CODE,
263
+ message: "Not found"
264
+ }));
265
+ // Marks the middleware functions created by `visibility`.
266
+ const gates = /*#__PURE__*/new WeakSet();
267
+ const makeGate = check => {
268
+ const gate = (effect, options) => Effect.flatMap(check(options), visible => visible ? effect : failHidden);
269
+ gates.add(gate);
270
+ return gate;
271
+ };
272
+ class MiddlewareFn extends /*#__PURE__*/Context.Service()("effect/ai/McpServer/MiddlewareFn") {}
273
+ const makeMiddleware = (fn, options) => {
274
+ const middleware = new MiddlewareImpl(Effect.isEffect(fn) ? Layer.effect(MiddlewareFn)(fn) : Layer.succeed(MiddlewareFn, fn));
275
+ return options?.global ? middleware.layerGlobal : middleware;
276
+ };
277
+ let middlewareId = 0;
278
+ class MiddlewareImpl {
279
+ [MiddlewareTypeId] = {};
280
+ layer;
281
+ layerGlobal;
282
+ layerFn;
283
+ dependencies;
284
+ constructor(layerFn, dependencies) {
285
+ this.layerFn = layerFn;
286
+ this.dependencies = dependencies;
287
+ const contextKey = `${middlewareKeyPrefix}${++middlewareId}`;
288
+ this.layer = Layer.effectContext(Effect.gen(function* () {
289
+ const stack = [yield* MiddlewareFn];
290
+ if (dependencies) {
291
+ const memoMap = yield* Layer.CurrentMemoMap;
292
+ const scope = yield* Effect.scope;
293
+ stack.push(...getMiddleware(yield* Layer.buildWithMemoMap(dependencies, memoMap, scope)));
294
+ }
295
+ return Context.makeUnsafe(new Map([[contextKey, stack]]));
296
+ })).pipe(Layer.provide(layerFn));
297
+ this.layerGlobal = Layer.effectDiscard(Effect.gen(function* () {
298
+ const stack = Context.getOrUndefinedUnsafe(yield* Effect.context(), contextKey);
299
+ const {
300
+ globalMiddleware
301
+ } = internalState.get(yield* McpServer);
302
+ yield* Effect.acquireRelease(Effect.sync(() => {
303
+ globalMiddleware.push(...stack);
304
+ }), () => Effect.sync(() => {
305
+ for (const fn of stack) {
306
+ const index = globalMiddleware.indexOf(fn);
307
+ if (index !== -1) globalMiddleware.splice(index, 1);
308
+ }
309
+ }));
310
+ })).pipe(Layer.provide(this.layer));
311
+ }
312
+ combine(other) {
313
+ return new MiddlewareImpl(this.layerFn, this.dependencies ? Layer.provideMerge(this.dependencies, other.layer) : other.layer);
314
+ }
315
+ }
316
+ // The innermost middleware comes first.
317
+ const getMiddleware = context => {
318
+ const stacks = [];
319
+ let maxLength = 0;
320
+ for (const [key, value] of context.mapUnsafe) {
321
+ if (key.startsWith(middlewareKeyPrefix)) {
322
+ stacks.push(value);
323
+ maxLength = Math.max(maxLength, value.length);
324
+ }
325
+ }
326
+ const unique = new Set();
327
+ for (let i = maxLength - 1; i >= 0; i--) {
328
+ for (const stack of stacks) {
329
+ if (i < stack.length) unique.add(stack[i]);
330
+ }
331
+ }
332
+ return Arr.fromIterable(unique).reverse();
333
+ };
334
+ const isMcpError = error => Predicate.hasProperty(error, "code") && typeof error.code === "number" && Predicate.hasProperty(error, "message") && typeof error.message === "string";
335
+ // Distinguishes handler failures from failures raised or rewritten by middleware.
336
+ const HandlerFailure = /*#__PURE__*/Context.Reference("effect/ai/McpServer/HandlerFailure", {
337
+ defaultValue: () => false
338
+ });
339
+ const handlerFailure = /*#__PURE__*/Context.make(HandlerFailure, true);
340
+ const internalError = /*#__PURE__*/new InternalError({
341
+ message: "Internal error"
342
+ });
343
+ const rejectWith = error => Effect.fail(new McpCore.RequestRejected({
344
+ code: error.code,
345
+ message: error.message,
346
+ data: error.data,
347
+ error
348
+ }));
349
+ const notFound = (method, target) => {
350
+ switch (method) {
351
+ case "tools/call":
352
+ return new McpCore.ToolNotFound({
353
+ name: target
354
+ });
355
+ case "resources/read":
356
+ return new McpCore.ResourceNotFound({
357
+ uri: target
358
+ });
359
+ case "prompts/get":
360
+ return new McpCore.PromptNotFound({
361
+ name: target
362
+ });
363
+ case "completion/complete":
364
+ return new InvalidParams({
365
+ message: "Unknown completion reference or argument"
366
+ });
367
+ case "skills/get":
368
+ return new McpCore.SkillNotFound({
369
+ uri: target
370
+ });
371
+ }
372
+ };
373
+ const isHidden = error => error instanceof Hidden;
374
+ // Recovers a request rejected by a visibility gate. Any other cause, including
375
+ // one that also holds an interrupt, is propagated unchanged.
376
+ const catchHidden = onHidden => self => Effect.catchCause(self, cause => {
377
+ const failure = Cause.findFail(cause);
378
+ return !Cause.hasInterrupts(cause) && Result.isSuccess(failure) && isHidden(failure.success.error) ? onHidden() : Effect.failCause(cause);
379
+ });
380
+ // The innermost middleware comes first. Middleware provided both locally and
381
+ // globally runs once, at its outermost position.
382
+ const middlewareStack = (localMiddleware, globalMiddleware) => {
383
+ if (globalMiddleware.length === 0) {
384
+ return localMiddleware;
385
+ }
386
+ if (localMiddleware.length === 0) {
387
+ return globalMiddleware;
388
+ }
389
+ const stack = [...localMiddleware, ...globalMiddleware];
390
+ return stack.filter((fn, index) => stack.lastIndexOf(fn) === index);
391
+ };
392
+ // Runs a handler inside middleware. The handler's own failures pass through, a
393
+ // visibility gate fails with `Hidden`, and other failures become
394
+ // `RequestRejected`: middleware failures as JSON-RPC errors, anything else as
395
+ // a reported internal error.
396
+ const runMiddleware = (handler, middleware, invocation, request) => {
397
+ const effect = middleware.length === 0 ? handler : Effect.withFiber(fiber => {
398
+ const headers = Context.getOrUndefined(fiber.context, HttpServerRequest.HttpServerRequest)?.headers ?? Headers.empty;
399
+ const options = {
400
+ ...request,
401
+ requestContext: invocation.requestContext,
402
+ headers,
403
+ sessionId: headers[MCP_SESSION_ID_HEADER]
404
+ };
405
+ const handled = Effect.catchCause(handler, cause => Effect.failCause(Cause.annotate(cause, handlerFailure)));
406
+ return middleware.reduce((effect, fn) => fn(effect, options), handled);
407
+ });
408
+ return provideInvocationContext(effect, invocation).pipe(Effect.catchCause(cause => {
409
+ if (Cause.hasInterrupts(cause)) {
410
+ return Effect.failCause(cause);
411
+ }
412
+ const failure = Cause.findFail(cause);
413
+ if (Result.isSuccess(failure) && !Cause.hasDies(cause)) {
414
+ const error = failure.success.error;
415
+ if (isHidden(error)) {
416
+ return Effect.fail(error);
417
+ }
418
+ if (middleware.length === 0 || Context.get(Cause.reasonAnnotations(failure.success), HandlerFailure)) {
419
+ return Effect.failCause(cause);
420
+ }
421
+ if (isMcpError(error)) {
422
+ return rejectWith(error);
423
+ }
424
+ }
425
+ return Effect.logError(cause).pipe(Effect.andThen(ErrorReporter.report(cause)), Effect.andThen(rejectWith(internalError)));
426
+ }));
427
+ };
428
+ // Request services override captured services; global middleware wraps local middleware.
429
+ const makeInvoke = (context, globalMiddleware) => {
430
+ const services = context === undefined ? Context.empty() : omitRequestServices(context);
431
+ const localMiddleware = context === undefined ? [] : getMiddleware(context);
432
+ const invoke = (handler, invocation, request) => runMiddleware(services.mapUnsafe.size === 0 ? handler : Effect.updateContext(handler, context => Context.merge(services, context)), middlewareStack(localMiddleware, globalMiddleware), invocation, request).pipe(catchHidden(() => Effect.fail(notFound(request.method, request.target))));
433
+ // On list requests only the middleware outside the innermost visibility runs.
434
+ const visible = (method, target) => invocation => {
435
+ const middleware = middlewareStack(localMiddleware, globalMiddleware);
436
+ const innermost = middleware.findIndex(fn => gates.has(fn));
437
+ if (innermost === -1) {
438
+ return Effect.succeed(true);
439
+ }
440
+ return runMiddleware(Effect.void, middleware.slice(innermost), invocation, {
441
+ method,
442
+ target,
443
+ payload: undefined
444
+ }).pipe(Effect.as(true), catchHidden(() => Effect.succeed(false)));
445
+ };
446
+ return {
447
+ invoke,
448
+ visible
449
+ };
450
+ };
451
+ // Applies the `EnabledWhen` annotation of a registration.
452
+ const isEnabled = annotations => {
453
+ const enabledWhen = Context.getOrUndefined(annotations, EnabledWhen);
454
+ return profile => enabledWhen === undefined || enabledWhen({
455
+ protocolVersion: profile.protocolVersion,
456
+ capabilities: profile.clientCapabilities,
457
+ clientInfo: profile.clientInfo
458
+ });
459
+ };
460
+ const rejectedError = rejected => Effect.fail(rejected.error);
120
461
  /**
121
462
  * Service that stores and serves an MCP server's registered tools, resources,
122
463
  * prompts, completions, and outgoing notifications.
@@ -144,6 +485,7 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
144
485
  const resourceTemplates = [];
145
486
  const prompts = [];
146
487
  const notificationsQueue = yield* Queue.make();
488
+ const globalMiddleware = [];
147
489
  const notificationDelivery = {
148
490
  consumers: 0,
149
491
  listChangeRevision: 0,
@@ -209,6 +551,38 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
209
551
  return enqueued && queued.requestContext !== undefined && notificationDelivery.consumers > 0 ? Effect.andThen(Deferred.await(delivered), acknowledge) : acknowledge;
210
552
  })))
211
553
  });
554
+ // Checking skill ownership and both writes happen in one synchronous step,
555
+ // so a skill cannot claim the URI in between. Skill files skip the check.
556
+ const addResource = (options, checkOwnership) => Effect.suspend(() => {
557
+ if (checkOwnership && internalCore.skills.ownsFile(options.resource.uri)) {
558
+ return Effect.die(new Cause.IllegalArgumentError(`Resource ${options.resource.uri} is a file of a registered skill`));
559
+ }
560
+ const existingIndex = resources.findIndex(({
561
+ resource
562
+ }) => resource.uri === options.resource.uri);
563
+ if (existingIndex === -1) {
564
+ resources.push(options);
565
+ } else {
566
+ resources[existingIndex] = options;
567
+ }
568
+ const {
569
+ invoke,
570
+ visible
571
+ } = makeInvoke(options.services, globalMiddleware);
572
+ internalCore.resources.register({
573
+ descriptor: options.resource,
574
+ visible: visible("resources/list", options.resource.uri),
575
+ isVisible: isEnabled(options.annotations),
576
+ read: invocation => invoke(options.handle, invocation, {
577
+ method: "resources/read",
578
+ target: options.resource.uri,
579
+ payload: {
580
+ uri: options.resource.uri
581
+ }
582
+ })
583
+ });
584
+ return notifications.client["notifications/resources/list_changed"]({});
585
+ });
212
586
  const service = McpServer.of({
213
587
  notifications: notifications.client,
214
588
  notifyElicitationComplete: ({
@@ -233,18 +607,22 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
233
607
  } else {
234
608
  tools[existingIndex] = options;
235
609
  }
236
- const enabledWhen = Context.getOrUndefined(options.annotations, EnabledWhen);
610
+ const {
611
+ invoke,
612
+ visible
613
+ } = makeInvoke(options.services, globalMiddleware);
237
614
  yield* internalCore.tools.register({
238
615
  descriptor: new McpTool({
239
616
  ...options.tool,
240
617
  title: options.tool.title ?? options.tool.annotations?.title
241
618
  }),
242
- isVisible: profile => enabledWhen === undefined || enabledWhen({
243
- protocolVersion: profile.protocolVersion,
244
- capabilities: profile.clientCapabilities,
245
- clientInfo: profile.clientInfo
246
- }),
247
- handle: (call, invocation) => provideInvocationContext(options.handle(call.arguments), invocation).pipe(Effect.catchTags({
619
+ visible: visible("tools/list", options.tool.name),
620
+ isVisible: isEnabled(options.annotations),
621
+ handle: (call, invocation) => invoke(options.handle(call.arguments), invocation, {
622
+ method: "tools/call",
623
+ target: call.name,
624
+ payload: call
625
+ }).pipe(Effect.catchTags({
248
626
  InternalError: error => Effect.fail(new McpCore.ToolExecutionError({
249
627
  name: options.tool.name,
250
628
  message: error.message
@@ -259,9 +637,9 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
259
637
  }),
260
638
  callTool: Effect.fnUntraced(function* (request) {
261
639
  const client = yield* McpServerClient;
262
- const result = yield* internalCore.tools.call(request, McpProtocolInternal.invocationFromClient(client)).pipe(Effect.mapError(error => new InvalidParams({
640
+ const result = yield* internalCore.tools.call(request, McpProtocolInternal.invocationFromClient(client)).pipe(Effect.catch(error => error._tag === "RequestRejected" ? rejectedError(error) : Effect.fail(new InvalidParams({
263
641
  message: error._tag === "ToolNotFound" ? `Tool '${error.name}' not found` : error.message
264
- })));
642
+ }))));
265
643
  if (result._tag === "InputRequired") {
266
644
  return yield* new InvalidParams({
267
645
  message: "Client input is not supported by this MCP protocol"
@@ -275,34 +653,13 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
275
653
  get resourceTemplates() {
276
654
  return resourceTemplates;
277
655
  },
278
- addResource: Effect.fnUntraced(function* (options) {
279
- const existingIndex = resources.findIndex(({
280
- resource
281
- }) => resource.uri === options.resource.uri);
282
- if (existingIndex === -1) {
283
- resources.push(options);
284
- } else {
285
- resources[existingIndex] = options;
286
- }
287
- yield* internalCore.resources.register({
288
- descriptor: options.resource,
289
- isVisible: profile => {
290
- const enabledWhen = Context.getOrUndefined(options.annotations, EnabledWhen);
291
- return enabledWhen === undefined || enabledWhen({
292
- protocolVersion: profile.protocolVersion,
293
- capabilities: profile.clientCapabilities,
294
- clientInfo: profile.clientInfo
295
- });
296
- },
297
- read: invocation => provideInvocationContext(options.handle, invocation)
298
- });
299
- yield* notifications.client["notifications/resources/list_changed"]({});
300
- }),
656
+ addResource: options => addResource(options, true),
301
657
  addResourceTemplate: Effect.fnUntraced(function* ({
302
658
  annotations,
303
659
  completions,
304
660
  handle,
305
661
  routerPath,
662
+ services,
306
663
  template
307
664
  }) {
308
665
  const existingIndex = resourceTemplates.findIndex(({
@@ -319,18 +676,16 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
319
676
  annotations
320
677
  };
321
678
  }
679
+ const {
680
+ invoke,
681
+ visible
682
+ } = makeInvoke(services, globalMiddleware);
322
683
  const templateMatcher = makeUriMatcher();
323
684
  templateMatcher.add(routerPath, true);
324
685
  yield* internalCore.resources.registerTemplate({
325
686
  descriptor: template,
326
- isVisible: profile => {
327
- const enabledWhen = Context.getOrUndefined(annotations, EnabledWhen);
328
- return enabledWhen === undefined || enabledWhen({
329
- protocolVersion: profile.protocolVersion,
330
- capabilities: profile.clientCapabilities,
331
- clientInfo: profile.clientInfo
332
- });
333
- },
687
+ visible: visible("resources/templates/list", template.uriTemplate),
688
+ isVisible: isEnabled(annotations),
334
689
  match: uri => {
335
690
  const match = templateMatcher.find(uri);
336
691
  if (match === undefined) {
@@ -342,10 +697,20 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
342
697
  }
343
698
  return params;
344
699
  },
345
- read: (uri, params, invocation) => provideInvocationContext(handle(uri, Array.from(params)), invocation)
700
+ read: (uri, params, invocation) => invoke(handle(uri, Array.from(params)), invocation, {
701
+ method: "resources/read",
702
+ target: uri,
703
+ payload: {
704
+ uri
705
+ }
706
+ })
346
707
  });
347
708
  for (const [param, handle] of Object.entries(completions)) {
348
- yield* internalCore.completions.register(`resource/${template.uriTemplate}/${param}`, (request, invocation) => provideInvocationContext(handle(request.argument.value, request.context), invocation).pipe(Effect.map(result => ({
709
+ yield* internalCore.completions.register(`resource/${template.uriTemplate}/${param}`, (request, invocation) => invoke(handle(request.argument.value, request.context), invocation, {
710
+ method: "completion/complete",
711
+ target: template.uriTemplate,
712
+ payload: request
713
+ }).pipe(Effect.map(result => ({
349
714
  values: result.completion.values,
350
715
  total: result.completion.total,
351
716
  hasMore: result.completion.hasMore,
@@ -356,9 +721,12 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
356
721
  }),
357
722
  findResource: Effect.fnUntraced(function* (uri) {
358
723
  const client = yield* McpServerClient;
359
- return yield* internalCore.resources.read(uri, McpProtocolInternal.invocationFromClient(client)).pipe(Effect.catchTag("ResourceNotFound", error => Effect.fail(new InvalidParams({
360
- message: `Resource '${error.uri}' not found`
361
- }))));
724
+ return yield* internalCore.resources.read(uri, McpProtocolInternal.invocationFromClient(client)).pipe(Effect.catchTags({
725
+ ResourceNotFound: error => Effect.fail(new InvalidParams({
726
+ message: `Resource '${error.uri}' not found`
727
+ })),
728
+ RequestRejected: rejectedError
729
+ }));
362
730
  }),
363
731
  get prompts() {
364
732
  return prompts;
@@ -372,20 +740,29 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
372
740
  } else {
373
741
  prompts[existingIndex] = options;
374
742
  }
743
+ const {
744
+ invoke,
745
+ visible
746
+ } = makeInvoke(options.services, globalMiddleware);
375
747
  yield* internalCore.prompts.register({
376
748
  descriptor: options.prompt,
377
- isVisible: profile => {
378
- const enabledWhen = Context.getOrUndefined(options.annotations, EnabledWhen);
379
- return enabledWhen === undefined || enabledWhen({
380
- protocolVersion: profile.protocolVersion,
381
- capabilities: profile.clientCapabilities,
382
- clientInfo: profile.clientInfo
383
- });
384
- },
385
- get: (params, invocation) => provideInvocationContext(options.handle(params), invocation).pipe(Effect.map(result => Predicate.isTagged(result, "InputRequired") ? McpCore.OperationOutcome.InputRequired(result) : McpCore.OperationOutcome.Complete(result)))
749
+ visible: visible("prompts/list", options.prompt.name),
750
+ isVisible: isEnabled(options.annotations),
751
+ get: (params, invocation) => invoke(options.handle(params), invocation, {
752
+ method: "prompts/get",
753
+ target: options.prompt.name,
754
+ payload: {
755
+ name: options.prompt.name,
756
+ arguments: params
757
+ }
758
+ }).pipe(Effect.map(result => Predicate.isTagged(result, "InputRequired") ? McpCore.OperationOutcome.InputRequired(result) : McpCore.OperationOutcome.Complete(result)))
386
759
  });
387
760
  for (const [param, handle] of Object.entries(options.completions)) {
388
- yield* internalCore.completions.register(`prompt/${options.prompt.name}/${param}`, (request, invocation) => provideInvocationContext(handle(request.argument.value, request.context), invocation).pipe(Effect.map(result => ({
761
+ yield* internalCore.completions.register(`prompt/${options.prompt.name}/${param}`, (request, invocation) => invoke(handle(request.argument.value, request.context), invocation, {
762
+ method: "completion/complete",
763
+ target: options.prompt.name,
764
+ payload: request
765
+ }).pipe(Effect.map(result => ({
389
766
  values: result.completion.values,
390
767
  total: result.completion.total,
391
768
  hasMore: result.completion.hasMore,
@@ -399,9 +776,12 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
399
776
  name
400
777
  }) {
401
778
  const client = yield* McpServerClient;
402
- const outcome = yield* internalCore.prompts.get(name, params ?? {}, McpProtocolInternal.invocationFromClient(client)).pipe(Effect.catchTag("PromptNotFound", () => new InvalidParams({
403
- message: `Prompt '${name}' not found`
404
- })));
779
+ const outcome = yield* internalCore.prompts.get(name, params ?? {}, McpProtocolInternal.invocationFromClient(client)).pipe(Effect.catchTags({
780
+ PromptNotFound: () => new InvalidParams({
781
+ message: `Prompt '${name}' not found`
782
+ }),
783
+ RequestRejected: rejectedError
784
+ }));
405
785
  return outcome._tag === "Complete" ? outcome.value : yield* new InvalidParams({
406
786
  message: "Client input is not supported by this MCP protocol"
407
787
  });
@@ -419,7 +799,7 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
419
799
  },
420
800
  argument: complete.argument,
421
801
  context: complete.context
422
- }, McpProtocolInternal.invocationFromClient(client));
802
+ }, McpProtocolInternal.invocationFromClient(client)).pipe(Effect.catchTag("RequestRejected", rejectedError));
423
803
  return {
424
804
  _meta: result.metadata,
425
805
  completion: {
@@ -432,13 +812,21 @@ export class McpServer extends /*#__PURE__*/Context.Service()("effect/ai/McpServ
432
812
  });
433
813
  internalState.set(service, {
434
814
  core: internalCore,
815
+ addSkillFile: options => addResource(options, false),
435
816
  notifications: notificationsQueue,
436
- notificationDelivery
817
+ notificationDelivery,
818
+ globalMiddleware
437
819
  });
438
820
  return service;
439
821
  });
440
822
  /**
441
- * Layer that provides the MCP server and client services.
823
+ * Layer that provides the MCP server service.
824
+ *
825
+ * **Details**
826
+ *
827
+ * It doesn't run a transport or discharge request-level dependencies. Use it
828
+ * to call registrations in process, providing their request-level
829
+ * dependencies with MCP middleware.
442
830
  *
443
831
  * @stability unstable
444
832
  * @since 4.0.0
@@ -452,6 +840,26 @@ const cancelledResponses = /*#__PURE__*/new WeakMap();
452
840
  const httpPostResponses = /*#__PURE__*/new WeakMap();
453
841
  const requestKey = requestId => `${typeof requestId}:${requestId}`;
454
842
  class McpClientKey extends Data.Class {}
843
+ // Converts each hint to the wire's nonnegative integer `ttlMs` once, when the server is built.
844
+ const normalizeCacheHints = cacheHints => {
845
+ if (cacheHints === undefined) return Effect.succeed(undefined);
846
+ const normalized = {};
847
+ for (const [name, hint] of Object.entries(cacheHints)) {
848
+ if (hint === undefined) continue;
849
+ const ttlMs = Option.match(Duration.fromInput(hint.ttl), {
850
+ onNone: () => NaN,
851
+ onSome: ttl => Math.floor(Duration.toMillis(ttl))
852
+ });
853
+ if (!Number.isSafeInteger(ttlMs) || ttlMs < 0 || hint.cacheScope !== "private") {
854
+ return Effect.fail(new Cause.IllegalArgumentError(`McpServer cacheHints.${name} must have a finite, nonnegative ttl and a "private" cacheScope`));
855
+ }
856
+ normalized[name] = {
857
+ ttlMs,
858
+ cacheScope: "private"
859
+ };
860
+ }
861
+ return Effect.succeed(normalized);
862
+ };
455
863
  /**
456
864
  * Runs an MCP server over the current `RpcServer.Protocol`.
457
865
  *
@@ -466,9 +874,13 @@ class McpClientKey extends Data.Class {}
466
874
  * @since 4.0.0
467
875
  */
468
876
  export const run = /*#__PURE__*/Effect.fnUntraced(function* (options) {
877
+ const cacheHints = yield* normalizeCacheHints(options.cacheHints);
469
878
  const runtimeOption = yield* Effect.serviceOption(McpRuntime.ServerRuntime);
470
879
  const runtime = Option.isSome(runtimeOption) ? runtimeOption.value : yield* McpRuntime.make(options.protocols);
471
- return yield* runWithRuntime(options, runtime, "custom");
880
+ return yield* runWithRuntime({
881
+ ...options,
882
+ cacheHints
883
+ }, runtime, "custom");
472
884
  });
473
885
  const runWithRuntime = /*#__PURE__*/Effect.fnUntraced(function* (options, runtime, transport, requestScoped) {
474
886
  const protocol = yield* RpcServer.Protocol;
@@ -975,7 +1387,7 @@ const runWithRuntime = /*#__PURE__*/Effect.fnUntraced(function* (options, runtim
975
1387
  if (requestContext?.clientId !== clientId || !isLoggingLevel(level) || McpSchema.LoggingLevel.literals.indexOf(notification.level) < McpSchema.LoggingLevel.literals.indexOf(level)) {
976
1388
  return;
977
1389
  }
978
- } else if (!runtime.canDeliver(clientId, (requestContext?.clientId === clientId ? requestHeaders : undefined) ?? clientStates.get(clientId)?.sessionHeaders ?? Headers.empty, notification, defaultLogLevel)) {
1390
+ } else if (!runtime.canDeliver(clientId, (requestContext?.clientId === clientId ? requestHeaders : undefined) ?? clientStates.get(clientId)?.sessionHeaders ?? Headers.empty, notification, defaultLogLevel, listChangeRevision)) {
979
1391
  return;
980
1392
  }
981
1393
  const rpc = selectedProtocol.serverNotificationRpcs.requests.get(projected.tag);
@@ -1028,6 +1440,11 @@ const runWithRuntime = /*#__PURE__*/Effect.fnUntraced(function* (options, runtim
1028
1440
  * `McpServer.layer`, so registration layers can use the `McpServer` service
1029
1441
  * while the server is running.
1030
1442
  *
1443
+ * Pass registration layers as `registrations` to build them before the server
1444
+ * reads its first request. The transport discharges the request-level
1445
+ * dependencies it supplies (see `ProvidedServices`); any other `McpRequest`
1446
+ * marker stays in the layer's requirements and must be met by MCP middleware.
1447
+ *
1031
1448
  * **Gotchas**
1032
1449
  *
1033
1450
  * Unlike `layerStdio` and `layerHttp`, this layer does not install a concrete
@@ -1043,9 +1460,13 @@ const runWithRuntime = /*#__PURE__*/Effect.fnUntraced(function* (options, runtim
1043
1460
  */
1044
1461
  export const layer = options => layerWithRuntime(options, "custom").pipe(Layer.provide(McpRuntime.layer(options.protocols)));
1045
1462
  const layerWithRuntime = (options, transport) => Layer.effectDiscard(Effect.gen(function* () {
1463
+ const cacheHints = yield* normalizeCacheHints(options.cacheHints);
1046
1464
  const runtime = yield* McpRuntime.ServerRuntime;
1047
- yield* Effect.forkScoped(runWithRuntime(options, runtime, transport));
1048
- })).pipe(Layer.provideMerge(McpServer.layer));
1465
+ yield* Effect.forkScoped(runWithRuntime({
1466
+ ...options,
1467
+ cacheHints
1468
+ }, runtime, transport));
1469
+ })).pipe(Layer.provide(options.registrations ?? Layer.empty), Layer.provideMerge(McpServer.layer));
1049
1470
  /**
1050
1471
  * Creates a layer that runs an MCP server over standard input and output.
1051
1472
  *
@@ -1061,6 +1482,11 @@ const layerWithRuntime = (options, transport) => Layer.effectDiscard(Effect.gen(
1061
1482
  * `McpRequestContext` and legacy `McpServerClient` services to handlers, and
1062
1483
  * requires `Stdio`.
1063
1484
  *
1485
+ * Pass registration layers as `registrations` to build them before the server
1486
+ * reads its first request. The transport discharges the request-level
1487
+ * dependencies it supplies (see `ProvidedServices`); any other `McpRequest`
1488
+ * marker stays in the layer's requirements and must be met by MCP middleware.
1489
+ *
1064
1490
  * @see {@link layer} for running over an existing `RpcServer.Protocol`
1065
1491
  * @see {@link layerHttp} for the single-endpoint HTTP transport
1066
1492
  *
@@ -1161,6 +1587,13 @@ const mcpStdioSerialization = protocols => {
1161
1587
  * serverless hosts where execution must belong to each request, use
1162
1588
  * `layerHttpRequestScoped` instead.
1163
1589
  *
1590
+ * Pass registration layers as `registrations` to build them before the
1591
+ * endpoint serves its first request. The transport discharges the
1592
+ * request-level dependencies it supplies (see `ProvidedServices`) and converts
1593
+ * the remaining `McpRequest` markers into `HttpRouter.Request` markers, so
1594
+ * `HttpRouter.middleware` can provide them, for example to authenticate the
1595
+ * request and resolve the current user.
1596
+ *
1164
1597
  * `layerHttp` always implements the single-endpoint Streamable HTTP topology.
1165
1598
  * Using `v2024_11_05` here is a custom compatibility transport for that
1166
1599
  * revision's schema. It does not implement the historical two-endpoint
@@ -1210,6 +1643,10 @@ export const layerHttp = options => {
1210
1643
  * Configuring a sessionful protocol through an untyped caller fails layer
1211
1644
  * construction with `IllegalArgumentError`.
1212
1645
  *
1646
+ * Registrations passed as `registrations` are built once, before the routes
1647
+ * are added, and shared by every POST. Remaining `McpRequest` markers become
1648
+ * `HttpRouter.Request` markers, as with `layerHttp`.
1649
+ *
1213
1650
  * @see {@link layerHttp} for the long-lived HTTP transport and HTTP admission policy
1214
1651
  *
1215
1652
  * @stability unstable
@@ -1222,6 +1659,10 @@ export const layerHttpRequestScoped = options => Layer.effectDiscard(Effect.gen(
1222
1659
  if (stateful !== undefined) {
1223
1660
  return yield* new Cause.IllegalArgumentError(`McpServer.layerHttpRequestScoped does not support the sessionful MCP protocol ${stateful.protocolVersion}`);
1224
1661
  }
1662
+ const serverOptions = {
1663
+ ...options,
1664
+ cacheHints: yield* normalizeCacheHints(options.cacheHints)
1665
+ };
1225
1666
  const server = yield* McpServer;
1226
1667
  const {
1227
1668
  core,
@@ -1235,7 +1676,7 @@ export const layerHttpRequestScoped = options => Layer.effectDiscard(Effect.gen(
1235
1676
  subscribeServerNotifications: Effect.die("Subscriptions are disabled for request-scoped MCP servers"),
1236
1677
  getListChangeRevision: () => notificationDelivery.listChangeRevision,
1237
1678
  defaultLogLevel: yield* CurrentLogLevel,
1238
- serverInfo: options
1679
+ serverInfo: serverOptions
1239
1680
  });
1240
1681
  yield* Effect.acquireRelease(Effect.sync(() => {
1241
1682
  notificationDelivery.requestEndpoints++;
@@ -1250,7 +1691,7 @@ export const layerHttpRequestScoped = options => Layer.effectDiscard(Effect.gen(
1250
1691
  protocol
1251
1692
  } = yield* RpcServer.makeProtocolWithHttpEffect().pipe(Effect.provideService(RpcSerialization.RpcSerialization, mcpHttpSerialization));
1252
1693
  const notifications = yield* Queue.make();
1253
- yield* runWithRuntime(options, runtime, "http", {
1694
+ yield* runWithRuntime(serverOptions, runtime, "http", {
1254
1695
  notifications,
1255
1696
  handlers
1256
1697
  }).pipe(Effect.provideService(RpcServer.Protocol, protocol), Effect.provideService(McpServer, server), Effect.forkScoped({
@@ -1258,7 +1699,7 @@ export const layerHttpRequestScoped = options => Layer.effectDiscard(Effect.gen(
1258
1699
  }));
1259
1700
  return yield* Effect.provideService(httpEffect, RequestNotificationQueue, notifications);
1260
1701
  }));
1261
- })).pipe(Layer.provideMerge(McpServer.layer), Layer.provide(McpRuntime.layer(options.protocols)));
1702
+ })).pipe(Layer.provide(options.registrations ?? Layer.empty), Layer.provideMerge(McpServer.layer), Layer.provide(McpRuntime.layer(options.protocols)));
1262
1703
  const layerMcpProtocolHttp = options => Layer.effect(RpcServer.Protocol)(Effect.gen(function* () {
1263
1704
  const {
1264
1705
  httpEffect,
@@ -1480,6 +1921,13 @@ const toolResultContent = encoded => encoded === undefined ? [] : [{
1480
1921
  /**
1481
1922
  * Registers a `Toolkit` with the `McpServer`.
1482
1923
  *
1924
+ * **Details**
1925
+ *
1926
+ * The MCP middleware in the current context, provided with
1927
+ * `Effect.provide(middleware.layer)`, runs around every call to the toolkit.
1928
+ *
1929
+ * @see {@link ToolkitRequirements} for which services are request-level
1930
+ *
1483
1931
  * @stability unstable
1484
1932
  * @category handlers
1485
1933
  * @since 4.0.0
@@ -1500,12 +1948,11 @@ export const registerToolkit = /*#__PURE__*/Effect.fnUntraced(function* (toolkit
1500
1948
  }
1501
1949
  return Context.makeUnsafe(services);
1502
1950
  }));
1503
- const services = omitRequestServices(yield* Effect.context());
1504
- const reportCause = cause => Effect.provideContext(ErrorReporter.report(cause), services);
1951
+ const services = yield* Effect.context();
1505
1952
  // Interruption propagates; anything else is logged, reported and scrubbed.
1506
1953
  const internalToolError = cause => {
1507
1954
  const failure = Cause.findFail(cause);
1508
- return Result.isFailure(failure) && !Cause.hasDies(cause) ? Effect.failCause(failure.failure) : Effect.logError(cause).pipe(Effect.andThen(reportCause(cause)), Effect.as(toolErrorResult(INTERNAL_TOOL_ERROR_MESSAGE)));
1955
+ return Result.isFailure(failure) && !Cause.hasDies(cause) ? Effect.failCause(failure.failure) : Effect.logError(cause).pipe(Effect.andThen(ErrorReporter.report(cause)), Effect.as(toolErrorResult(INTERNAL_TOOL_ERROR_MESSAGE)));
1509
1956
  };
1510
1957
  const registrations = [];
1511
1958
  for (const tool of Object.values(built.tools)) {
@@ -1526,6 +1973,22 @@ export const registerToolkit = /*#__PURE__*/Effect.fnUntraced(function* (toolkit
1526
1973
  isError: true,
1527
1974
  content: toolResultContent(encoded)
1528
1975
  }));
1976
+ // `structuredContent` must be JSON and match the advertised `outputSchema`, which is derived from the JSON codec.
1977
+ // The Toolkit has already encoded the result, so only the JSON conversion of its encoded form runs here.
1978
+ const encodeStructured = Schema.encodeUnknownEffect(Schema.toCodecJson(Schema.toEncoded(tool.successSchema)));
1979
+ const successResult = result => encodeStructured(result).pipe(Effect.mapError(cause => AiError.make({
1980
+ module: "McpServer",
1981
+ method: "registerToolkit",
1982
+ reason: new AiError.ToolResultEncodingError({
1983
+ toolName: tool.name,
1984
+ toolResult: result,
1985
+ description: cause.message
1986
+ })
1987
+ })), Effect.map(structuredContent => new CallToolResult({
1988
+ isError: false,
1989
+ structuredContent,
1990
+ content: toolResultContent(structuredContent)
1991
+ })));
1529
1992
  const handleCause = cause => {
1530
1993
  const failure = Cause.findFail(cause);
1531
1994
  if (Result.isSuccess(failure)) {
@@ -1564,14 +2027,22 @@ export const registerToolkit = /*#__PURE__*/Effect.fnUntraced(function* (toolkit
1564
2027
  tool: mcpTool,
1565
2028
  annotations,
1566
2029
  handle(payload) {
1567
- return built.handle(tool.name, payload ?? {}, undefined, decodeOptions).pipe(Stream.unwrap, Stream.runLast, Effect.flatMap(Effect.fromOption), Effect.flatMap(result =>
1568
- // Declared failures return their encoded payload; anything else is classified by origin.
1569
- result.isFailure && result.failureOrigin !== "handler" ? Effect.failCause(Cause.annotate(Cause.fail(result.result), Context.make(Toolkit.FailureOrigin, result.failureOrigin ?? "result"))) : Effect.succeed(new CallToolResult({
1570
- isError: result.isFailure,
1571
- structuredContent: result.isFailure ? undefined : result.encodedResult,
1572
- content: toolResultContent(result.encodedResult)
1573
- }))), Effect.catchCause(handleCause), Effect.provideContext(services));
1574
- }
2030
+ return built.handle(tool.name, payload ?? {}, undefined, decodeOptions).pipe(Stream.unwrap, Stream.runLast, Effect.flatMap(Effect.fromOption), Effect.flatMap(result => {
2031
+ if (!result.isFailure) {
2032
+ // An absent result, such as `Schema.Void`, has no structured form.
2033
+ return result.encodedResult === undefined ? Effect.succeed(new CallToolResult({
2034
+ isError: false,
2035
+ content: []
2036
+ })) : successResult(result.encodedResult);
2037
+ }
2038
+ // Declared failures return their encoded payload; anything else is classified by origin.
2039
+ return result.failureOrigin === "handler" ? Effect.succeed(new CallToolResult({
2040
+ isError: true,
2041
+ content: toolResultContent(result.encodedResult)
2042
+ })) : Effect.failCause(Cause.annotate(Cause.fail(result.result), Context.make(Toolkit.FailureOrigin, result.failureOrigin ?? "result")));
2043
+ }), Effect.catchCause(handleCause));
2044
+ },
2045
+ services
1575
2046
  });
1576
2047
  }
1577
2048
  for (const registration of registrations) {
@@ -1598,13 +2069,31 @@ const toolJsonSchema = (schema, strict) => {
1598
2069
  };
1599
2070
  };
1600
2071
  /**
1601
- * Registers an `AiToolkit` with the `McpServer`.
2072
+ * Creates a layer that registers a `Toolkit` with the `McpServer`.
2073
+ *
2074
+ * **Details**
2075
+ *
2076
+ * The layer requires `McpServer`. Pass it to a transport through the
2077
+ * `registrations` option, or provide the transport layer to it.
2078
+ *
2079
+ * @see {@link ToolkitRequirements} for which services are request-level
1602
2080
  *
1603
2081
  * @stability unstable
1604
2082
  * @category layers
1605
2083
  * @since 4.0.0
1606
2084
  */
1607
- export const toolkit = toolkit => Layer.effectDiscard(registerToolkit(toolkit)).pipe(Layer.provide(McpServer.layer));
2085
+ export const toolkit = toolkit => Layer.effectDiscard(registerToolkit(toolkit));
2086
+ // Leave defects and interruption to makeInvoke; convert only expected failures.
2087
+ const handlerFailureToInternalError = cause => Cause.hasDies(cause) || Cause.hasInterrupts(cause) ? Effect.failCause(cause) : Effect.fail(new InternalError({
2088
+ message: Cause.prettyErrors(cause)[0].message
2089
+ }));
2090
+ const completionHandler = (handle, encodeValues) => (input, context) => handle(input, context).pipe(Effect.flatMap(encodeValues), Effect.map(values => ({
2091
+ completion: {
2092
+ values: values,
2093
+ total: values.length,
2094
+ hasMore: false
2095
+ }
2096
+ })), Effect.catchCause(handlerFailureToInternalError));
1608
2097
  /**
1609
2098
  * Registers an MCP resource or resource template from an Effect program.
1610
2099
  *
@@ -1618,19 +2107,15 @@ export const registerResource = function () {
1618
2107
  if (arguments.length === 1) {
1619
2108
  const options = arguments[0];
1620
2109
  return Effect.gen(function* () {
1621
- const services = omitRequestServices(yield* Effect.context());
2110
+ const services = yield* Effect.context();
1622
2111
  const registry = yield* McpServer;
1623
2112
  yield* registry.addResource({
1624
2113
  resource: new Resource({
1625
2114
  ...options,
1626
2115
  annotations: options
1627
2116
  }),
1628
- handle: options.content.pipe(Effect.provideContext(services), Effect.map(content => resolveResourceContent(options.uri, content)), Effect.catchCause(cause => {
1629
- const prettyError = Cause.prettyErrors(cause)[0];
1630
- return Effect.fail(new InternalError({
1631
- message: prettyError.message
1632
- }));
1633
- })),
2117
+ services,
2118
+ handle: options.content.pipe(Effect.map(content => resolveResourceContent(options.uri, content)), Effect.catchCause(handlerFailureToInternalError)),
1634
2119
  annotations: options.annotations ?? Context.empty()
1635
2120
  });
1636
2121
  });
@@ -1642,7 +2127,7 @@ export const registerResource = function () {
1642
2127
  uriPath
1643
2128
  } = compileUriTemplate(...arguments);
1644
2129
  return Effect.fnUntraced(function* (options) {
1645
- const services = omitRequestServices(yield* Effect.context());
2130
+ const services = yield* Effect.context();
1646
2131
  const registry = yield* McpServer;
1647
2132
  const decode = Schema.decodeUnknownEffect(schema);
1648
2133
  const template = new ResourceTemplate({
@@ -1652,41 +2137,32 @@ export const registerResource = function () {
1652
2137
  });
1653
2138
  const completions = Object.create(null);
1654
2139
  for (const [param, handle] of Object.entries(options.completion ?? {})) {
1655
- const encodeArray = Schema.encodeUnknownEffect(Schema.Array(params[param]));
1656
- const handler = (input, context) => handle(input, context).pipe(Effect.flatMap(encodeArray), Effect.map(values => ({
1657
- completion: {
1658
- values: values,
1659
- total: values.length,
1660
- hasMore: false
1661
- }
1662
- })), Effect.catchCause(cause => {
1663
- const prettyError = Cause.prettyErrors(cause)[0];
1664
- return Effect.fail(new InternalError({
1665
- message: prettyError.message
1666
- }));
1667
- }), Effect.provideContext(services));
1668
- completions[param] = handler;
2140
+ completions[param] = completionHandler(handle, Schema.encodeUnknownEffect(Schema.Array(params[param])));
1669
2141
  }
1670
2142
  yield* registry.addResourceTemplate({
1671
2143
  template,
1672
2144
  routerPath,
1673
2145
  completions,
2146
+ services,
1674
2147
  annotations: options.annotations ?? Context.empty(),
1675
2148
  handle: (uri, params) => decode(params).pipe(Effect.mapError(error => new InvalidParams({
1676
2149
  message: error.message
1677
- })), Effect.flatMap(params => options.content(uri, ...params).pipe(Effect.map(content => resolveResourceContent(uri, content)), Effect.catchCause(cause => {
1678
- const prettyError = Cause.prettyErrors(cause)[0];
1679
- return Effect.fail(new InternalError({
1680
- message: prettyError.message
1681
- }));
1682
- }))), Effect.provideContext(services))
2150
+ })), Effect.flatMap(params => options.content(uri, ...params).pipe(Effect.map(content => resolveResourceContent(uri, content)), Effect.catchCause(handlerFailureToInternalError))))
1683
2151
  });
1684
2152
  });
1685
2153
  };
1686
2154
  /**
1687
2155
  * Creates a layer that registers an MCP resource or resource template.
1688
2156
  *
2157
+ * **Details**
2158
+ *
2159
+ * Services read by the content and completion handlers are request-level, so
2160
+ * providing them with `Layer.provide` doesn't satisfy them. Read
2161
+ * construction-time services in an enclosing `Layer.unwrap` and close over
2162
+ * them, and provide per-request services with MCP middleware.
2163
+ *
1689
2164
  * @see {@link registerResource} for the Effect-level resource registration API
2165
+ * @see {@link middleware} for providing request-level dependencies
1690
2166
  *
1691
2167
  * @stability unstable
1692
2168
  * @category layers
@@ -1694,11 +2170,156 @@ export const registerResource = function () {
1694
2170
  */
1695
2171
  export const resource = function () {
1696
2172
  if (arguments.length === 1) {
1697
- return Layer.effectDiscard(registerResource(arguments[0])).pipe(Layer.provide(McpServer.layer));
2173
+ return Layer.effectDiscard(registerResource(arguments[0]));
1698
2174
  }
1699
2175
  const register = registerResource(...arguments);
1700
- return options => Layer.effectDiscard(register(options)).pipe(Layer.provide(McpServer.layer));
2176
+ return options => Layer.effectDiscard(register(options));
2177
+ };
2178
+ const skillFileEncoder = /*#__PURE__*/new TextEncoder();
2179
+ // Bytes are copied so that later changes by the caller cannot alter what is
2180
+ // served under the listed digest. `Buffer#slice` shares memory, so copy with
2181
+ // the `Uint8Array` constructor.
2182
+ const toSkillSourceFile = (path, file) => {
2183
+ const {
2184
+ content,
2185
+ mimeType
2186
+ } = typeof file === "string" || file instanceof Uint8Array ? {
2187
+ content: file
2188
+ } : file;
2189
+ return {
2190
+ path,
2191
+ content: typeof content === "string" ? skillFileEncoder.encode(content) : new Uint8Array(content),
2192
+ mimeType
2193
+ };
1701
2194
  };
2195
+ /**
2196
+ * Registers an Agent Skill under the MCP Skills extension (SEP-2640).
2197
+ *
2198
+ * **Details**
2199
+ *
2200
+ * Each file is registered as a resource, and the skill is listed by
2201
+ * `skills/list` and `skills/get` with a manifest of every file's SHA-256
2202
+ * digest and size, computed from the bytes served. Every directory of the
2203
+ * skill namespace is readable with `resources/directory/read`. The server
2204
+ * declares the extension once any skill is registered.
2205
+ *
2206
+ * Fails when the skill breaks the extension's rules: a name that does not
2207
+ * match the URI, a `SKILL.md` without YAML frontmatter, frontmatter that is
2208
+ * not valid {@link McpSchema.SkillFrontmatter}, a file path that leaves the
2209
+ * skill, or more than 512 files or 16 MiB in all. It also fails when the
2210
+ * skill's directory contains or lies inside another skill's, or one of its
2211
+ * files is already registered as a resource. Registering a resource at the
2212
+ * URI of a skill's file afterwards is a defect.
2213
+ *
2214
+ * SHA-256 runs on `crypto.subtle`.
2215
+ *
2216
+ * @see {@link skill} for the layer-based skill registration wrapper
2217
+ *
2218
+ * @stability unstable
2219
+ * @category handlers
2220
+ * @since 4.1.1
2221
+ */
2222
+ export const registerSkill = /*#__PURE__*/Effect.fnUntraced(function* (options) {
2223
+ const files = Object.entries(options.files).map(([path, file]) => toSkillSourceFile(path, file));
2224
+ const skill = yield* McpSkills.makeStaticSkill({
2225
+ uri: options.uri,
2226
+ files
2227
+ }).pipe(Effect.provide(Digest.layerWebCrypto));
2228
+ const registry = yield* McpServer;
2229
+ const {
2230
+ addSkillFile,
2231
+ core,
2232
+ globalMiddleware
2233
+ } = internalState.get(registry);
2234
+ const services = yield* Effect.context();
2235
+ const annotations = options.annotations ?? Context.empty();
2236
+ const {
2237
+ invoke,
2238
+ visible
2239
+ } = makeInvoke(services, globalMiddleware);
2240
+ // Claims the skill's file URIs before they are registered as resources.
2241
+ yield* core.skills.register({
2242
+ entry: skill.entry,
2243
+ isVisible: isEnabled(annotations),
2244
+ visible: visible("skills/list", options.uri),
2245
+ visibleInDirectories: visible("resources/directory/read", options.uri),
2246
+ get: invocation => invoke(Effect.succeed(skill.entry), invocation, {
2247
+ method: "skills/get",
2248
+ target: options.uri,
2249
+ payload: {
2250
+ uri: options.uri
2251
+ }
2252
+ }),
2253
+ directory: uri => skill.directories.get(uri)
2254
+ });
2255
+ for (const {
2256
+ content,
2257
+ resource,
2258
+ text
2259
+ } of skill.files) {
2260
+ const {
2261
+ uri,
2262
+ mimeType
2263
+ } = resource;
2264
+ yield* addSkillFile({
2265
+ resource: new Resource(resource),
2266
+ annotations,
2267
+ services,
2268
+ handle: Effect.succeed({
2269
+ contents: [text === undefined ? {
2270
+ uri,
2271
+ mimeType,
2272
+ blob: content
2273
+ } : {
2274
+ uri,
2275
+ mimeType,
2276
+ text
2277
+ }]
2278
+ })
2279
+ });
2280
+ }
2281
+ });
2282
+ /**
2283
+ * Creates a layer that registers an Agent Skill under the MCP Skills extension
2284
+ * (SEP-2640).
2285
+ *
2286
+ * **Example** (Publishing a skill with a supporting file)
2287
+ *
2288
+ * ```ts
2289
+ * import { Layer } from "effect"
2290
+ * import { McpProtocol, McpServer } from "effect/ai"
2291
+ *
2292
+ * const RefundsSkill = McpServer.skill({
2293
+ * uri: "skill://billing/refunds/SKILL.md",
2294
+ * files: {
2295
+ * "SKILL.md": `---
2296
+ * name: refunds
2297
+ * description: Process refunds using the billing tools
2298
+ * ---
2299
+ *
2300
+ * Read references/policy.md before issuing a refund.
2301
+ * `,
2302
+ * "references/policy.md": "Refunds above CHF 500 require manager approval.\n"
2303
+ * }
2304
+ * })
2305
+ *
2306
+ * const ServerLayer = RefundsSkill.pipe(
2307
+ * Layer.provide(McpServer.layerHttp({
2308
+ * name: "billing",
2309
+ * version: "1.0.0",
2310
+ * path: "/mcp",
2311
+ * protocols: [McpProtocol.v2026_07_28, McpProtocol.v2025_11_25]
2312
+ * }))
2313
+ * )
2314
+ * ```
2315
+ *
2316
+ * @see {@link registerSkill} for the Effect-level skill registration API
2317
+ *
2318
+ * @stability unstable
2319
+ * @category layers
2320
+ * @since 4.1.1
2321
+ */
2322
+ export const skill = options => Layer.effectDiscard(registerSkill(options));
1702
2323
  /**
1703
2324
  * Registers an MCP prompt from an Effect program.
1704
2325
  *
@@ -1733,36 +2354,19 @@ export const registerPrompt = options => {
1733
2354
  const completion = options.completion ?? {};
1734
2355
  return Effect.gen(function* () {
1735
2356
  const registry = yield* McpServer;
1736
- const services = omitRequestServices(yield* Effect.context());
2357
+ const services = yield* Effect.context();
1737
2358
  const completions = Object.create(null);
1738
2359
  for (const [param, handle] of Object.entries(completion)) {
1739
- const encodeArray = Schema.encodeEffect(Schema.Array(props[param]));
1740
- const handler = (input, context) => handle(input, context).pipe(Effect.flatMap(encodeArray), Effect.map(values => ({
1741
- completion: {
1742
- values: values,
1743
- total: values.length,
1744
- hasMore: false
1745
- }
1746
- })), Effect.catchCause(cause => {
1747
- const prettyError = Cause.prettyErrors(cause)[0];
1748
- return Effect.fail(new InternalError({
1749
- message: prettyError.message
1750
- }));
1751
- }), Effect.provide(services));
1752
- completions[param] = handler;
2360
+ completions[param] = completionHandler(handle, Schema.encodeUnknownEffect(Schema.Array(props[param])));
1753
2361
  }
1754
2362
  yield* registry.addPrompt({
1755
2363
  prompt,
1756
2364
  completions,
2365
+ services,
1757
2366
  annotations: options.annotations ?? Context.empty(),
1758
2367
  handle: params => decode(params).pipe(Effect.mapError(error => new InvalidParams({
1759
2368
  message: error.message
1760
- })), Effect.flatMap(params => options.content(params).pipe(Effect.catchCause(cause => {
1761
- const prettyError = Cause.prettyErrors(cause)[0];
1762
- return Effect.fail(new InternalError({
1763
- message: prettyError.message
1764
- }));
1765
- }))), Effect.map(messages => {
2369
+ })), Effect.flatMap(params => options.content(params).pipe(Effect.catchCause(handlerFailureToInternalError))), Effect.map(messages => {
1766
2370
  messages = typeof messages === "string" ? [{
1767
2371
  role: "user",
1768
2372
  content: TextContent.make({
@@ -1773,20 +2377,28 @@ export const registerPrompt = options => {
1773
2377
  messages,
1774
2378
  description: prompt.description
1775
2379
  });
1776
- }), Effect.provideContext(services))
2380
+ }))
1777
2381
  });
1778
2382
  });
1779
2383
  };
1780
2384
  /**
1781
2385
  * Creates a layer that registers an MCP prompt.
1782
2386
  *
2387
+ * **Details**
2388
+ *
2389
+ * Services read by the content and completion handlers are request-level, so
2390
+ * providing them with `Layer.provide` doesn't satisfy them. Read
2391
+ * construction-time services in an enclosing `Layer.unwrap` and close over
2392
+ * them, and provide per-request services with MCP middleware.
2393
+ *
1783
2394
  * @see {@link registerPrompt} for the Effect-level prompt registration API
2395
+ * @see {@link middleware} for providing request-level dependencies
1784
2396
  *
1785
2397
  * @stability unstable
1786
2398
  * @category layers
1787
2399
  * @since 4.0.0
1788
2400
  */
1789
- export const prompt = options => Layer.effectDiscard(registerPrompt(options)).pipe(Layer.provide(McpServer.layer));
2401
+ export const prompt = options => Layer.effectDiscard(registerPrompt(options));
1790
2402
  /**
1791
2403
  * Collects structured input from the current MCP client and decodes the
1792
2404
  * accepted response with `schema`.
@@ -1834,6 +2446,21 @@ export const elicit = /*#__PURE__*/Effect.fnUntraced(function* (options) {
1834
2446
  * @since 4.0.0
1835
2447
  */
1836
2448
  export const clientCapabilities = /*#__PURE__*/McpRequestContext.useSync(_ => _.clientCapabilities);
2449
+ /**
2450
+ * Decodes an `Mcp-Name` header, including base64-wrapped values.
2451
+ * Returns `undefined` for malformed values.
2452
+ *
2453
+ * **Details**
2454
+ *
2455
+ * Use in `HttpRouter.middleware` to identify the tool, prompt or resource
2456
+ * targeted by a `2026-07-28` request. Earlier protocols carry the name only
2457
+ * in the JSON-RPC body.
2458
+ *
2459
+ * @stability unstable
2460
+ * @category decoding
2461
+ * @since 4.0.0
2462
+ */
2463
+ export const decodeNameHeader = value => McpProtocolInternal.decodeRoutingHeader(value);
1837
2464
  // -----------------------------------------------------------------------------
1838
2465
  // Internal
1839
2466
  // -----------------------------------------------------------------------------