effect 4.1.1 → 4.1.3

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 (548) hide show
  1. package/ai-docs/package.json +2 -2
  2. package/ai-docs/tsconfig.json +2 -1
  3. package/dist/ByteSize.d.ts.map +1 -1
  4. package/dist/ByteSize.js +27 -14
  5. package/dist/ByteSize.js.map +1 -1
  6. package/dist/DateTime.d.ts +33 -2
  7. package/dist/DateTime.d.ts.map +1 -1
  8. package/dist/DateTime.js +16 -0
  9. package/dist/DateTime.js.map +1 -1
  10. package/dist/Iterable.d.ts.map +1 -1
  11. package/dist/Iterable.js +27 -24
  12. package/dist/Iterable.js.map +1 -1
  13. package/dist/JsonSchema.d.ts.map +1 -1
  14. package/dist/JsonSchema.js +27 -6
  15. package/dist/JsonSchema.js.map +1 -1
  16. package/dist/Match.d.ts +6 -6
  17. package/dist/Match.d.ts.map +1 -1
  18. package/dist/Match.js.map +1 -1
  19. package/dist/MutableRef.d.ts.map +1 -1
  20. package/dist/MutableRef.js +0 -7
  21. package/dist/MutableRef.js.map +1 -1
  22. package/dist/Queue.d.ts +2 -1
  23. package/dist/Queue.d.ts.map +1 -1
  24. package/dist/Queue.js +16 -9
  25. package/dist/Queue.js.map +1 -1
  26. package/dist/Rational.d.ts +1214 -0
  27. package/dist/Rational.d.ts.map +1 -0
  28. package/dist/Rational.js +880 -0
  29. package/dist/Rational.js.map +1 -0
  30. package/dist/RcMap.d.ts +3 -0
  31. package/dist/RcMap.d.ts.map +1 -1
  32. package/dist/RcMap.js +13 -14
  33. package/dist/RcMap.js.map +1 -1
  34. package/dist/Ref.d.ts.map +1 -1
  35. package/dist/Ref.js +0 -8
  36. package/dist/Ref.js.map +1 -1
  37. package/dist/Runtime.d.ts +75 -3
  38. package/dist/Runtime.d.ts.map +1 -1
  39. package/dist/Runtime.js +81 -4
  40. package/dist/Runtime.js.map +1 -1
  41. package/dist/Schedule.d.ts.map +1 -1
  42. package/dist/Schedule.js +8 -3
  43. package/dist/Schedule.js.map +1 -1
  44. package/dist/Schema.d.ts +131 -29
  45. package/dist/Schema.d.ts.map +1 -1
  46. package/dist/Schema.js +128 -22
  47. package/dist/Schema.js.map +1 -1
  48. package/dist/SchemaAST.d.ts.map +1 -1
  49. package/dist/SchemaAST.js +24 -12
  50. package/dist/SchemaAST.js.map +1 -1
  51. package/dist/SchemaParser.js +2 -2
  52. package/dist/SchemaParser.js.map +1 -1
  53. package/dist/SchemaRepresentation.d.ts +9 -0
  54. package/dist/SchemaRepresentation.d.ts.map +1 -1
  55. package/dist/SchemaRepresentation.js +9 -0
  56. package/dist/SchemaRepresentation.js.map +1 -1
  57. package/dist/ScopedCache.d.ts +7 -0
  58. package/dist/ScopedCache.d.ts.map +1 -1
  59. package/dist/ScopedCache.js +18 -1
  60. package/dist/ScopedCache.js.map +1 -1
  61. package/dist/Stream.d.ts.map +1 -1
  62. package/dist/Stream.js +6 -5
  63. package/dist/Stream.js.map +1 -1
  64. package/dist/ai/AgUi.d.ts +109 -0
  65. package/dist/ai/AgUi.d.ts.map +1 -0
  66. package/dist/ai/AgUi.js +543 -0
  67. package/dist/ai/AgUi.js.map +1 -0
  68. package/dist/ai/AgUiSchema.d.ts +6965 -0
  69. package/dist/ai/AgUiSchema.d.ts.map +1 -0
  70. package/dist/ai/AgUiSchema.js +974 -0
  71. package/dist/ai/AgUiSchema.js.map +1 -0
  72. package/dist/ai/AgUiServer.d.ts +6400 -0
  73. package/dist/ai/AgUiServer.d.ts.map +1 -0
  74. package/dist/ai/AgUiServer.js +309 -0
  75. package/dist/ai/AgUiServer.js.map +1 -0
  76. package/dist/ai/Chat.d.ts +30 -4
  77. package/dist/ai/Chat.d.ts.map +1 -1
  78. package/dist/ai/Chat.js +34 -4
  79. package/dist/ai/Chat.js.map +1 -1
  80. package/dist/ai/LanguageModel.d.ts +1 -1
  81. package/dist/ai/LanguageModel.d.ts.map +1 -1
  82. package/dist/ai/LanguageModel.js +18 -8
  83. package/dist/ai/LanguageModel.js.map +1 -1
  84. package/dist/ai/McpClient.d.ts +5 -0
  85. package/dist/ai/McpClient.d.ts.map +1 -1
  86. package/dist/ai/McpClient.js +11 -1
  87. package/dist/ai/McpClient.js.map +1 -1
  88. package/dist/ai/McpServer.d.ts +18 -1
  89. package/dist/ai/McpServer.d.ts.map +1 -1
  90. package/dist/ai/McpServer.js +251 -43
  91. package/dist/ai/McpServer.js.map +1 -1
  92. package/dist/ai/Prompt.d.ts +6 -2
  93. package/dist/ai/Prompt.d.ts.map +1 -1
  94. package/dist/ai/Prompt.js.map +1 -1
  95. package/dist/ai/Response.d.ts +5 -2
  96. package/dist/ai/Response.d.ts.map +1 -1
  97. package/dist/ai/Response.js +5 -1
  98. package/dist/ai/Response.js.map +1 -1
  99. package/dist/ai/Tool.d.ts +265 -69
  100. package/dist/ai/Tool.d.ts.map +1 -1
  101. package/dist/ai/Tool.js +19 -2
  102. package/dist/ai/Tool.js.map +1 -1
  103. package/dist/ai/Toolkit.d.ts +32 -2
  104. package/dist/ai/Toolkit.d.ts.map +1 -1
  105. package/dist/ai/Toolkit.js +61 -8
  106. package/dist/ai/Toolkit.js.map +1 -1
  107. package/dist/ai/index.d.ts +15 -0
  108. package/dist/ai/index.d.ts.map +1 -1
  109. package/dist/ai/index.js +15 -0
  110. package/dist/ai/index.js.map +1 -1
  111. package/dist/ai/internal/mcpCore.d.ts +0 -2
  112. package/dist/ai/internal/mcpCore.d.ts.map +1 -1
  113. package/dist/ai/internal/mcpCore.js +2 -8
  114. package/dist/ai/internal/mcpCore.js.map +1 -1
  115. package/dist/ai/internal/mcpProtocol/v2024_11_05.js +6 -11
  116. package/dist/ai/internal/mcpProtocol/v2024_11_05.js.map +1 -1
  117. package/dist/ai/internal/mcpProtocol/v2025_03_26.js +6 -11
  118. package/dist/ai/internal/mcpProtocol/v2025_03_26.js.map +1 -1
  119. package/dist/ai/internal/mcpProtocol/v2025_06_18.js +6 -8
  120. package/dist/ai/internal/mcpProtocol/v2025_06_18.js.map +1 -1
  121. package/dist/ai/internal/mcpProtocol/v2025_11_25.js +6 -8
  122. package/dist/ai/internal/mcpProtocol/v2025_11_25.js.map +1 -1
  123. package/dist/ai/internal/mcpProtocol/v2026_07_28.js +64 -54
  124. package/dist/ai/internal/mcpProtocol/v2026_07_28.js.map +1 -1
  125. package/dist/ai/internal/mcpProtocol.js +11 -1
  126. package/dist/ai/internal/mcpProtocol.js.map +1 -1
  127. package/dist/ai/internal/mcpProtocolRegistry.js +4 -0
  128. package/dist/ai/internal/mcpProtocolRegistry.js.map +1 -1
  129. package/dist/ai/internal/mcpRuntime.js +6 -2
  130. package/dist/ai/internal/mcpRuntime.js.map +1 -1
  131. package/dist/ai/internal/mcpSchema/v2024_11_05.js +0 -2
  132. package/dist/ai/internal/mcpSchema/v2024_11_05.js.map +1 -1
  133. package/dist/ai/internal/mcpSchema/v2025_03_26.d.ts.map +1 -1
  134. package/dist/ai/internal/mcpSchema/v2025_03_26.js +0 -2
  135. package/dist/ai/internal/mcpSchema/v2025_03_26.js.map +1 -1
  136. package/dist/ai/internal/mcpSchema/v2025_06_18.d.ts.map +1 -1
  137. package/dist/ai/internal/mcpSchema/v2025_06_18.js +0 -2
  138. package/dist/ai/internal/mcpSchema/v2025_06_18.js.map +1 -1
  139. package/dist/ai/internal/mcpSchema/v2025_11_25.d.ts.map +1 -1
  140. package/dist/ai/internal/mcpSchema/v2025_11_25.js +0 -2
  141. package/dist/ai/internal/mcpSchema/v2025_11_25.js.map +1 -1
  142. package/dist/ai/internal/mcpSchema/v2026_07_28.d.ts.map +1 -1
  143. package/dist/ai/internal/mcpSchema/v2026_07_28.js +0 -2
  144. package/dist/ai/internal/mcpSchema/v2026_07_28.js.map +1 -1
  145. package/dist/ai/internal/mcpSkills.js +3 -93
  146. package/dist/ai/internal/mcpSkills.js.map +1 -1
  147. package/dist/ai/internal/mcpStatefulRuntime.js +0 -2
  148. package/dist/ai/internal/mcpStatefulRuntime.js.map +1 -1
  149. package/dist/ai/internal/structured-output.js +12 -3
  150. package/dist/ai/internal/structured-output.js.map +1 -1
  151. package/dist/cli/Argument.d.ts +81 -0
  152. package/dist/cli/Argument.d.ts.map +1 -1
  153. package/dist/cli/Argument.js +26 -0
  154. package/dist/cli/Argument.js.map +1 -1
  155. package/dist/cli/CliError.d.ts +7 -4
  156. package/dist/cli/CliError.d.ts.map +1 -1
  157. package/dist/cli/CliError.js +7 -4
  158. package/dist/cli/CliError.js.map +1 -1
  159. package/dist/cli/Command.d.ts +241 -22
  160. package/dist/cli/Command.d.ts.map +1 -1
  161. package/dist/cli/Command.js +85 -9
  162. package/dist/cli/Command.js.map +1 -1
  163. package/dist/cli/CommandSpec.d.ts +287 -0
  164. package/dist/cli/CommandSpec.d.ts.map +1 -0
  165. package/dist/cli/CommandSpec.js +277 -0
  166. package/dist/cli/CommandSpec.js.map +1 -0
  167. package/dist/cli/Completions.d.ts +5 -0
  168. package/dist/cli/Completions.d.ts.map +1 -1
  169. package/dist/cli/Completions.js.map +1 -1
  170. package/dist/cli/Flag.d.ts +102 -0
  171. package/dist/cli/Flag.d.ts.map +1 -1
  172. package/dist/cli/Flag.js +47 -0
  173. package/dist/cli/Flag.js.map +1 -1
  174. package/dist/cli/Param.d.ts +154 -1
  175. package/dist/cli/Param.d.ts.map +1 -1
  176. package/dist/cli/Param.js +87 -29
  177. package/dist/cli/Param.js.map +1 -1
  178. package/dist/cli/index.d.ts +5 -0
  179. package/dist/cli/index.d.ts.map +1 -1
  180. package/dist/cli/index.js +5 -0
  181. package/dist/cli/index.js.map +1 -1
  182. package/dist/cli/internal/command.d.ts +2 -2
  183. package/dist/cli/internal/command.d.ts.map +1 -1
  184. package/dist/cli/internal/command.js +1 -1
  185. package/dist/cli/internal/command.js.map +1 -1
  186. package/dist/cli/internal/completions/bash.js +6 -7
  187. package/dist/cli/internal/completions/bash.js.map +1 -1
  188. package/dist/cli/internal/completions/descriptor.js +21 -7
  189. package/dist/cli/internal/completions/descriptor.js.map +1 -1
  190. package/dist/cli/internal/completions/fish.js +3 -3
  191. package/dist/cli/internal/completions/fish.js.map +1 -1
  192. package/dist/cli/internal/completions/powershell.js +2 -2
  193. package/dist/cli/internal/completions/powershell.js.map +1 -1
  194. package/dist/cli/internal/completions/zsh.js +2 -2
  195. package/dist/cli/internal/completions/zsh.js.map +1 -1
  196. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  197. package/dist/cluster/ClusterWorkflowEngine.js +31 -20
  198. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  199. package/dist/cluster/Entity.d.ts +43 -0
  200. package/dist/cluster/Entity.d.ts.map +1 -1
  201. package/dist/cluster/Entity.js +20 -0
  202. package/dist/cluster/Entity.js.map +1 -1
  203. package/dist/cluster/MessageRetention.d.ts +71 -0
  204. package/dist/cluster/MessageRetention.d.ts.map +1 -0
  205. package/dist/cluster/MessageRetention.js +100 -0
  206. package/dist/cluster/MessageRetention.js.map +1 -0
  207. package/dist/cluster/MessageStorage.d.ts +87 -6
  208. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  209. package/dist/cluster/MessageStorage.js +35 -5
  210. package/dist/cluster/MessageStorage.js.map +1 -1
  211. package/dist/cluster/Runners.d.ts.map +1 -1
  212. package/dist/cluster/Runners.js +13 -2
  213. package/dist/cluster/Runners.js.map +1 -1
  214. package/dist/cluster/Sharding.d.ts +13 -0
  215. package/dist/cluster/Sharding.d.ts.map +1 -1
  216. package/dist/cluster/Sharding.js.map +1 -1
  217. package/dist/cluster/ShardingConfig.d.ts +24 -2
  218. package/dist/cluster/ShardingConfig.d.ts.map +1 -1
  219. package/dist/cluster/ShardingConfig.js.map +1 -1
  220. package/dist/cluster/SqlMessageStorage.d.ts.map +1 -1
  221. package/dist/cluster/SqlMessageStorage.js +187 -29
  222. package/dist/cluster/SqlMessageStorage.js.map +1 -1
  223. package/dist/cluster/index.d.ts +5 -0
  224. package/dist/cluster/index.d.ts.map +1 -1
  225. package/dist/cluster/index.js +5 -0
  226. package/dist/cluster/index.js.map +1 -1
  227. package/dist/cluster/internal/clusterAbandon.d.ts.map +1 -1
  228. package/dist/cluster/internal/clusterAbandon.js +6 -4
  229. package/dist/cluster/internal/clusterAbandon.js.map +1 -1
  230. package/dist/cluster/internal/entityManager.js +48 -4
  231. package/dist/cluster/internal/entityManager.js.map +1 -1
  232. package/dist/cluster/internal/transactionNotifications.d.ts +5 -0
  233. package/dist/cluster/internal/transactionNotifications.d.ts.map +1 -0
  234. package/dist/cluster/internal/transactionNotifications.js +5 -0
  235. package/dist/cluster/internal/transactionNotifications.js.map +1 -0
  236. package/dist/encoding/Base64.d.ts +0 -6
  237. package/dist/encoding/Base64.d.ts.map +1 -1
  238. package/dist/encoding/Base64.js +25 -5
  239. package/dist/encoding/Base64.js.map +1 -1
  240. package/dist/encoding/Base64Url.d.ts +0 -6
  241. package/dist/encoding/Base64Url.d.ts.map +1 -1
  242. package/dist/encoding/Base64Url.js +91 -8
  243. package/dist/encoding/Base64Url.js.map +1 -1
  244. package/dist/encoding/Csv.d.ts.map +1 -1
  245. package/dist/encoding/Csv.js +11 -5
  246. package/dist/encoding/Csv.js.map +1 -1
  247. package/dist/encoding/Hex.d.ts.map +1 -1
  248. package/dist/encoding/Hex.js +51 -34
  249. package/dist/encoding/Hex.js.map +1 -1
  250. package/dist/encoding/Json5.d.ts +44 -0
  251. package/dist/encoding/Json5.d.ts.map +1 -0
  252. package/dist/encoding/Json5.js +56 -0
  253. package/dist/encoding/Json5.js.map +1 -0
  254. package/dist/encoding/Jsonc.d.ts +47 -0
  255. package/dist/encoding/Jsonc.d.ts.map +1 -0
  256. package/dist/encoding/Jsonc.js +120 -0
  257. package/dist/encoding/Jsonc.js.map +1 -0
  258. package/dist/encoding/SchemaBinary.d.ts +108 -2
  259. package/dist/encoding/SchemaBinary.d.ts.map +1 -1
  260. package/dist/encoding/SchemaBinary.js +297 -11
  261. package/dist/encoding/SchemaBinary.js.map +1 -1
  262. package/dist/encoding/Xml.d.ts +25 -0
  263. package/dist/encoding/Xml.d.ts.map +1 -1
  264. package/dist/encoding/Xml.js +44 -19
  265. package/dist/encoding/Xml.js.map +1 -1
  266. package/dist/encoding/index.d.ts +10 -0
  267. package/dist/encoding/index.d.ts.map +1 -1
  268. package/dist/encoding/index.js +10 -0
  269. package/dist/encoding/index.js.map +1 -1
  270. package/dist/eventlog/EventLogServer.d.ts.map +1 -1
  271. package/dist/eventlog/EventLogServer.js +28 -12
  272. package/dist/eventlog/EventLogServer.js.map +1 -1
  273. package/dist/graphql/GraphQL.d.ts.map +1 -1
  274. package/dist/graphql/GraphQL.js +4 -1
  275. package/dist/graphql/GraphQL.js.map +1 -1
  276. package/dist/http/Headers.d.ts +5 -1
  277. package/dist/http/Headers.d.ts.map +1 -1
  278. package/dist/http/Headers.js +7 -2
  279. package/dist/http/Headers.js.map +1 -1
  280. package/dist/http/HttpClient.d.ts +72 -21
  281. package/dist/http/HttpClient.d.ts.map +1 -1
  282. package/dist/http/HttpClient.js +105 -60
  283. package/dist/http/HttpClient.js.map +1 -1
  284. package/dist/http/HttpClientError.d.ts +22 -8
  285. package/dist/http/HttpClientError.d.ts.map +1 -1
  286. package/dist/http/HttpClientError.js +68 -14
  287. package/dist/http/HttpClientError.js.map +1 -1
  288. package/dist/http/HttpEffect.d.ts +63 -4
  289. package/dist/http/HttpEffect.d.ts.map +1 -1
  290. package/dist/http/HttpEffect.js +89 -9
  291. package/dist/http/HttpEffect.js.map +1 -1
  292. package/dist/http/HttpMiddleware.js +1 -1
  293. package/dist/http/HttpMiddleware.js.map +1 -1
  294. package/dist/http/HttpServer.d.ts +80 -0
  295. package/dist/http/HttpServer.d.ts.map +1 -1
  296. package/dist/http/HttpServer.js +16 -0
  297. package/dist/http/HttpServer.js.map +1 -1
  298. package/dist/http/HttpServerRequest.d.ts.map +1 -1
  299. package/dist/http/HttpServerRequest.js +1 -14
  300. package/dist/http/HttpServerRequest.js.map +1 -1
  301. package/dist/http/HttpStaticServer.js +10 -16
  302. package/dist/http/HttpStaticServer.js.map +1 -1
  303. package/dist/http-api/HttpApiBuilder.js +9 -1
  304. package/dist/http-api/HttpApiBuilder.js.map +1 -1
  305. package/dist/http-api/HttpApiSchema.d.ts +19 -0
  306. package/dist/http-api/HttpApiSchema.d.ts.map +1 -1
  307. package/dist/http-api/HttpApiSchema.js +8 -1
  308. package/dist/http-api/HttpApiSchema.js.map +1 -1
  309. package/dist/index.d.ts +5 -0
  310. package/dist/index.d.ts.map +1 -1
  311. package/dist/index.js +5 -0
  312. package/dist/index.js.map +1 -1
  313. package/dist/internal/base64.d.ts +2 -0
  314. package/dist/internal/base64.d.ts.map +1 -0
  315. package/dist/internal/base64.js +30 -0
  316. package/dist/internal/base64.js.map +1 -0
  317. package/dist/internal/core.js +3 -4
  318. package/dist/internal/core.js.map +1 -1
  319. package/dist/internal/dateTime.js +35 -13
  320. package/dist/internal/dateTime.js.map +1 -1
  321. package/dist/internal/effect.js +41 -17
  322. package/dist/internal/effect.js.map +1 -1
  323. package/dist/internal/equal.js +7 -0
  324. package/dist/internal/equal.js.map +1 -1
  325. package/dist/internal/jsonParser.d.ts +5 -0
  326. package/dist/internal/jsonParser.d.ts.map +1 -0
  327. package/dist/internal/jsonParser.js +280 -0
  328. package/dist/internal/jsonParser.js.map +1 -0
  329. package/dist/internal/matcher.js +1 -1
  330. package/dist/internal/matcher.js.map +1 -1
  331. package/dist/internal/persistence.js +8 -1
  332. package/dist/internal/persistence.js.map +1 -1
  333. package/dist/internal/schema/codegen.js +7 -7
  334. package/dist/internal/schema/codegen.js.map +1 -1
  335. package/dist/internal/schema/fromJsonSchemaDocument.js +20 -1
  336. package/dist/internal/schema/fromJsonSchemaDocument.js.map +1 -1
  337. package/dist/internal/schema/interpreter.js +10 -10
  338. package/dist/internal/schema/interpreter.js.map +1 -1
  339. package/dist/internal/schema/parser.js +9 -4
  340. package/dist/internal/schema/parser.js.map +1 -1
  341. package/dist/internal/schema/toEquivalence.js +6 -5
  342. package/dist/internal/schema/toEquivalence.js.map +1 -1
  343. package/dist/internal/schema/toFormatter.js +3 -2
  344. package/dist/internal/schema/toFormatter.js.map +1 -1
  345. package/dist/internal/sql.js +16 -0
  346. package/dist/internal/sql.js.map +1 -1
  347. package/dist/internal/version.js +1 -1
  348. package/dist/observability/OtlpExporter.d.ts +4 -0
  349. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  350. package/dist/observability/OtlpExporter.js +40 -12
  351. package/dist/observability/OtlpExporter.js.map +1 -1
  352. package/dist/observability/OtlpMetrics.js +1 -1
  353. package/dist/observability/OtlpMetrics.js.map +1 -1
  354. package/dist/observability/OtlpTracer.js +2 -2
  355. package/dist/observability/OtlpTracer.js.map +1 -1
  356. package/dist/persistence/PersistedQueue.d.ts +72 -3
  357. package/dist/persistence/PersistedQueue.d.ts.map +1 -1
  358. package/dist/persistence/PersistedQueue.js +142 -29
  359. package/dist/persistence/PersistedQueue.js.map +1 -1
  360. package/dist/persistence/RateLimiter.d.ts +19 -2
  361. package/dist/persistence/RateLimiter.d.ts.map +1 -1
  362. package/dist/persistence/RateLimiter.js +24 -8
  363. package/dist/persistence/RateLimiter.js.map +1 -1
  364. package/dist/process/CommandLine.d.ts +9 -9
  365. package/dist/process/CommandLine.js +6 -6
  366. package/dist/process/index.d.ts +1 -1
  367. package/dist/process/index.js +1 -1
  368. package/dist/reactivity/Atom.d.ts.map +1 -1
  369. package/dist/reactivity/Atom.js +24 -3
  370. package/dist/reactivity/Atom.js.map +1 -1
  371. package/dist/reactivity/AtomRpc.d.ts +24 -6
  372. package/dist/reactivity/AtomRpc.d.ts.map +1 -1
  373. package/dist/reactivity/AtomRpc.js.map +1 -1
  374. package/dist/rpc/OpenRpc.d.ts +384 -0
  375. package/dist/rpc/OpenRpc.d.ts.map +1 -0
  376. package/dist/rpc/OpenRpc.js +490 -0
  377. package/dist/rpc/OpenRpc.js.map +1 -0
  378. package/dist/rpc/Rpc.d.ts +22 -3
  379. package/dist/rpc/Rpc.d.ts.map +1 -1
  380. package/dist/rpc/Rpc.js.map +1 -1
  381. package/dist/rpc/RpcClient.d.ts +20 -21
  382. package/dist/rpc/RpcClient.d.ts.map +1 -1
  383. package/dist/rpc/RpcClient.js.map +1 -1
  384. package/dist/rpc/RpcServer.d.ts +23 -2
  385. package/dist/rpc/RpcServer.d.ts.map +1 -1
  386. package/dist/rpc/RpcServer.js +77 -26
  387. package/dist/rpc/RpcServer.js.map +1 -1
  388. package/dist/rpc/index.d.ts +5 -0
  389. package/dist/rpc/index.d.ts.map +1 -1
  390. package/dist/rpc/index.js +5 -0
  391. package/dist/rpc/index.js.map +1 -1
  392. package/dist/schema/SchemaCompiler/runtime.js +3 -2
  393. package/dist/schema/SchemaCompiler/runtime.js.map +1 -1
  394. package/dist/sql/SqlClient.d.ts +67 -6
  395. package/dist/sql/SqlClient.d.ts.map +1 -1
  396. package/dist/sql/SqlClient.js +98 -27
  397. package/dist/sql/SqlClient.js.map +1 -1
  398. package/dist/sql/Statement.d.ts +6 -1
  399. package/dist/sql/Statement.d.ts.map +1 -1
  400. package/dist/sql/Statement.js +17 -22
  401. package/dist/sql/Statement.js.map +1 -1
  402. package/dist/testing/TestClock.d.ts +2 -12
  403. package/dist/testing/TestClock.d.ts.map +1 -1
  404. package/dist/testing/TestClock.js +177 -169
  405. package/dist/testing/TestClock.js.map +1 -1
  406. package/dist/workflow/DurableClock.d.ts +27 -0
  407. package/dist/workflow/DurableClock.d.ts.map +1 -1
  408. package/dist/workflow/DurableClock.js +18 -2
  409. package/dist/workflow/DurableClock.js.map +1 -1
  410. package/dist/workflow/Workflow.d.ts.map +1 -1
  411. package/dist/workflow/Workflow.js +5 -4
  412. package/dist/workflow/Workflow.js.map +1 -1
  413. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  414. package/dist/workflow/WorkflowEngine.js +14 -3
  415. package/dist/workflow/WorkflowEngine.js.map +1 -1
  416. package/package.json +5 -5
  417. package/src/ByteSize.ts +29 -14
  418. package/src/DateTime.ts +35 -2
  419. package/src/Iterable.ts +20 -14
  420. package/src/JsonSchema.ts +45 -7
  421. package/src/Match.ts +10 -8
  422. package/src/MutableRef.ts +1 -8
  423. package/src/Queue.ts +16 -11
  424. package/src/Rational.ts +1549 -0
  425. package/src/RcMap.ts +16 -14
  426. package/src/Ref.ts +0 -8
  427. package/src/Runtime.ts +84 -4
  428. package/src/Schedule.ts +8 -6
  429. package/src/Schema.ts +188 -29
  430. package/src/SchemaAST.ts +29 -13
  431. package/src/SchemaParser.ts +2 -2
  432. package/src/SchemaRepresentation.ts +13 -0
  433. package/src/ScopedCache.ts +18 -1
  434. package/src/Stream.ts +6 -5
  435. package/src/ai/AgUi.ts +485 -0
  436. package/src/ai/AgUiSchema.ts +1666 -0
  437. package/src/ai/AgUiServer.ts +451 -0
  438. package/src/ai/Chat.ts +78 -16
  439. package/src/ai/LanguageModel.ts +27 -9
  440. package/src/ai/McpClient.ts +11 -1
  441. package/src/ai/McpServer.ts +287 -67
  442. package/src/ai/Prompt.ts +6 -2
  443. package/src/ai/Response.ts +19 -3
  444. package/src/ai/Tool.ts +426 -110
  445. package/src/ai/Toolkit.ts +71 -10
  446. package/src/ai/index.ts +18 -0
  447. package/src/ai/internal/mcpCore.ts +11 -15
  448. package/src/ai/internal/mcpProtocol/v2024_11_05.ts +9 -14
  449. package/src/ai/internal/mcpProtocol/v2025_03_26.ts +9 -14
  450. package/src/ai/internal/mcpProtocol/v2025_06_18.ts +9 -11
  451. package/src/ai/internal/mcpProtocol/v2025_11_25.ts +9 -11
  452. package/src/ai/internal/mcpProtocol/v2026_07_28.ts +80 -60
  453. package/src/ai/internal/mcpProtocol.ts +22 -3
  454. package/src/ai/internal/mcpProtocolRegistry.ts +5 -0
  455. package/src/ai/internal/mcpRuntime.ts +10 -4
  456. package/src/ai/internal/mcpSchema/v2024_11_05.ts +0 -2
  457. package/src/ai/internal/mcpSchema/v2025_03_26.ts +0 -2
  458. package/src/ai/internal/mcpSchema/v2025_06_18.ts +0 -2
  459. package/src/ai/internal/mcpSchema/v2025_11_25.ts +0 -2
  460. package/src/ai/internal/mcpSchema/v2026_07_28.ts +0 -2
  461. package/src/ai/internal/mcpSkills.ts +3 -86
  462. package/src/ai/internal/mcpStatefulRuntime.ts +0 -2
  463. package/src/ai/internal/structured-output.ts +11 -5
  464. package/src/cli/Argument.ts +86 -0
  465. package/src/cli/CliError.ts +7 -4
  466. package/src/cli/Command.ts +261 -35
  467. package/src/cli/CommandSpec.ts +508 -0
  468. package/src/cli/Completions.ts +5 -0
  469. package/src/cli/Flag.ts +106 -0
  470. package/src/cli/Param.ts +225 -23
  471. package/src/cli/index.ts +6 -0
  472. package/src/cli/internal/command.ts +3 -4
  473. package/src/cli/internal/completions/bash.ts +9 -7
  474. package/src/cli/internal/completions/descriptor.ts +37 -5
  475. package/src/cli/internal/completions/fish.ts +9 -3
  476. package/src/cli/internal/completions/powershell.ts +2 -1
  477. package/src/cli/internal/completions/zsh.ts +2 -2
  478. package/src/cluster/ClusterWorkflowEngine.ts +41 -41
  479. package/src/cluster/Entity.ts +76 -0
  480. package/src/cluster/MessageRetention.ts +111 -0
  481. package/src/cluster/MessageStorage.ts +76 -8
  482. package/src/cluster/Runners.ts +16 -2
  483. package/src/cluster/Sharding.ts +13 -0
  484. package/src/cluster/ShardingConfig.ts +12 -1
  485. package/src/cluster/SqlMessageStorage.ts +271 -41
  486. package/src/cluster/index.ts +6 -0
  487. package/src/cluster/internal/clusterAbandon.ts +7 -7
  488. package/src/cluster/internal/entityManager.ts +65 -5
  489. package/src/cluster/internal/transactionNotifications.ts +7 -0
  490. package/src/encoding/Base64.ts +26 -5
  491. package/src/encoding/Base64Url.ts +93 -10
  492. package/src/encoding/Csv.ts +11 -5
  493. package/src/encoding/Hex.ts +56 -42
  494. package/src/encoding/Json5.ts +59 -0
  495. package/src/encoding/Jsonc.ts +126 -0
  496. package/src/encoding/SchemaBinary.ts +304 -12
  497. package/src/encoding/Xml.ts +65 -16
  498. package/src/encoding/index.ts +12 -0
  499. package/src/eventlog/EventLogServer.ts +36 -12
  500. package/src/graphql/GraphQL.ts +7 -4
  501. package/src/http/Headers.ts +7 -2
  502. package/src/http/HttpClient.ts +147 -85
  503. package/src/http/HttpClientError.ts +82 -15
  504. package/src/http/HttpEffect.ts +101 -10
  505. package/src/http/HttpMiddleware.ts +2 -2
  506. package/src/http/HttpServer.ts +80 -0
  507. package/src/http/HttpServerRequest.ts +1 -19
  508. package/src/http/HttpStaticServer.ts +10 -16
  509. package/src/http-api/HttpApiBuilder.ts +11 -1
  510. package/src/http-api/HttpApiSchema.ts +22 -1
  511. package/src/index.ts +6 -0
  512. package/src/internal/base64.ts +42 -0
  513. package/src/internal/core.ts +3 -4
  514. package/src/internal/dateTime.ts +53 -16
  515. package/src/internal/effect.ts +45 -18
  516. package/src/internal/equal.ts +8 -0
  517. package/src/internal/jsonParser.ts +307 -0
  518. package/src/internal/matcher.ts +7 -3
  519. package/src/internal/persistence.ts +9 -1
  520. package/src/internal/schema/codegen.ts +8 -7
  521. package/src/internal/schema/fromJsonSchemaDocument.ts +21 -1
  522. package/src/internal/schema/interpreter.ts +10 -10
  523. package/src/internal/schema/parser.ts +8 -4
  524. package/src/internal/schema/toEquivalence.ts +7 -5
  525. package/src/internal/schema/toFormatter.ts +3 -2
  526. package/src/internal/sql.ts +25 -0
  527. package/src/internal/version.ts +1 -1
  528. package/src/observability/OtlpExporter.ts +42 -18
  529. package/src/observability/OtlpMetrics.ts +1 -1
  530. package/src/observability/OtlpTracer.ts +2 -2
  531. package/src/persistence/PersistedQueue.ts +199 -41
  532. package/src/persistence/RateLimiter.ts +30 -9
  533. package/src/process/CommandLine.ts +10 -10
  534. package/src/process/index.ts +1 -1
  535. package/src/reactivity/Atom.ts +25 -3
  536. package/src/reactivity/AtomRpc.ts +61 -45
  537. package/src/rpc/OpenRpc.ts +747 -0
  538. package/src/rpc/Rpc.ts +38 -6
  539. package/src/rpc/RpcClient.ts +45 -82
  540. package/src/rpc/RpcServer.ts +89 -29
  541. package/src/rpc/index.ts +6 -0
  542. package/src/schema/SchemaCompiler/runtime.ts +8 -3
  543. package/src/sql/SqlClient.ts +156 -36
  544. package/src/sql/Statement.ts +27 -36
  545. package/src/testing/TestClock.ts +204 -189
  546. package/src/workflow/DurableClock.ts +20 -3
  547. package/src/workflow/Workflow.ts +5 -3
  548. package/src/workflow/WorkflowEngine.ts +20 -5
@@ -13,6 +13,7 @@
13
13
  */
14
14
  import * as Arr from "../Array.ts"
15
15
  import * as Cause from "../Cause.ts"
16
+ import * as Clock from "../Clock.ts"
16
17
  import * as Context from "../Context.ts"
17
18
  import * as Digest from "../crypto/Digest.ts"
18
19
  import * as Data from "../Data.ts"
@@ -28,7 +29,9 @@ import { appendPreResponseHandlerUnsafe } from "../http/HttpEffect.ts"
28
29
  import * as HttpRouter from "../http/HttpRouter.ts"
29
30
  import * as HttpServerRequest from "../http/HttpServerRequest.ts"
30
31
  import * as HttpServerResponse from "../http/HttpServerResponse.ts"
32
+ import * as HttpTraceContext from "../http/HttpTraceContext.ts"
31
33
  import type * as JsonSchema from "../JsonSchema.ts"
34
+ import * as Latch from "../Latch.ts"
32
35
  import * as Layer from "../Layer.ts"
33
36
  import * as Option from "../Option.ts"
34
37
  import * as Predicate from "../Predicate.ts"
@@ -104,6 +107,7 @@ interface QueuedServerNotification {
104
107
  readonly delivered: Deferred.Deferred<void>
105
108
  readonly requestContext?: McpRequestContext["Service"] | undefined
106
109
  readonly requestHeaders?: Headers.Headers | undefined
110
+ readonly requestLiveness?: { active: boolean } | undefined
107
111
  }
108
112
 
109
113
  const internalState = new WeakMap<object, {
@@ -121,6 +125,10 @@ const RequestNotificationQueue = Context.Reference<Queue.Queue<QueuedServerNotif
121
125
  "effect/ai/McpServer/RequestNotificationQueue",
122
126
  { defaultValue: () => undefined }
123
127
  )
128
+ const RequestLiveness = Context.Reference<{ active: boolean } | undefined>(
129
+ "effect/ai/McpServer/RequestLiveness",
130
+ { defaultValue: () => undefined }
131
+ )
124
132
  // Progress and logs belong to the request that emitted them.
125
133
  const isRequestNotification = (notification: McpCore.ServerNotification) =>
126
134
  notification._tag === "Progress" || notification._tag === "LoggingMessage"
@@ -737,23 +745,48 @@ class MiddlewareImpl {
737
745
  }
738
746
  }
739
747
 
740
- // The innermost middleware comes first.
748
+ // The innermost middleware comes first. Each stack keeps its own order, and
749
+ // where that leaves the order open, stacks provided further outside, which come
750
+ // first in the context, run further outside. Stacks that order the same
751
+ // middleware both ways have no common order, so insertion order decides.
741
752
  const getMiddleware = (context: Context.Context<never>): ReadonlyArray<AnyMiddlewareFn> => {
742
- const stacks: Array<ReadonlyArray<AnyMiddlewareFn>> = []
743
- let maxLength = 0
744
- for (const [key, value] of context.mapUnsafe) {
745
- if (key.startsWith(middlewareKeyPrefix)) {
746
- stacks.push(value)
747
- maxLength = Math.max(maxLength, value.length)
753
+ // The middleware directly inside each middleware, and how many of those
754
+ // directly outside it are still unplaced.
755
+ const inners = new Map<AnyMiddlewareFn, Array<AnyMiddlewareFn>>()
756
+ const unplacedOuters = new Map<AnyMiddlewareFn, number>()
757
+ for (const [key, stack] of context.mapUnsafe) {
758
+ if (!key.startsWith(middlewareKeyPrefix)) continue
759
+ for (let i = stack.length - 1; i >= 0; i--) {
760
+ const fn = stack[i]
761
+ if (!inners.has(fn)) {
762
+ inners.set(fn, [])
763
+ unplacedOuters.set(fn, 0)
764
+ }
765
+ const outer = stack[i + 1]
766
+ if (outer !== undefined && outer !== fn) {
767
+ inners.get(outer)!.push(fn)
768
+ unplacedOuters.set(fn, unplacedOuters.get(fn)! + 1)
769
+ }
748
770
  }
749
771
  }
750
- const unique = new Set<AnyMiddlewareFn>()
751
- for (let i = maxLength - 1; i >= 0; i--) {
752
- for (const stack of stacks) {
753
- if (i < stack.length) unique.add(stack[i])
772
+ // Repeatedly places the first middleware with nothing left to place outside it.
773
+ const outermostFirst: Array<AnyMiddlewareFn> = []
774
+ while (unplacedOuters.size > 0) {
775
+ let next = unplacedOuters.keys().next().value!
776
+ for (const [fn, count] of unplacedOuters) {
777
+ if (count === 0) {
778
+ next = fn
779
+ break
780
+ }
781
+ }
782
+ unplacedOuters.delete(next)
783
+ outermostFirst.push(next)
784
+ for (const fn of inners.get(next)!) {
785
+ const count = unplacedOuters.get(fn)
786
+ if (count !== undefined) unplacedOuters.set(fn, count - 1)
754
787
  }
755
788
  }
756
- return Arr.fromIterable(unique).reverse()
789
+ return outermostFirst.reverse()
757
790
  }
758
791
 
759
792
  const isMcpError = (error: unknown): error is McpErrorBase =>
@@ -1092,6 +1125,7 @@ export class McpServer extends Context.Service<McpServer, {
1092
1125
  const queued: QueuedServerNotification = {
1093
1126
  notification,
1094
1127
  delivered,
1128
+ requestLiveness: Context.get(fiber.context, RequestLiveness),
1095
1129
  requestContext: Context.getOrUndefined(fiber.context, McpRequestContext),
1096
1130
  requestHeaders: Context.getOrUndefined(fiber.context, HttpServerRequest.HttpServerRequest)?.headers
1097
1131
  }
@@ -1208,8 +1242,8 @@ export class McpServer extends Context.Service<McpServer, {
1208
1242
  }),
1209
1243
  visible: visible("tools/list", options.tool.name),
1210
1244
  isVisible: isEnabled(options.annotations),
1211
- handle: (call, invocation) =>
1212
- invoke(options.handle(call.arguments), invocation, {
1245
+ handle: (call, invocation, beforeHandle) =>
1246
+ invoke(Effect.andThen(beforeHandle, () => options.handle(call.arguments)), invocation, {
1213
1247
  method: "tools/call",
1214
1248
  target: call.name,
1215
1249
  payload: call
@@ -1460,10 +1494,123 @@ const requestKey = (requestId: string | number): string => `${typeof requestId}:
1460
1494
  interface ActiveRequest {
1461
1495
  readonly requestId: RpcMessage.RequestId
1462
1496
  readonly prepared: McpRuntime.PreparedRequest
1497
+ readonly liveness: { active: boolean }
1463
1498
  readonly cancelled: boolean
1464
1499
  readonly httpPost: { expected: number } | undefined
1465
1500
  }
1466
1501
 
1502
+ // JSON-RPC errors caused by the request rather than the server: parse error,
1503
+ // invalid request, method not found, invalid params and resource not found.
1504
+ // Per the MCP semantic conventions they do not mark the server span as failed.
1505
+ const requestErrorCodes: ReadonlySet<number> = new Set([-32700, -32600, -32601, -32602, -32002])
1506
+
1507
+ // Only the W3C keys are read: other `_meta` members can carry protocol claims.
1508
+ const remoteParentSpan = (params: Readonly<Record<string, unknown>> | undefined): Tracer.ExternalSpan | undefined => {
1509
+ const meta = params?._meta
1510
+ if (!Predicate.isReadonlyObject(meta) || typeof meta.traceparent !== "string") {
1511
+ return undefined
1512
+ }
1513
+ return Option.getOrUndefined(HttpTraceContext.w3c(Headers.fromInput({ traceparent: meta.traceparent })))
1514
+ }
1515
+
1516
+ const requestSpanOptions = (
1517
+ method: string,
1518
+ request: RpcMessage.Request<Rpc.Any>,
1519
+ options: {
1520
+ readonly protocolVersion: string
1521
+ readonly networkTransport: string | undefined
1522
+ readonly sessionId: string | undefined
1523
+ readonly recordToolArguments: boolean
1524
+ }
1525
+ ): Tracer.SpanOptionsNoTrace & { readonly name: string } => {
1526
+ const params = Predicate.isReadonlyObject(request.payload)
1527
+ ? request.payload as Readonly<Record<string, unknown>>
1528
+ : undefined
1529
+ const attributes: Record<string, unknown> = {
1530
+ "mcp.method.name": method,
1531
+ "mcp.protocol.version": options.protocolVersion
1532
+ }
1533
+ if (request.isNotification !== true) attributes["jsonrpc.request.id"] = String(request.id)
1534
+ if (options.sessionId !== undefined) attributes["mcp.session.id"] = options.sessionId
1535
+ if (options.networkTransport !== undefined) attributes["network.transport"] = options.networkTransport
1536
+ let target: string | undefined
1537
+ switch (method) {
1538
+ case "tools/call": {
1539
+ attributes["gen_ai.operation.name"] = "execute_tool"
1540
+ if (typeof params?.name === "string") {
1541
+ target = params.name
1542
+ attributes["gen_ai.tool.name"] = target
1543
+ }
1544
+ if (options.recordToolArguments && params?.arguments !== undefined) {
1545
+ attributes["gen_ai.tool.call.arguments"] = Toolkit.stringifyToolArguments(params.arguments)
1546
+ }
1547
+ break
1548
+ }
1549
+ case "prompts/get": {
1550
+ if (typeof params?.name === "string") {
1551
+ target = params.name
1552
+ attributes["gen_ai.prompt.name"] = target
1553
+ }
1554
+ break
1555
+ }
1556
+ case "resources/read":
1557
+ case "resources/subscribe":
1558
+ case "resources/unsubscribe": {
1559
+ // Resource URIs can be unbounded and sensitive, so they stay out of the span name.
1560
+ if (typeof params?.uri === "string") attributes["mcp.resource.uri"] = params.uri
1561
+ break
1562
+ }
1563
+ }
1564
+ return {
1565
+ name: target === undefined ? method : `${method} ${target}`,
1566
+ kind: "server",
1567
+ attributes,
1568
+ parent: remoteParentSpan(params)
1569
+ }
1570
+ }
1571
+
1572
+ // The MCP span of the request being handled. Unlike `Tracer.ParentSpan`, it is
1573
+ // unset outside a request, so code that sends a response for a request can
1574
+ // tell whether that request has an MCP span.
1575
+ const CurrentRequestSpan = Context.Reference<Tracer.Span | undefined>("effect/ai/McpServer/CurrentRequestSpan", {
1576
+ defaultValue: () => undefined
1577
+ })
1578
+
1579
+ // Spans whose request was answered with an error response sent by `McpServer`
1580
+ // itself. That response, not the handler's exit, classifies the span.
1581
+ const errorResponseSpans = new WeakSet<Tracer.Span>()
1582
+
1583
+ const recordErrorResponse = (span: Tracer.Span, code: number) => {
1584
+ errorResponseSpans.add(span)
1585
+ span.attribute("rpc.status_code", String(code))
1586
+ span.attribute("error.type", String(code))
1587
+ }
1588
+
1589
+ const endRequestSpan = (span: Tracer.Span, method: string, exit: Exit.Exit<unknown, unknown>, endTime: bigint) => {
1590
+ if (errorResponseSpans.has(span)) {
1591
+ return span.end(endTime, exit)
1592
+ }
1593
+ if (Exit.isSuccess(exit)) {
1594
+ if (method === "tools/call" && Predicate.hasProperty(exit.value, "isError") && exit.value.isError === true) {
1595
+ span.attribute("error.type", "tool_error")
1596
+ }
1597
+ return span.end(endTime, exit)
1598
+ }
1599
+ // Interruptions and defects carry no JSON-RPC error. When one is answered
1600
+ // with an internal error, the response write records it on the span.
1601
+ const error = Cause.findErrorOption(exit.cause)
1602
+ if (Option.isNone(error) || !Predicate.hasProperty(error.value, "code") || typeof error.value.code !== "number") {
1603
+ return span.end(endTime, exit)
1604
+ }
1605
+ const code = error.value.code
1606
+ span.attribute("rpc.status_code", String(code))
1607
+ if (requestErrorCodes.has(code)) {
1608
+ return span.end(endTime, Exit.void)
1609
+ }
1610
+ span.attribute("error.type", String(code))
1611
+ span.end(endTime, exit)
1612
+ }
1613
+
1467
1614
  class McpClientKey extends Data.Class<{
1468
1615
  readonly clientId: number
1469
1616
  readonly profile: McpCore.NegotiatedProtocolProfile<string>
@@ -1557,6 +1704,14 @@ const normalizeCacheHints = (
1557
1704
  * runtime handles protocol lifecycle state and determines which clients receive
1558
1705
  * queued server notifications.
1559
1706
  *
1707
+ * Each request handled by the server runs in a server span that follows the
1708
+ * OpenTelemetry MCP semantic conventions. Spans are named after the JSON-RPC
1709
+ * method, with the tool or prompt name appended for `tools/call` and
1710
+ * `prompts/get` (for example `tools/call get_weather`). A W3C `traceparent` in
1711
+ * `params._meta` becomes the span's parent, and the transport span (such as
1712
+ * the HTTP server span) is linked. Tool arguments are recorded only when
1713
+ * `Toolkit.RecordToolArguments` is `true`.
1714
+ *
1560
1715
  * @stability unstable
1561
1716
  * @category running
1562
1717
  * @since 4.0.0
@@ -1617,14 +1772,56 @@ const runWithRuntime = Effect.fnUntraced(function*(
1617
1772
  const server = yield* McpServer
1618
1773
  const defaultLogLevel = yield* CurrentLogLevel
1619
1774
  const isHttp = transport === "http"
1775
+ const networkTransport = isHttp ? "tcp" : transport === "stdio" ? "pipe" : undefined
1776
+ // `RpcServer` tracing is disabled so that this span can follow the MCP
1777
+ // semantic conventions and continue the client's `_meta` trace. Wrapping the
1778
+ // request effect keeps the span on its lifecycle: it ends after the response
1779
+ // is written, or when the request is interrupted.
1780
+ const traceRequest = <X, E, R>(
1781
+ effect: Effect.Effect<X, E, R>,
1782
+ request: RpcMessage.Request<Rpc.Any>
1783
+ ): Effect.Effect<X, E, R> =>
1784
+ Effect.withFiber((fiber) => {
1785
+ const method = runtime.methodForInternalTag(request.tag)
1786
+ const { name, ...spanOptions } = requestSpanOptions(method, request, {
1787
+ protocolVersion: runtime.protocolForInternalTag(request.tag).protocolVersion,
1788
+ networkTransport,
1789
+ sessionId: isHttp
1790
+ ? Context.getOrUndefined(fiber.context, HttpServerRequest.HttpServerRequest)?.headers[MCP_SESSION_ID_HEADER]
1791
+ : undefined,
1792
+ recordToolArguments: fiber.getRef(Toolkit.RecordToolArguments)
1793
+ })
1794
+ const ambientParent = Context.getOrUndefined(fiber.context, Tracer.ParentSpan)
1795
+ return Effect.flatMap(
1796
+ Effect.makeSpan(name, {
1797
+ ...spanOptions,
1798
+ links: spanOptions.parent !== undefined && ambientParent !== undefined
1799
+ ? [{ span: ambientParent, attributes: {} }]
1800
+ : undefined
1801
+ }),
1802
+ (span) =>
1803
+ Effect.onExit(
1804
+ effect.pipe(
1805
+ Effect.provideService(Tracer.ParentSpan, span),
1806
+ Effect.provideService(CurrentRequestSpan, span)
1807
+ ),
1808
+ (exit) =>
1809
+ Effect.sync(() => endRequestSpan(span, method, exit, fiber.getRef(Clock.Clock).currentTimeNanosUnsafe()))
1810
+ )
1811
+ )
1812
+ })
1620
1813
  const clientStates = new Map<number, {
1621
1814
  protocol: McpProtocol.AnyProtocolAdapter
1622
1815
  profile: McpCore.NegotiatedProtocolProfile<string> | undefined
1623
1816
  sessionHeaders: Headers.Headers | undefined
1624
1817
  }>()
1625
1818
  const activeRequests = new Map<number, Map<string, ActiveRequest>>()
1819
+ // Stdio has a single client whose session ends with stdin, so one latch is
1820
+ // enough; built-in subscriptions complete on it while finite requests drain.
1821
+ const stdioEnd = transport === "stdio" ? Latch.makeUnsafe() : undefined
1626
1822
  const reverseRequestClients = new Map<string, Array<McpClientKey>>()
1627
1823
  const disconnectClient = (clientId: number) => {
1824
+ for (const request of activeRequests.get(clientId)?.values() ?? []) request.liveness.active = false
1628
1825
  activeRequests.delete(clientId)
1629
1826
  clientStates.delete(clientId)
1630
1827
  runtime.disconnect(clientId)
@@ -1687,6 +1884,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
1687
1884
  if (request === undefined) {
1688
1885
  return false
1689
1886
  }
1887
+ request.liveness.active = false
1690
1888
  requests!.set(key, { ...request, cancelled: true })
1691
1889
  return true
1692
1890
  }
@@ -1715,6 +1913,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
1715
1913
  getListChangeRevision: () => notificationDelivery.listChangeRevision,
1716
1914
  ...(!protocol.supportsNotifications || options.allowSubscriptions === false ? {} : {
1717
1915
  sendNotification,
1916
+ awaitClientEnd: stdioEnd?.await,
1718
1917
  markSubscriptionCancelled: (clientId: number, requestId: RpcMessage.RequestId) =>
1719
1918
  Effect.sync(() => {
1720
1919
  cancelRequest(clientId, requestId)
@@ -1854,6 +2053,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
1854
2053
  const requests = activeRequests.get(clientId)
1855
2054
  const key = requestKey(response.requestId)
1856
2055
  const active = requests?.get(key)
2056
+ if (active !== undefined) active.liveness.active = false
1857
2057
  if (requests !== undefined && requests.delete(key) && requests.size === 0) {
1858
2058
  activeRequests.delete(clientId)
1859
2059
  }
@@ -1870,7 +2070,12 @@ const runWithRuntime = Effect.fnUntraced(function*(
1870
2070
  return sendRequestError(clientId, response.requestId, {
1871
2071
  code: McpSchema.INTERNAL_ERROR_CODE,
1872
2072
  message: "Internal error"
1873
- })
2073
+ }).pipe(
2074
+ Effect.andThen(CurrentRequestSpan),
2075
+ Effect.map((span) => {
2076
+ if (span !== undefined) recordErrorResponse(span, McpSchema.INTERNAL_ERROR_CODE)
2077
+ })
2078
+ )
1874
2079
  }
1875
2080
  }
1876
2081
  return protocol.send(clientId, response)
@@ -2033,17 +2238,19 @@ const runWithRuntime = Effect.fnUntraced(function*(
2033
2238
  ? Effect.void
2034
2239
  : sendRequestError(clientId, request.id, new InvalidParams({ message: "Invalid method parameters" }))
2035
2240
  }
2241
+ const liveness = { active: true }
2036
2242
  if (request.isNotification !== true) {
2037
2243
  const requests = activeRequests.get(clientId) ?? new Map<string, ActiveRequest>()
2038
2244
  requests.set(requestKey(request.id), {
2039
2245
  requestId: RpcMessage.RequestId(request.id),
2040
2246
  prepared,
2247
+ liveness,
2041
2248
  cancelled: false,
2042
2249
  httpPost: httpRequest === undefined ? undefined : httpPostResponses.get(httpRequest)
2043
2250
  })
2044
2251
  activeRequests.set(clientId, requests)
2045
2252
  }
2046
- const handled = f(clientId, routedRequest)
2253
+ const handled = Effect.provideService(f(clientId, routedRequest), RequestLiveness, liveness)
2047
2254
  return yield* prepared.requestContext === undefined
2048
2255
  ? handled
2049
2256
  : Effect.provideService(handled, McpRequestContext, prepared.requestContext)
@@ -2067,6 +2274,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
2067
2274
  return f(clientId, request)
2068
2275
  case "Eof":
2069
2276
  if (!isHttp) {
2277
+ stdioEnd?.openUnsafe()
2070
2278
  disconnectClient(clientId)
2071
2279
  }
2072
2280
  return f(clientId, request)
@@ -2099,7 +2307,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
2099
2307
  const selectedProtocol = clientState?.protocol ?? runtime.protocols[0]
2100
2308
  const profile = reverseKey?.profile ?? clientState?.profile ?? {
2101
2309
  protocolVersion: selectedProtocol.protocolVersion,
2102
- clientCapabilities: {},
2310
+ clientCapabilities: new McpSchema.ClientCapabilities({}),
2103
2311
  clientInfo: { name: "unknown", version: "unknown" }
2104
2312
  }
2105
2313
  return RcMap.get(
@@ -2235,6 +2443,12 @@ const runWithRuntime = Effect.fnUntraced(function*(
2235
2443
  return
2236
2444
  }
2237
2445
  const encoded = yield* selectedProtocol.payloadCodecs(rpc).encode(projected.payload)
2446
+ // Projection and encoding can suspend after the request has ended.
2447
+ if (notification._tag === "Progress") {
2448
+ // The disconnect hook may still be scheduled when an interrupted handler resumes delivery.
2449
+ if (!(yield* patchedProtocol.clientIds).has(clientId)) return
2450
+ if (queued.requestLiveness?.active === false) return
2451
+ }
2238
2452
  yield* patchedProtocol.send(clientId, {
2239
2453
  _tag: "Request",
2240
2454
  id: "",
@@ -2263,8 +2477,12 @@ const runWithRuntime = Effect.fnUntraced(function*(
2263
2477
  )
2264
2478
 
2265
2479
  return yield* RpcServer.make(runtime.clientRpcs, {
2266
- spanPrefix: "McpServer",
2267
- disableFatalDefects: true
2480
+ disableTracing: true,
2481
+ disableFatalDefects: true,
2482
+ onDisconnect: (clientId) => Effect.sync(() => disconnectClient(clientId)),
2483
+ // Wrapped so `RpcServer.make` infers the group's rpcs from `clientRpcs`
2484
+ // rather than from `traceRequest`'s parameter type.
2485
+ onRequest: (effect, request) => traceRequest(effect, request)
2268
2486
  }).pipe(
2269
2487
  Effect.provideService(RpcServer.Protocol, patchedProtocol),
2270
2488
  Effect.provideService(McpServerClientMiddleware, clientMiddleware),
@@ -2321,6 +2539,9 @@ type RegistrationServices<RR> = Exclude<McpRequest.Without<RR>, McpServer>
2321
2539
  * `McpServer.layer`, so registration layers can use the `McpServer` service
2322
2540
  * while the server is running.
2323
2541
  *
2542
+ * Core lists return one complete page; supplying a cursor, including an empty
2543
+ * string, fails with `InvalidParams`.
2544
+ *
2324
2545
  * Pass registration layers as `registrations` to build them before the server
2325
2546
  * reads its first request. The transport discharges the request-level
2326
2547
  * dependencies it supplies (see `ProvidedServices`); any other `McpRequest`
@@ -2409,6 +2630,10 @@ const layerWithRuntime = (options: {
2409
2630
  * dependencies it supplies (see `ProvidedServices`); any other `McpRequest`
2410
2631
  * marker stays in the layer's requirements and must be met by MCP middleware.
2411
2632
  *
2633
+ * Each call builds its own `RpcServer.Protocol`, so several stdio servers can
2634
+ * live in one layer graph as long as each is provided its own `Stdio`. They
2635
+ * still share the memoized `McpServer` registry.
2636
+ *
2412
2637
  * @see {@link layer} for running over an existing `RpcServer.Protocol`
2413
2638
  * @see {@link layerHttp} for the single-endpoint HTTP transport
2414
2639
  *
@@ -2441,7 +2666,11 @@ export const layerStdio = <
2441
2666
  > =>
2442
2667
  layerWithRuntime(options, "stdio").pipe(
2443
2668
  Layer.provide(McpRuntime.layer(options.protocols)),
2444
- Layer.provide(RpcServer.layerProtocolStdio),
2669
+ // Build a fresh protocol layer per call. `RpcServer.layerProtocolStdio` is
2670
+ // a module-level constant, and layers are memoized by reference, so two
2671
+ // `layerStdio` servers in one layer graph would otherwise share a single
2672
+ // protocol bound to whichever `Stdio` was built first.
2673
+ Layer.provide(Layer.effect(RpcServer.Protocol, RpcServer.makeProtocolStdio)),
2445
2674
  Layer.provide(Layer.succeed(
2446
2675
  RpcSerialization.RpcSerialization,
2447
2676
  mcpStdioSerialization(options.protocols)
@@ -3081,40 +3310,33 @@ export const registerToolkit: <Tools extends Record<string, Tool.Any>>(
3081
3310
  const annotations = tool.annotations
3082
3311
  const toolMeta = Context.getOrUndefined(annotations, Tool.Meta)
3083
3312
  const isDeclaredFailure = Schema.is(tool.failureSchema)
3084
- const encodeFailure = Schema.encodeUnknownEffect(tool.failureSchema) as (
3085
- error: unknown
3313
+ // MCP content is JSON. Failures raised in "error" mode skip the Toolkit's encoding, so they use the JSON codec here.
3314
+ const encodeFailureJson = Schema.encodeUnknownEffect(Schema.toCodecJson(tool.failureSchema)) as (
3315
+ value: unknown
3086
3316
  ) => Effect.Effect<unknown, Schema.SchemaError, Tool.HandlerServices<Tools[keyof Tools]>>
3317
+ const encodeFailure = (toolResult: unknown) =>
3318
+ Effect.mapError(encodeFailureJson(toolResult), (cause) =>
3319
+ AiError.make({
3320
+ module: "McpServer",
3321
+ method: "registerToolkit",
3322
+ reason: new AiError.ToolResultEncodingError({
3323
+ toolName: tool.name,
3324
+ toolResult,
3325
+ description: cause.message
3326
+ })
3327
+ }))
3328
+ const failureResult = (encoded: unknown) =>
3329
+ new CallToolResult({ isError: true, content: toolResultContent(encoded) })
3087
3330
  const declaredFailureResult = (error: unknown) =>
3088
3331
  error instanceof Error && error.message !== ""
3089
3332
  ? Effect.succeed(toolErrorResult(error.message))
3090
- : Effect.map(encodeFailure(error), (encoded) =>
3091
- new CallToolResult({ isError: true, content: toolResultContent(encoded) }))
3092
- // `structuredContent` must be JSON and match the advertised `outputSchema`, which is derived from the JSON codec.
3093
- // The Toolkit has already encoded the result, so only the JSON conversion of its encoded form runs here.
3094
- const encodeStructured = Schema.encodeUnknownEffect(Schema.toCodecJson(Schema.toEncoded(tool.successSchema))) as (
3095
- result: unknown
3096
- ) => Effect.Effect<unknown, Schema.SchemaError, Tool.HandlerServices<Tools[keyof Tools]>>
3097
- const successResult = (result: unknown) =>
3098
- encodeStructured(result).pipe(
3099
- Effect.mapError((cause) =>
3100
- AiError.make({
3101
- module: "McpServer",
3102
- method: "registerToolkit",
3103
- reason: new AiError.ToolResultEncodingError({
3104
- toolName: tool.name,
3105
- toolResult: result,
3106
- description: cause.message
3107
- })
3108
- })
3109
- ),
3110
- Effect.map((structuredContent) =>
3111
- new CallToolResult({
3112
- isError: false,
3113
- structuredContent,
3114
- content: toolResultContent(structuredContent)
3115
- })
3116
- )
3117
- )
3333
+ : Effect.map(encodeFailure(error), failureResult)
3334
+ const successResult = (structuredContent: unknown) =>
3335
+ new CallToolResult({
3336
+ isError: false,
3337
+ structuredContent,
3338
+ content: toolResultContent(structuredContent)
3339
+ })
3118
3340
  const handleCause = (cause: Cause.Cause<unknown>) => {
3119
3341
  const failure = Cause.findFail(cause)
3120
3342
  if (Result.isSuccess(failure)) {
@@ -3175,17 +3397,18 @@ export const registerToolkit: <Tools extends Record<string, Tool.Any>>(
3175
3397
  unknown,
3176
3398
  Tool.HandlerServices<Tools[keyof Tools]>
3177
3399
  > => {
3400
+ // The Toolkit encodes successes and "return"-mode failures with their JSON codec.
3178
3401
  if (!result.isFailure) {
3179
3402
  // An absent result, such as `Schema.Void`, has no structured form.
3180
- return result.encodedResult === undefined
3181
- ? Effect.succeed(new CallToolResult({ isError: false, content: [] }))
3182
- : successResult(result.encodedResult)
3403
+ return Effect.succeed(
3404
+ result.result === undefined
3405
+ ? new CallToolResult({ isError: false, content: [] })
3406
+ : successResult(result.encodedResult)
3407
+ )
3183
3408
  }
3184
3409
  // Declared failures return their encoded payload; anything else is classified by origin.
3185
3410
  return result.failureOrigin === "handler"
3186
- ? Effect.succeed(
3187
- new CallToolResult({ isError: true, content: toolResultContent(result.encodedResult) })
3188
- )
3411
+ ? Effect.succeed(failureResult(result.encodedResult))
3189
3412
  : Effect.failCause(Cause.annotate(
3190
3413
  Cause.fail(result.result),
3191
3414
  Context.make(Toolkit.FailureOrigin, result.failureOrigin ?? "result")
@@ -3463,7 +3686,7 @@ export const registerResource: {
3463
3686
  }),
3464
3687
  services,
3465
3688
  handle: options.content.pipe(
3466
- Effect.map((content) => resolveResourceContent(options.uri, content)),
3689
+ Effect.map((content) => resolveResourceContent(options.uri, options.mimeType, content)),
3467
3690
  Effect.catchCause(handlerFailureToInternalError)
3468
3691
  ),
3469
3692
  annotations: options.annotations ?? Context.empty()
@@ -3527,7 +3750,7 @@ export const registerResource: {
3527
3750
  Effect.mapError((error) => new InvalidParams({ message: error.message })),
3528
3751
  Effect.flatMap((params: any) =>
3529
3752
  options.content(uri, ...params).pipe(
3530
- Effect.map((content) => resolveResourceContent(uri, content)),
3753
+ Effect.map((content) => resolveResourceContent(uri, options.mimeType, content)),
3531
3754
  Effect.catchCause(handlerFailureToInternalError)
3532
3755
  )
3533
3756
  )
@@ -3688,7 +3911,9 @@ const toSkillSourceFile = (path: string, file: SkillFile): McpSkills.SourceFile
3688
3911
  * `skills/list` and `skills/get` with a manifest of every file's SHA-256
3689
3912
  * digest and size, computed from the bytes served. Every directory of the
3690
3913
  * skill namespace is readable with `resources/directory/read`. The server
3691
- * declares the extension once any skill is registered.
3914
+ * declares the extension on protocol 2026-07-28 once any skill is registered.
3915
+ * Earlier revisions neither declare it nor answer its methods, but still serve
3916
+ * the skill's files through `resources/read`.
3692
3917
  *
3693
3918
  * Fails when the skill breaks the extension's rules: a name that does not
3694
3919
  * match the URI, a `SKILL.md` without YAML frontmatter, frontmatter that is
@@ -4053,21 +4278,16 @@ const compileUriTemplate = (segments: TemplateStringsArray, ...schemas: Readonly
4053
4278
 
4054
4279
  const resolveResourceContent = (
4055
4280
  uri: string,
4281
+ mimeType: string | undefined,
4056
4282
  content: ReadResourceResult | string | Uint8Array
4057
4283
  ): ReadResourceResult => {
4058
4284
  if (typeof content === "string") {
4059
4285
  return {
4060
- contents: [{
4061
- uri,
4062
- text: content
4063
- }]
4286
+ contents: [mimeType === undefined ? { uri, text: content } : { uri, mimeType, text: content }]
4064
4287
  }
4065
4288
  } else if (content instanceof Uint8Array) {
4066
4289
  return {
4067
- contents: [{
4068
- uri,
4069
- blob: content
4070
- }]
4290
+ contents: [mimeType === undefined ? { uri, blob: content } : { uri, mimeType, blob: content }]
4071
4291
  }
4072
4292
  }
4073
4293
  return content
package/src/ai/Prompt.ts CHANGED
@@ -788,7 +788,9 @@ export interface ToolResultPart extends BasePart<"tool-result", ToolResultPartOp
788
788
  */
789
789
  readonly isFailure: boolean
790
790
  /**
791
- * The result returned by the tool execution.
791
+ * The result returned by the tool execution. Results of locally handled
792
+ * tools hold their JSON encoding; provider-executed tools keep the
793
+ * provider's payload.
792
794
  */
793
795
  readonly result: unknown
794
796
  /**
@@ -822,7 +824,9 @@ export interface ToolResultPartEncoded extends BasePartEncoded<"tool-result", To
822
824
  */
823
825
  readonly isFailure: boolean
824
826
  /**
825
- * The result returned by the tool execution.
827
+ * The result returned by the tool execution. Results of locally handled
828
+ * tools hold their JSON encoding; provider-executed tools keep the
829
+ * provider's payload.
826
830
  */
827
831
  readonly result: unknown
828
832
  /**
@@ -162,9 +162,15 @@ const toolPartSchemaCache = new WeakMap<Tool.Any, {
162
162
  const toolPartSchemas = (tool: Tool.Any) => {
163
163
  let parts = toolPartSchemaCache.get(tool)
164
164
  if (parts === undefined) {
165
+ // Provider-executed tools keep the provider's payload; locally handled
166
+ // tools carry the JSON encoding of their results, as the Toolkit produces.
167
+ const hasProviderResults = Tool.isProviderDefined(tool) && !tool.requiresHandler
168
+ const failure = Tool.failureResultSchema(tool)
165
169
  parts = {
166
170
  toolCall: ToolCallPart(tool.name, tool.parametersSchema),
167
- toolResult: ToolResultPart(tool.name, tool.successSchema, Tool.failureResultSchema(tool))
171
+ toolResult: hasProviderResults
172
+ ? ToolResultPart(tool.name, tool.successSchema, failure)
173
+ : ToolResultPart(tool.name, Schema.toCodecJson(tool.successSchema), Schema.toCodecJson(failure))
168
174
  }
169
175
  toolPartSchemaCache.set(tool, parts)
170
176
  }
@@ -599,12 +605,20 @@ type ToolCallPartForName<
599
605
  Name extends keyof Tools
600
606
  > = Name extends string ? ToolCallPart<
601
607
  Name,
602
- ParametersMode extends "encoded" ? Tool.ParametersEncoded<Tools[Name]>
608
+ ParametersMode extends "encoded" ? ToolCallParametersEncoded<Tools[Name]>
603
609
  : ParametersMode extends "opaque" ? unknown
604
610
  : Tool.Parameters<Tools[Name]>
605
611
  >
606
612
  : never
607
613
 
614
+ // Provider-executed tools keep the provider's payload; locally handled tool
615
+ // calls carry the JSON encoding of their parameters. Distributes over a
616
+ // non-literal handler flag, which may be either at runtime.
617
+ type ToolCallParametersEncoded<T extends Tool.Any> = T extends
618
+ Tool.ProviderDefined<any, any, any, infer RequiresHandler, any>
619
+ ? RequiresHandler extends true ? Schema.Json : Tool.ParametersEncoded<T>
620
+ : Schema.Json
621
+
608
622
  /**
609
623
  * Utility type that extracts tool result parts from a set of tools.
610
624
  *
@@ -1705,7 +1719,9 @@ export interface BaseToolResult<Name extends string> extends BasePart<"tool-resu
1705
1719
  */
1706
1720
  readonly name: Name
1707
1721
  /**
1708
- * The encoded result for serialization purposes.
1722
+ * The encoded result for serialization purposes. Results of locally handled
1723
+ * tools hold their JSON encoding; provider-executed tools keep the
1724
+ * provider's payload.
1709
1725
  */
1710
1726
  readonly encodedResult: unknown
1711
1727
  /**