effect 4.0.3 → 4.0.5

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 (449) hide show
  1. package/AGENTS.md +24 -0
  2. package/CLAUDE.md +24 -0
  3. package/ai-docs/package.json +2 -2
  4. package/ai-docs/src/52_graphql/10_basics.ts +117 -0
  5. package/ai-docs/src/52_graphql/20_testing.ts +45 -0
  6. package/ai-docs/src/52_graphql/30_batching.ts +118 -0
  7. package/ai-docs/src/52_graphql/40_aliased-batching.ts +124 -0
  8. package/ai-docs/src/52_graphql/50_errors-and-retries.ts +74 -0
  9. package/ai-docs/src/52_graphql/index.md +6 -0
  10. package/dist/Array.d.ts +90 -6
  11. package/dist/Array.d.ts.map +1 -1
  12. package/dist/Array.js +4 -2
  13. package/dist/Array.js.map +1 -1
  14. package/dist/Channel.d.ts +6 -1
  15. package/dist/Channel.d.ts.map +1 -1
  16. package/dist/Channel.js +17 -3
  17. package/dist/Channel.js.map +1 -1
  18. package/dist/ConfigProvider.d.ts.map +1 -1
  19. package/dist/ConfigProvider.js +33 -32
  20. package/dist/ConfigProvider.js.map +1 -1
  21. package/dist/Context.d.ts.map +1 -1
  22. package/dist/Context.js +9 -0
  23. package/dist/Context.js.map +1 -1
  24. package/dist/Duration.d.ts.map +1 -1
  25. package/dist/Duration.js +2 -5
  26. package/dist/Duration.js.map +1 -1
  27. package/dist/Effect.d.ts +61 -19
  28. package/dist/Effect.d.ts.map +1 -1
  29. package/dist/Effect.js +58 -39
  30. package/dist/Effect.js.map +1 -1
  31. package/dist/FileSystem.d.ts +23 -9
  32. package/dist/FileSystem.d.ts.map +1 -1
  33. package/dist/FileSystem.js.map +1 -1
  34. package/dist/Match.d.ts +20 -6
  35. package/dist/Match.d.ts.map +1 -1
  36. package/dist/Match.js +2 -2
  37. package/dist/Match.js.map +1 -1
  38. package/dist/Path.d.ts +37 -5
  39. package/dist/Path.d.ts.map +1 -1
  40. package/dist/Path.js +36 -5
  41. package/dist/Path.js.map +1 -1
  42. package/dist/RequestResolver.d.ts.map +1 -1
  43. package/dist/RequestResolver.js +4 -10
  44. package/dist/RequestResolver.js.map +1 -1
  45. package/dist/Scheduler.d.ts +9 -0
  46. package/dist/Scheduler.d.ts.map +1 -1
  47. package/dist/Scheduler.js +9 -0
  48. package/dist/Scheduler.js.map +1 -1
  49. package/dist/Schema.d.ts +15 -2
  50. package/dist/Schema.d.ts.map +1 -1
  51. package/dist/Schema.js +16 -2
  52. package/dist/Schema.js.map +1 -1
  53. package/dist/SchemaGetter.d.ts +4 -0
  54. package/dist/SchemaGetter.d.ts.map +1 -1
  55. package/dist/SchemaGetter.js +52 -33
  56. package/dist/SchemaGetter.js.map +1 -1
  57. package/dist/Sink.d.ts.map +1 -1
  58. package/dist/Sink.js +38 -17
  59. package/dist/Sink.js.map +1 -1
  60. package/dist/Stream.d.ts +11 -0
  61. package/dist/Stream.d.ts.map +1 -1
  62. package/dist/Stream.js +16 -1
  63. package/dist/Stream.js.map +1 -1
  64. package/dist/String.d.ts +12 -0
  65. package/dist/String.d.ts.map +1 -1
  66. package/dist/String.js +17 -4
  67. package/dist/String.js.map +1 -1
  68. package/dist/TxRef.d.ts.map +1 -1
  69. package/dist/TxRef.js +3 -2
  70. package/dist/TxRef.js.map +1 -1
  71. package/dist/Utils.js +8 -3
  72. package/dist/Utils.js.map +1 -1
  73. package/dist/ai/AiError.d.ts +10 -10
  74. package/dist/ai/AiError.d.ts.map +1 -1
  75. package/dist/ai/AiError.js +1 -1
  76. package/dist/ai/AiError.js.map +1 -1
  77. package/dist/ai/AnthropicStructuredOutput.js +0 -2
  78. package/dist/ai/AnthropicStructuredOutput.js.map +1 -1
  79. package/dist/ai/Chat.d.ts +2 -2
  80. package/dist/ai/Chat.d.ts.map +1 -1
  81. package/dist/ai/Decision.d.ts +70 -19
  82. package/dist/ai/Decision.d.ts.map +1 -1
  83. package/dist/ai/Decision.js +37 -3
  84. package/dist/ai/Decision.js.map +1 -1
  85. package/dist/ai/DecisionModel.js +1 -1
  86. package/dist/ai/DecisionModel.js.map +1 -1
  87. package/dist/ai/LanguageModel.d.ts +38 -7
  88. package/dist/ai/LanguageModel.d.ts.map +1 -1
  89. package/dist/ai/LanguageModel.js +70 -40
  90. package/dist/ai/LanguageModel.js.map +1 -1
  91. package/dist/ai/McpServer.d.ts +61 -52
  92. package/dist/ai/McpServer.d.ts.map +1 -1
  93. package/dist/ai/McpServer.js +134 -50
  94. package/dist/ai/McpServer.js.map +1 -1
  95. package/dist/ai/Prompt.d.ts.map +1 -1
  96. package/dist/ai/Prompt.js +28 -5
  97. package/dist/ai/Prompt.js.map +1 -1
  98. package/dist/ai/Response.d.ts +5 -4
  99. package/dist/ai/Response.d.ts.map +1 -1
  100. package/dist/ai/Response.js.map +1 -1
  101. package/dist/cli/Completions.d.ts +5 -0
  102. package/dist/cli/Completions.d.ts.map +1 -1
  103. package/dist/cli/Completions.js.map +1 -1
  104. package/dist/cli/Flag.d.ts +100 -0
  105. package/dist/cli/Flag.d.ts.map +1 -1
  106. package/dist/cli/Flag.js +33 -0
  107. package/dist/cli/Flag.js.map +1 -1
  108. package/dist/cli/Param.d.ts +87 -0
  109. package/dist/cli/Param.d.ts.map +1 -1
  110. package/dist/cli/Param.js +30 -0
  111. package/dist/cli/Param.js.map +1 -1
  112. package/dist/cli/internal/command.d.ts.map +1 -1
  113. package/dist/cli/internal/command.js +2 -1
  114. package/dist/cli/internal/command.js.map +1 -1
  115. package/dist/cli/internal/completions/bash.js +4 -3
  116. package/dist/cli/internal/completions/bash.js.map +1 -1
  117. package/dist/cli/internal/completions/descriptor.js +8 -1
  118. package/dist/cli/internal/completions/descriptor.js.map +1 -1
  119. package/dist/cli/internal/completions/fish.js +4 -4
  120. package/dist/cli/internal/completions/fish.js.map +1 -1
  121. package/dist/cli/internal/completions/powershell.js +3 -2
  122. package/dist/cli/internal/completions/powershell.js.map +1 -1
  123. package/dist/cli/internal/completions/zsh.js +7 -3
  124. package/dist/cli/internal/completions/zsh.js.map +1 -1
  125. package/dist/cli/internal/parser.js +11 -3
  126. package/dist/cli/internal/parser.js.map +1 -1
  127. package/dist/cli/internal/wizard.d.ts.map +1 -1
  128. package/dist/cli/internal/wizard.js +2 -1
  129. package/dist/cli/internal/wizard.js.map +1 -1
  130. package/dist/cluster/ClusterWorkflowEngine.d.ts +1 -0
  131. package/dist/cluster/ClusterWorkflowEngine.d.ts.map +1 -1
  132. package/dist/cluster/ClusterWorkflowEngine.js +113 -21
  133. package/dist/cluster/ClusterWorkflowEngine.js.map +1 -1
  134. package/dist/cluster/MessageStorage.d.ts.map +1 -1
  135. package/dist/cluster/MessageStorage.js +20 -12
  136. package/dist/cluster/MessageStorage.js.map +1 -1
  137. package/dist/cluster/Runners.d.ts.map +1 -1
  138. package/dist/cluster/Runners.js +54 -34
  139. package/dist/cluster/Runners.js.map +1 -1
  140. package/dist/cluster/Sharding.d.ts.map +1 -1
  141. package/dist/cluster/Sharding.js +6 -4
  142. package/dist/cluster/Sharding.js.map +1 -1
  143. package/dist/cluster/internal/entityManager.js +1 -1
  144. package/dist/cluster/internal/entityManager.js.map +1 -1
  145. package/dist/encoding/Sse.d.ts +6 -0
  146. package/dist/encoding/Sse.d.ts.map +1 -1
  147. package/dist/encoding/Sse.js +63 -71
  148. package/dist/encoding/Sse.js.map +1 -1
  149. package/dist/graphql/GraphQL.d.ts +349 -0
  150. package/dist/graphql/GraphQL.d.ts.map +1 -0
  151. package/dist/graphql/GraphQL.js +207 -0
  152. package/dist/graphql/GraphQL.js.map +1 -0
  153. package/dist/graphql/GraphQLClient.d.ts +562 -0
  154. package/dist/graphql/GraphQLClient.d.ts.map +1 -0
  155. package/dist/graphql/GraphQLClient.js +505 -0
  156. package/dist/graphql/GraphQLClient.js.map +1 -0
  157. package/dist/graphql/GraphQLClientError.d.ts +445 -0
  158. package/dist/graphql/GraphQLClientError.d.ts.map +1 -0
  159. package/dist/graphql/GraphQLClientError.js +479 -0
  160. package/dist/graphql/GraphQLClientError.js.map +1 -0
  161. package/dist/graphql/GraphQLGroup.d.ts +118 -0
  162. package/dist/graphql/GraphQLGroup.d.ts.map +1 -0
  163. package/dist/graphql/GraphQLGroup.js +109 -0
  164. package/dist/graphql/GraphQLGroup.js.map +1 -0
  165. package/dist/graphql/GraphQLMiddleware.d.ts +249 -0
  166. package/dist/graphql/GraphQLMiddleware.d.ts.map +1 -0
  167. package/dist/graphql/GraphQLMiddleware.js +130 -0
  168. package/dist/graphql/GraphQLMiddleware.js.map +1 -0
  169. package/dist/graphql/GraphQLProtocol.d.ts +969 -0
  170. package/dist/graphql/GraphQLProtocol.d.ts.map +1 -0
  171. package/dist/graphql/GraphQLProtocol.js +809 -0
  172. package/dist/graphql/GraphQLProtocol.js.map +1 -0
  173. package/dist/graphql/GraphQLResolver.d.ts +453 -0
  174. package/dist/graphql/GraphQLResolver.d.ts.map +1 -0
  175. package/dist/graphql/GraphQLResolver.js +582 -0
  176. package/dist/graphql/GraphQLResolver.js.map +1 -0
  177. package/dist/graphql/index.d.ts +40 -0
  178. package/dist/graphql/index.d.ts.map +1 -0
  179. package/dist/graphql/index.js +41 -0
  180. package/dist/graphql/index.js.map +1 -0
  181. package/dist/http/FetchHttpClient.d.ts +6 -3
  182. package/dist/http/FetchHttpClient.d.ts.map +1 -1
  183. package/dist/http/FetchHttpClient.js +6 -3
  184. package/dist/http/FetchHttpClient.js.map +1 -1
  185. package/dist/http/FindMyWay/internal/router.js +2 -1
  186. package/dist/http/FindMyWay/internal/router.js.map +1 -1
  187. package/dist/http/Headers.d.ts +3 -3
  188. package/dist/http/Headers.d.ts.map +1 -1
  189. package/dist/http/Headers.js +6 -5
  190. package/dist/http/Headers.js.map +1 -1
  191. package/dist/http/HttpClient.d.ts +27 -0
  192. package/dist/http/HttpClient.d.ts.map +1 -1
  193. package/dist/http/HttpClient.js +38 -11
  194. package/dist/http/HttpClient.js.map +1 -1
  195. package/dist/http/HttpClientError.d.ts.map +1 -1
  196. package/dist/http/HttpClientError.js +8 -6
  197. package/dist/http/HttpClientError.js.map +1 -1
  198. package/dist/http/HttpClientRequest.d.ts +147 -4
  199. package/dist/http/HttpClientRequest.d.ts.map +1 -1
  200. package/dist/http/HttpClientRequest.js +47 -1
  201. package/dist/http/HttpClientRequest.js.map +1 -1
  202. package/dist/http/HttpEffect.d.ts.map +1 -1
  203. package/dist/http/HttpEffect.js +14 -7
  204. package/dist/http/HttpEffect.js.map +1 -1
  205. package/dist/http/HttpMiddleware.d.ts +60 -0
  206. package/dist/http/HttpMiddleware.d.ts.map +1 -1
  207. package/dist/http/HttpMiddleware.js +93 -32
  208. package/dist/http/HttpMiddleware.js.map +1 -1
  209. package/dist/http/HttpRouter.d.ts +35 -0
  210. package/dist/http/HttpRouter.d.ts.map +1 -1
  211. package/dist/http/HttpRouter.js +87 -13
  212. package/dist/http/HttpRouter.js.map +1 -1
  213. package/dist/http/HttpServerError.d.ts.map +1 -1
  214. package/dist/http/HttpServerError.js +6 -4
  215. package/dist/http/HttpServerError.js.map +1 -1
  216. package/dist/http/HttpServerRequest.js +2 -2
  217. package/dist/http/HttpServerRequest.js.map +1 -1
  218. package/dist/http/HttpServerResponse.d.ts +8 -6
  219. package/dist/http/HttpServerResponse.d.ts.map +1 -1
  220. package/dist/http/HttpServerResponse.js +27 -16
  221. package/dist/http/HttpServerResponse.js.map +1 -1
  222. package/dist/http/HttpStaticServer.d.ts.map +1 -1
  223. package/dist/http/HttpStaticServer.js +4 -10
  224. package/dist/http/HttpStaticServer.js.map +1 -1
  225. package/dist/http/HttpTraceContext.js +1 -1
  226. package/dist/http/HttpTraceContext.js.map +1 -1
  227. package/dist/http/Multipart.d.ts.map +1 -1
  228. package/dist/http/Multipart.js +15 -1
  229. package/dist/http/Multipart.js.map +1 -1
  230. package/dist/http/Url.d.ts.map +1 -1
  231. package/dist/http/Url.js +2 -1
  232. package/dist/http/Url.js.map +1 -1
  233. package/dist/http/UrlParams.d.ts +112 -8
  234. package/dist/http/UrlParams.d.ts.map +1 -1
  235. package/dist/http/UrlParams.js +141 -14
  236. package/dist/http/UrlParams.js.map +1 -1
  237. package/dist/http/internal/compression.d.ts +1 -1
  238. package/dist/http/internal/compression.d.ts.map +1 -1
  239. package/dist/http/internal/compression.js +2 -10
  240. package/dist/http/internal/compression.js.map +1 -1
  241. package/dist/http/internal/compressionBody.d.ts +2 -0
  242. package/dist/http/internal/compressionBody.d.ts.map +1 -0
  243. package/dist/http/internal/compressionBody.js +36 -0
  244. package/dist/http/internal/compressionBody.js.map +1 -0
  245. package/dist/http/internal/decompression.d.ts +2 -0
  246. package/dist/http/internal/decompression.d.ts.map +1 -0
  247. package/dist/http/internal/decompression.js +162 -0
  248. package/dist/http/internal/decompression.js.map +1 -0
  249. package/dist/http/internal/tracing.js +14 -4
  250. package/dist/http/internal/tracing.js.map +1 -1
  251. package/dist/http/internal/urlParams.d.ts +2 -0
  252. package/dist/http/internal/urlParams.d.ts.map +1 -0
  253. package/dist/http/internal/urlParams.js +4 -0
  254. package/dist/http/internal/urlParams.js.map +1 -0
  255. package/dist/http-api/HttpApiClient.d.ts.map +1 -1
  256. package/dist/http-api/HttpApiClient.js +2 -1
  257. package/dist/http-api/HttpApiClient.js.map +1 -1
  258. package/dist/http-api/HttpApiScalar.d.ts +5 -0
  259. package/dist/http-api/HttpApiScalar.d.ts.map +1 -1
  260. package/dist/http-api/HttpApiScalar.js.map +1 -1
  261. package/dist/internal/core.js +17 -1
  262. package/dist/internal/core.js.map +1 -1
  263. package/dist/internal/dateTime.js +40 -35
  264. package/dist/internal/dateTime.js.map +1 -1
  265. package/dist/internal/effect.js +13 -6
  266. package/dist/internal/effect.js.map +1 -1
  267. package/dist/internal/graphql.d.ts +2 -0
  268. package/dist/internal/graphql.d.ts.map +1 -0
  269. package/dist/internal/graphql.js +205 -0
  270. package/dist/internal/graphql.js.map +1 -0
  271. package/dist/internal/graphqlHeaders.d.ts +4 -0
  272. package/dist/internal/graphqlHeaders.d.ts.map +1 -0
  273. package/dist/internal/graphqlHeaders.js +11 -0
  274. package/dist/internal/graphqlHeaders.js.map +1 -0
  275. package/dist/internal/request.js +20 -1
  276. package/dist/internal/request.js.map +1 -1
  277. package/dist/internal/schema/toCodeDocument.js +4 -1
  278. package/dist/internal/schema/toCodeDocument.js.map +1 -1
  279. package/dist/internal/schema/toJsonSchemaDocument.js +29 -5
  280. package/dist/internal/schema/toJsonSchemaDocument.js.map +1 -1
  281. package/dist/internal/version.js +1 -1
  282. package/dist/net/Host.d.ts +49 -0
  283. package/dist/net/Host.d.ts.map +1 -1
  284. package/dist/net/Host.js +55 -0
  285. package/dist/net/Host.js.map +1 -1
  286. package/dist/net/NetAddress.d.ts +8 -0
  287. package/dist/net/NetAddress.d.ts.map +1 -1
  288. package/dist/net/NetAddress.js +8 -0
  289. package/dist/net/NetAddress.js.map +1 -1
  290. package/dist/observability/Otlp.d.ts +15 -0
  291. package/dist/observability/Otlp.d.ts.map +1 -1
  292. package/dist/observability/Otlp.js +3 -0
  293. package/dist/observability/Otlp.js.map +1 -1
  294. package/dist/observability/OtlpExporter.d.ts +8 -0
  295. package/dist/observability/OtlpExporter.d.ts.map +1 -1
  296. package/dist/observability/OtlpExporter.js +10 -1
  297. package/dist/observability/OtlpExporter.js.map +1 -1
  298. package/dist/observability/OtlpLogger.d.ts +17 -0
  299. package/dist/observability/OtlpLogger.d.ts.map +1 -1
  300. package/dist/observability/OtlpLogger.js +14 -1
  301. package/dist/observability/OtlpLogger.js.map +1 -1
  302. package/dist/observability/OtlpMetrics.d.ts +17 -0
  303. package/dist/observability/OtlpMetrics.d.ts.map +1 -1
  304. package/dist/observability/OtlpMetrics.js +13 -0
  305. package/dist/observability/OtlpMetrics.js.map +1 -1
  306. package/dist/observability/OtlpTracer.d.ts +17 -0
  307. package/dist/observability/OtlpTracer.d.ts.map +1 -1
  308. package/dist/observability/OtlpTracer.js +15 -2
  309. package/dist/observability/OtlpTracer.js.map +1 -1
  310. package/dist/reactivity/AsyncResult.d.ts +6 -0
  311. package/dist/reactivity/AsyncResult.d.ts.map +1 -1
  312. package/dist/reactivity/AsyncResult.js +27 -0
  313. package/dist/reactivity/AsyncResult.js.map +1 -1
  314. package/dist/reactivity/AtomRegistry.js +3 -1
  315. package/dist/reactivity/AtomRegistry.js.map +1 -1
  316. package/dist/rpc/RpcClient.d.ts.map +1 -1
  317. package/dist/rpc/RpcClient.js +6 -1
  318. package/dist/rpc/RpcClient.js.map +1 -1
  319. package/dist/rpc/RpcServer.d.ts.map +1 -1
  320. package/dist/rpc/RpcServer.js +36 -9
  321. package/dist/rpc/RpcServer.js.map +1 -1
  322. package/dist/socket/Socket.d.ts +6 -0
  323. package/dist/socket/Socket.d.ts.map +1 -1
  324. package/dist/socket/Socket.js.map +1 -1
  325. package/dist/sql/SqlClient.d.ts +8 -7
  326. package/dist/sql/SqlClient.d.ts.map +1 -1
  327. package/dist/sql/SqlClient.js +8 -7
  328. package/dist/sql/SqlClient.js.map +1 -1
  329. package/dist/testing/TestClock.d.ts +16 -3
  330. package/dist/testing/TestClock.d.ts.map +1 -1
  331. package/dist/testing/TestClock.js +112 -22
  332. package/dist/testing/TestClock.js.map +1 -1
  333. package/dist/workflow/Activity.js +1 -0
  334. package/dist/workflow/Activity.js.map +1 -1
  335. package/dist/workflow/DurableDeferred.d.ts.map +1 -1
  336. package/dist/workflow/DurableDeferred.js +32 -3
  337. package/dist/workflow/DurableDeferred.js.map +1 -1
  338. package/dist/workflow/Workflow.d.ts +22 -0
  339. package/dist/workflow/Workflow.d.ts.map +1 -1
  340. package/dist/workflow/Workflow.js +15 -3
  341. package/dist/workflow/Workflow.js.map +1 -1
  342. package/dist/workflow/WorkflowEngine.d.ts +44 -3
  343. package/dist/workflow/WorkflowEngine.d.ts.map +1 -1
  344. package/dist/workflow/WorkflowEngine.js +45 -22
  345. package/dist/workflow/WorkflowEngine.js.map +1 -1
  346. package/package.json +6 -3
  347. package/src/Array.ts +95 -6
  348. package/src/Channel.ts +24 -3
  349. package/src/ConfigProvider.ts +40 -44
  350. package/src/Context.ts +9 -0
  351. package/src/Duration.ts +4 -5
  352. package/src/Effect.ts +140 -53
  353. package/src/FileSystem.ts +23 -9
  354. package/src/Match.ts +65 -12
  355. package/src/Path.ts +52 -7
  356. package/src/RequestResolver.ts +4 -10
  357. package/src/Scheduler.ts +9 -0
  358. package/src/Schema.ts +25 -4
  359. package/src/SchemaGetter.ts +47 -35
  360. package/src/Sink.ts +45 -18
  361. package/src/Stream.ts +33 -4
  362. package/src/String.ts +17 -4
  363. package/src/TxRef.ts +4 -2
  364. package/src/Utils.ts +8 -5
  365. package/src/ai/AiError.ts +3 -1
  366. package/src/ai/AnthropicStructuredOutput.ts +2 -2
  367. package/src/ai/Chat.ts +2 -2
  368. package/src/ai/Decision.ts +70 -21
  369. package/src/ai/DecisionModel.ts +1 -1
  370. package/src/ai/LanguageModel.ts +141 -63
  371. package/src/ai/McpServer.ts +259 -145
  372. package/src/ai/Prompt.ts +24 -10
  373. package/src/ai/Response.ts +6 -3
  374. package/src/cli/Completions.ts +5 -0
  375. package/src/cli/Flag.ts +101 -0
  376. package/src/cli/Param.ts +96 -0
  377. package/src/cli/internal/command.ts +2 -1
  378. package/src/cli/internal/completions/bash.ts +4 -3
  379. package/src/cli/internal/completions/descriptor.ts +10 -1
  380. package/src/cli/internal/completions/fish.ts +4 -4
  381. package/src/cli/internal/completions/powershell.ts +5 -2
  382. package/src/cli/internal/completions/zsh.ts +7 -3
  383. package/src/cli/internal/parser.ts +12 -3
  384. package/src/cli/internal/wizard.ts +2 -1
  385. package/src/cluster/ClusterWorkflowEngine.ts +143 -36
  386. package/src/cluster/MessageStorage.ts +14 -3
  387. package/src/cluster/Runners.ts +88 -66
  388. package/src/cluster/Sharding.ts +12 -9
  389. package/src/cluster/internal/entityManager.ts +1 -1
  390. package/src/encoding/Sse.ts +70 -80
  391. package/src/graphql/GraphQL.ts +494 -0
  392. package/src/graphql/GraphQLClient.ts +924 -0
  393. package/src/graphql/GraphQLClientError.ts +542 -0
  394. package/src/graphql/GraphQLGroup.ts +167 -0
  395. package/src/graphql/GraphQLMiddleware.ts +253 -0
  396. package/src/graphql/GraphQLProtocol.ts +1540 -0
  397. package/src/graphql/GraphQLResolver.ts +1038 -0
  398. package/src/graphql/index.ts +48 -0
  399. package/src/http/FetchHttpClient.ts +6 -3
  400. package/src/http/FindMyWay/internal/router.ts +2 -1
  401. package/src/http/Headers.ts +6 -9
  402. package/src/http/HttpClient.ts +72 -11
  403. package/src/http/HttpClientError.ts +10 -6
  404. package/src/http/HttpClientRequest.ts +173 -7
  405. package/src/http/HttpEffect.ts +11 -5
  406. package/src/http/HttpMiddleware.ts +113 -34
  407. package/src/http/HttpRouter.ts +95 -13
  408. package/src/http/HttpServerError.ts +8 -4
  409. package/src/http/HttpServerRequest.ts +2 -2
  410. package/src/http/HttpServerResponse.ts +28 -16
  411. package/src/http/HttpStaticServer.ts +4 -10
  412. package/src/http/HttpTraceContext.ts +1 -1
  413. package/src/http/Multipart.ts +17 -1
  414. package/src/http/Url.ts +2 -1
  415. package/src/http/UrlParams.ts +225 -26
  416. package/src/http/internal/compression.ts +3 -17
  417. package/src/http/internal/compressionBody.ts +56 -0
  418. package/src/http/internal/decompression.ts +226 -0
  419. package/src/http/internal/tracing.ts +21 -4
  420. package/src/http/internal/urlParams.ts +5 -0
  421. package/src/http-api/HttpApiClient.ts +2 -1
  422. package/src/http-api/HttpApiScalar.ts +5 -0
  423. package/src/internal/core.ts +21 -1
  424. package/src/internal/dateTime.ts +13 -10
  425. package/src/internal/effect.ts +13 -7
  426. package/src/internal/graphql.ts +286 -0
  427. package/src/internal/graphqlHeaders.ts +11 -0
  428. package/src/internal/request.ts +31 -3
  429. package/src/internal/schema/toCodeDocument.ts +7 -1
  430. package/src/internal/schema/toJsonSchemaDocument.ts +34 -2
  431. package/src/internal/version.ts +1 -1
  432. package/src/net/Host.ts +72 -0
  433. package/src/net/NetAddress.ts +9 -0
  434. package/src/observability/Otlp.ts +18 -0
  435. package/src/observability/OtlpExporter.ts +14 -3
  436. package/src/observability/OtlpLogger.ts +31 -2
  437. package/src/observability/OtlpMetrics.ts +30 -1
  438. package/src/observability/OtlpTracer.ts +32 -3
  439. package/src/reactivity/AsyncResult.ts +31 -0
  440. package/src/reactivity/AtomRegistry.ts +3 -1
  441. package/src/rpc/RpcClient.ts +6 -1
  442. package/src/rpc/RpcServer.ts +55 -15
  443. package/src/socket/Socket.ts +6 -0
  444. package/src/sql/SqlClient.ts +9 -7
  445. package/src/testing/TestClock.ts +144 -29
  446. package/src/workflow/Activity.ts +1 -0
  447. package/src/workflow/DurableDeferred.ts +43 -5
  448. package/src/workflow/Workflow.ts +31 -5
  449. package/src/workflow/WorkflowEngine.ts +107 -25
@@ -104,8 +104,19 @@ interface QueuedServerNotification {
104
104
  const internalState = new WeakMap<object, {
105
105
  readonly core: McpCore.McpCore
106
106
  readonly notifications: Queue.Dequeue<QueuedServerNotification>
107
- readonly notificationDelivery: { consumers: number; listChangeRevision: number }
107
+ readonly notificationDelivery: { consumers: number; listChangeRevision: number; requestEndpoints: number }
108
108
  }>()
109
+
110
+ // Request-scoped HTTP servers deliver a request's own notifications through
111
+ // that request's server instead of the shared notification queue.
112
+ const RequestNotificationQueue = Context.Reference<Queue.Queue<QueuedServerNotification> | undefined>(
113
+ "effect/ai/McpServer/RequestNotificationQueue",
114
+ { defaultValue: () => undefined }
115
+ )
116
+ // Progress and logs belong to the request that emitted them.
117
+ const isRequestNotification = (notification: McpCore.ServerNotification) =>
118
+ notification._tag === "Progress" || notification._tag === "LoggingMessage"
119
+
109
120
  type ServerExtensions = NonNullable<ServerCapabilities["extensions"]>
110
121
  type ServerNotificationRequest<
111
122
  R extends Rpc.Any = RpcGroup.Rpcs<typeof BroadcastServerNotificationRpcs>
@@ -322,7 +333,10 @@ export class McpServer extends Context.Service<McpServer, {
322
333
  readonly annotations: Context.Context<never>
323
334
  }> = []
324
335
  const notificationsQueue = yield* Queue.make<QueuedServerNotification>()
325
- const notificationDelivery = { consumers: 0, listChangeRevision: 0 }
336
+ const notificationDelivery = { consumers: 0, listChangeRevision: 0, requestEndpoints: 0 }
337
+ // With only request-scoped endpoints, no long-lived server ever takes from the shared queue.
338
+ const withoutSharedConsumer = () =>
339
+ notificationDelivery.consumers === 0 && notificationDelivery.requestEndpoints > 0
326
340
  const pendingListChanges = new Map<string, QueuedServerNotification>()
327
341
  const dispatcher = (yield* Scheduler).makeDispatcher()
328
342
  const notifications = yield* RpcClient.makeNoSerialization(BroadcastServerNotificationRpcs, {
@@ -344,6 +358,26 @@ export class McpServer extends Context.Service<McpServer, {
344
358
  requestContext: Context.getOrUndefined(fiber.context, McpRequestContext),
345
359
  requestHeaders: Context.getOrUndefined(fiber.context, HttpServerRequest.HttpServerRequest)?.headers
346
360
  }
361
+ // write resumes the caller synchronously, so defer it until delivery completes.
362
+ const acknowledge = Effect.suspend(() =>
363
+ notifications.write({
364
+ clientId: 0,
365
+ requestId: message.id,
366
+ _tag: "Exit",
367
+ exit: Exit.void
368
+ })
369
+ )
370
+ // A request-scoped endpoint delivers its request's own progress and logs on that request's response.
371
+ const requestQueue = Context.get(fiber.context, RequestNotificationQueue)
372
+ if (
373
+ requestQueue !== undefined && queued.requestContext !== undefined && isRequestNotification(notification)
374
+ ) {
375
+ Queue.offerUnsafe(requestQueue, queued)
376
+ return Effect.andThen(Deferred.await(delivered), acknowledge)
377
+ }
378
+ if (withoutSharedConsumer()) {
379
+ return acknowledge
380
+ }
347
381
  let enqueued = false
348
382
  if (message.tag.includes("list_changed")) {
349
383
  const revision = ++notificationDelivery.listChangeRevision
@@ -364,15 +398,6 @@ export class McpServer extends Context.Service<McpServer, {
364
398
  enqueued = true
365
399
  Queue.offerUnsafe(notificationsQueue, queued)
366
400
  }
367
- // write resumes the caller synchronously, so defer it until delivery completes.
368
- const acknowledge = Effect.suspend(() =>
369
- notifications.write({
370
- clientId: 0,
371
- requestId: message.id,
372
- _tag: "Exit",
373
- exit: Exit.void
374
- })
375
- )
376
401
  return enqueued && queued.requestContext !== undefined && notificationDelivery.consumers > 0
377
402
  ? Effect.andThen(Deferred.await(delivered), acknowledge)
378
403
  : acknowledge
@@ -383,7 +408,7 @@ export class McpServer extends Context.Service<McpServer, {
383
408
  const service = McpServer.of({
384
409
  notifications: notifications.client,
385
410
  notifyElicitationComplete: ({ clientId, elicitationId }) =>
386
- Deferred.make<void>().pipe(
411
+ withoutSharedConsumer() ? Effect.void : Deferred.make<void>().pipe(
387
412
  Effect.flatMap((delivered) =>
388
413
  Queue.offer(notificationsQueue, {
389
414
  notification: McpCore.ServerNotification.ElicitationComplete({ elicitationId }),
@@ -727,7 +752,11 @@ const runWithRuntime = Effect.fnUntraced(function*(
727
752
  readonly allowSubscriptions?: boolean | undefined
728
753
  },
729
754
  runtime: McpRuntime.ServerRuntimeShape,
730
- transport: "custom" | "http" | "stdio"
755
+ transport: "custom" | "http" | "stdio",
756
+ requestScoped?: {
757
+ readonly notifications: Queue.Dequeue<QueuedServerNotification>
758
+ readonly handlers: Context.Context<never>
759
+ }
731
760
  ) {
732
761
  const protocol = yield* RpcServer.Protocol
733
762
  const server = yield* McpServer
@@ -817,7 +846,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
817
846
  })
818
847
  let writeFromClient!: (clientId: number, message: RpcMessage.FromClientEncoded) => Effect.Effect<void>
819
848
  const { core, notificationDelivery, notifications } = internalState.get(server)!
820
- const handlers = yield* runtime.installHandlers({
849
+ const handlers = requestScoped?.handlers ?? (yield* runtime.installHandlers({
821
850
  core,
822
851
  subscribeServerNotifications: PubSub.subscribe(serverNotifications),
823
852
  getListChangeRevision: () => notificationDelivery.listChangeRevision,
@@ -831,7 +860,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
831
860
  }),
832
861
  defaultLogLevel,
833
862
  serverInfo: options
834
- })
863
+ }))
835
864
 
836
865
  const clients = yield* RcMap.make({
837
866
  lookup: Effect.fnUntraced(function*(key: McpClientKey) {
@@ -1252,17 +1281,19 @@ const runWithRuntime = Effect.fnUntraced(function*(
1252
1281
  })
1253
1282
  }
1254
1283
 
1255
- yield* Effect.acquireRelease(
1256
- Effect.sync(() => {
1257
- notificationDelivery.consumers++
1258
- }),
1259
- () =>
1284
+ if (requestScoped === undefined) {
1285
+ yield* Effect.acquireRelease(
1260
1286
  Effect.sync(() => {
1261
- notificationDelivery.consumers--
1262
- })
1263
- )
1287
+ notificationDelivery.consumers++
1288
+ }),
1289
+ () =>
1290
+ Effect.sync(() => {
1291
+ notificationDelivery.consumers--
1292
+ })
1293
+ )
1294
+ }
1264
1295
  const notificationTails = new Map<number, Deferred.Deferred<void>>()
1265
- yield* Queue.take(notifications).pipe(
1296
+ yield* Queue.take(requestScoped?.notifications ?? notifications).pipe(
1266
1297
  Effect.flatMap(Effect.fnUntraced(function*(queued) {
1267
1298
  const { delivered, listChangeRevision, notification, targetClientId, requestContext, requestHeaders } = queued
1268
1299
  if (McpProtocolInternal.isSubscriptionServerNotification(notification)) {
@@ -1276,7 +1307,7 @@ const runWithRuntime = Effect.fnUntraced(function*(
1276
1307
  runtime.disconnect(clientId)
1277
1308
  }
1278
1309
  }
1279
- const requestNotification = notification._tag === "LoggingMessage" || notification._tag === "Progress"
1310
+ const requestNotification = isRequestNotification(notification)
1280
1311
  const deliveryClientIds = requestNotification && requestContext !== undefined
1281
1312
  ? [requestContext.clientId]
1282
1313
  : targetClientId === undefined
@@ -1594,11 +1625,20 @@ const mcpStdioSerialization = (
1594
1625
  * Method not found. Request-scoped progress and logs, legacy protocols, and
1595
1626
  * default subscription behavior are unchanged.
1596
1627
  *
1628
+ * The layer runs one long-lived MCP server that every POST shares. For
1629
+ * serverless hosts where execution must belong to each request, use
1630
+ * `layerHttpRequestScoped` instead.
1631
+ *
1597
1632
  * `layerHttp` always implements the single-endpoint Streamable HTTP topology.
1598
1633
  * Using `v2024_11_05` here is a custom compatibility transport for that
1599
1634
  * revision's schema. It does not implement the historical two-endpoint
1600
1635
  * HTTP+SSE transport, GET SSE, event resumption, or session expiry.
1601
1636
  *
1637
+ * **Gotchas**
1638
+ *
1639
+ * This layer starts a scoped server fiber. For sharing it across Cloudflare
1640
+ * Workers requests, see `HttpRouter.toWebHandler` for setup and limitations.
1641
+ *
1602
1642
  * @see {@link layerStdio} for exposing the server over stdio
1603
1643
  * @see {@link layer} for the base MCP server layer without a transport protocol
1604
1644
  *
@@ -1628,6 +1668,105 @@ export const layerHttp = (options: {
1628
1668
  )
1629
1669
  }
1630
1670
 
1671
+ /**
1672
+ * Registers a request-scoped Streamable HTTP MCP endpoint at `options.path`.
1673
+ *
1674
+ * **When to use**
1675
+ *
1676
+ * Use when serving on serverless hosts such as Cloudflare Workers, where execution must
1677
+ * belong to the HTTP request rather than a shared long-lived server.
1678
+ *
1679
+ * **Details**
1680
+ *
1681
+ * Each POST runs its own server in the request scope, with no background
1682
+ * fiber, timer, or queue consumer left after the response body completes.
1683
+ * Only sessionless protocols such as `v2026_07_28` are accepted. Tools,
1684
+ * resources, prompts, completions, multi round-trip input requests, and the
1685
+ * request's own progress and log notifications are supported. Legacy reverse
1686
+ * requests through `McpServer.elicit` are not available.
1687
+ *
1688
+ * Discovery advertises `listChanged: false`, `subscriptions/listen` returns
1689
+ * Method not found, and DELETE returns `405`. Request-scoped clients receive
1690
+ * no broadcast notifications such as list changes. Those still reach clients
1691
+ * of a `layerHttp` endpoint sharing the same `McpServer`, and are dropped when
1692
+ * no such endpoint exists. Use `layerHttp` on a long-lived host for sessions,
1693
+ * subscriptions, or legacy reverse requests.
1694
+ *
1695
+ * HTTP admission, origin checks, and JSON-RPC errors follow `layerHttp`.
1696
+ * Configuring a sessionful protocol through an untyped caller fails layer
1697
+ * construction with `IllegalArgumentError`.
1698
+ *
1699
+ * @see {@link layerHttp} for the long-lived HTTP transport and HTTP admission policy
1700
+ *
1701
+ * @stability unstable
1702
+ * @category layers
1703
+ * @since 4.0.0
1704
+ */
1705
+ export const layerHttpRequestScoped = (options: {
1706
+ readonly name: string
1707
+ readonly version: string
1708
+ readonly instructions?: string | undefined
1709
+ readonly description?: string | undefined
1710
+ readonly websiteUrl?: string | undefined
1711
+ readonly icons?: ReadonlyArray<McpSchema.Icon> | undefined
1712
+ readonly path: HttpRouter.PathInput
1713
+ readonly protocols: Arr.NonEmptyReadonlyArray<
1714
+ McpProtocol.ProtocolAdapter<McpProtocol.ProtocolVersion, McpProtocol.StatelessRuntimeDescriptor>
1715
+ >
1716
+ readonly extensions?: ServerExtensions | undefined
1717
+ readonly allowedOrigins?: ReadonlyArray<string> | undefined
1718
+ }): Layer.Layer<McpServer | McpServerClient, Cause.IllegalArgumentError, HttpRouter.HttpRouter> =>
1719
+ Layer.effectDiscard(Effect.gen(function*() {
1720
+ const runtime = yield* McpRuntime.ServerRuntime
1721
+ const stateful = runtime.protocols.find((protocol) => protocol.runtime._tag === "Stateful")
1722
+ if (stateful !== undefined) {
1723
+ return yield* new Cause.IllegalArgumentError(
1724
+ `McpServer.layerHttpRequestScoped does not support the sessionful MCP protocol ${stateful.protocolVersion}`
1725
+ )
1726
+ }
1727
+ const server = yield* McpServer
1728
+ const { core, notificationDelivery } = internalState.get(server)!
1729
+ // Subscriptions are disabled, so handlers hold no per-request state and
1730
+ // read registrations from the shared core on every call. Request services
1731
+ // still take precedence over the layer context captured here.
1732
+ const handlers = yield* (runtime.installHandlers({
1733
+ core,
1734
+ subscribeServerNotifications: Effect.die("Subscriptions are disabled for request-scoped MCP servers"),
1735
+ getListChangeRevision: () => notificationDelivery.listChangeRevision,
1736
+ defaultLogLevel: yield* CurrentLogLevel,
1737
+ serverInfo: options
1738
+ }) as Effect.Effect<Context.Context<never>>)
1739
+ yield* Effect.acquireRelease(
1740
+ Effect.sync(() => {
1741
+ notificationDelivery.requestEndpoints++
1742
+ }),
1743
+ () =>
1744
+ Effect.sync(() => {
1745
+ notificationDelivery.requestEndpoints--
1746
+ })
1747
+ )
1748
+ // Each POST runs its own RPC server in the request scope, so no fiber,
1749
+ // timer, or queue consumer outlives the request that created it.
1750
+ yield* addMcpHttpRoutes(
1751
+ options,
1752
+ Effect.gen(function*() {
1753
+ const { httpEffect, protocol } = yield* RpcServer.makeProtocolWithHttpEffect().pipe(
1754
+ Effect.provideService(RpcSerialization.RpcSerialization, mcpHttpSerialization)
1755
+ )
1756
+ const notifications = yield* Queue.make<QueuedServerNotification>()
1757
+ yield* runWithRuntime(options, runtime, "http", { notifications, handlers }).pipe(
1758
+ Effect.provideService(RpcServer.Protocol, protocol),
1759
+ Effect.provideService(McpServer, server),
1760
+ Effect.forkScoped({ startImmediately: true })
1761
+ )
1762
+ return yield* Effect.provideService(httpEffect, RequestNotificationQueue, notifications)
1763
+ })
1764
+ )
1765
+ })).pipe(
1766
+ Layer.provideMerge(McpServer.layer),
1767
+ Layer.provide(McpRuntime.layer(options.protocols))
1768
+ )
1769
+
1631
1770
  const layerMcpProtocolHttp = (options: {
1632
1771
  readonly path: HttpRouter.PathInput
1633
1772
  readonly allowedOrigins?: ReadonlyArray<string> | undefined
@@ -1638,81 +1777,96 @@ const layerMcpProtocolHttp = (options: {
1638
1777
  McpRuntime.ServerRuntime | HttpRouter.HttpRouter
1639
1778
  > =>
1640
1779
  Layer.effect(RpcServer.Protocol)(Effect.gen(function*() {
1641
- const runtime = yield* McpRuntime.ServerRuntime
1642
1780
  const { httpEffect, protocol } = yield* RpcServer.makeProtocolWithHttpEffect().pipe(
1643
1781
  Effect.provideService(RpcSerialization.RpcSerialization, mcpHttpSerialization)
1644
1782
  )
1645
- const router = yield* HttpRouter.HttpRouter
1646
- const allowSessionTermination = options.allowSessionTermination === true &&
1647
- runtime.protocols.some((protocol) => protocol.runtime._tag === "Stateful")
1648
- const forbidden = Effect.succeed(HttpServerResponse.empty({ status: 403 }))
1649
- const withAllowedOrigin = (
1650
- handler: (request: HttpServerRequest.HttpServerRequest) => Effect.Effect<HttpServerResponse.HttpServerResponse>
1651
- ) =>
1652
- (request: HttpServerRequest.HttpServerRequest) =>
1653
- isAllowedMcpOrigin(request, options.allowedOrigins) ? handler(request) : forbidden
1654
- const methodNotAllowedResponse = Effect.succeed(HttpServerResponse.empty({
1655
- status: 405,
1656
- headers: { allow: allowSessionTermination ? "POST, DELETE" : "POST" }
1657
- }))
1658
- const methodNotAllowed = withAllowedOrigin(() => methodNotAllowedResponse)
1659
- for (const method of ["GET", "PUT", "PATCH", "OPTIONS"] as const) {
1660
- yield* router.add(method, options.path, methodNotAllowed)
1783
+ yield* addMcpHttpRoutes(options, httpEffect)
1784
+ return protocol
1785
+ }))
1786
+
1787
+ const addMcpHttpRoutes = Effect.fnUntraced(function*(
1788
+ options: {
1789
+ readonly path: HttpRouter.PathInput
1790
+ readonly allowedOrigins?: ReadonlyArray<string> | undefined
1791
+ readonly allowSessionTermination?: boolean | undefined
1792
+ },
1793
+ httpEffect: Effect.Effect<
1794
+ HttpServerResponse.HttpServerResponse,
1795
+ never,
1796
+ Scope.Scope | HttpServerRequest.HttpServerRequest
1797
+ >
1798
+ ) {
1799
+ const runtime = yield* McpRuntime.ServerRuntime
1800
+ const router = yield* HttpRouter.HttpRouter
1801
+ const allowSessionTermination = options.allowSessionTermination === true &&
1802
+ runtime.protocols.some((protocol) => protocol.runtime._tag === "Stateful")
1803
+ const forbidden = Effect.succeed(HttpServerResponse.empty({ status: 403 }))
1804
+ const withAllowedOrigin = (
1805
+ handler: (request: HttpServerRequest.HttpServerRequest) => Effect.Effect<HttpServerResponse.HttpServerResponse>
1806
+ ) =>
1807
+ (request: HttpServerRequest.HttpServerRequest) =>
1808
+ isAllowedMcpOrigin(request, options.allowedOrigins) ? handler(request) : forbidden
1809
+ const methodNotAllowedResponse = Effect.succeed(HttpServerResponse.empty({
1810
+ status: 405,
1811
+ headers: { allow: allowSessionTermination ? "POST, DELETE" : "POST" }
1812
+ }))
1813
+ const methodNotAllowed = withAllowedOrigin(() => methodNotAllowedResponse)
1814
+ for (const method of ["GET", "PUT", "PATCH", "OPTIONS"] as const) {
1815
+ yield* router.add(method, options.path, methodNotAllowed)
1816
+ }
1817
+ yield* router.add(
1818
+ "DELETE",
1819
+ options.path,
1820
+ allowSessionTermination
1821
+ ? withAllowedOrigin((request) => runtime.terminateHttpSession(request.headers))
1822
+ : methodNotAllowed
1823
+ )
1824
+ yield* router.add("POST", options.path, (request) => {
1825
+ if (!isAllowedMcpOrigin(request, options.allowedOrigins)) {
1826
+ return Effect.succeed(HttpServerResponse.empty({ status: 403 }))
1661
1827
  }
1662
- yield* router.add(
1663
- "DELETE",
1664
- options.path,
1665
- allowSessionTermination
1666
- ? withAllowedOrigin((request) => runtime.terminateHttpSession(request.headers))
1667
- : methodNotAllowed
1668
- )
1669
- yield* router.add("POST", options.path, (request) => {
1670
- if (!isAllowedMcpOrigin(request, options.allowedOrigins)) {
1671
- return Effect.succeed(HttpServerResponse.empty({ status: 403 }))
1672
- }
1673
- if (mcpMediaTypes(request.headers["content-type"])[0] !== "application/json") {
1674
- return Effect.succeed(HttpServerResponse.empty({ status: 415 }))
1828
+ if (mcpMediaTypes(request.headers["content-type"])[0] !== "application/json") {
1829
+ return Effect.succeed(HttpServerResponse.empty({ status: 415 }))
1830
+ }
1831
+ const accepted = mcpMediaTypes(request.headers["accept"])
1832
+ if (!accepted.includes("application/json") || !accepted.includes("text/event-stream")) {
1833
+ return Effect.succeed(HttpServerResponse.empty({ status: 406 }))
1834
+ }
1835
+ return Effect.gen(function*() {
1836
+ const parsed = yield* Effect.result(
1837
+ Effect.flatMap(request.text, Schema.decodeEffect(Schema.UnknownFromJsonString))
1838
+ )
1839
+ const admission = runtime.admitHttp(request.headers, parsed)
1840
+ if (admission._tag === "Rejected") {
1841
+ return admission.response
1675
1842
  }
1676
- const accepted = mcpMediaTypes(request.headers["accept"])
1677
- if (!accepted.includes("application/json") || !accepted.includes("text/event-stream")) {
1678
- return Effect.succeed(HttpServerResponse.empty({ status: 406 }))
1843
+ const toResponse = (response: HttpServerResponse.HttpServerResponse) => {
1844
+ // Completed responses may already contain notifications followed by the result.
1845
+ const hasMultipleMessages = response.body._tag === "Uint8Array" &&
1846
+ response.body.body.subarray(0, -1).includes(10)
1847
+ return admission.isSubscription || response.body._tag === "Stream" || hasMultipleMessages
1848
+ ? toServerSentEvents(response, admission.isSubscription)
1849
+ : response
1679
1850
  }
1680
- return Effect.gen(function*() {
1681
- const parsed = yield* Effect.result(
1682
- Effect.flatMap(request.text, Schema.decodeEffect(Schema.UnknownFromJsonString))
1851
+ if (admission.acknowledge) {
1852
+ return yield* Effect.catchCause(
1853
+ Effect.map(httpEffect, toResponse),
1854
+ () => Effect.succeed(HttpServerResponse.empty({ status: 202 }))
1683
1855
  )
1684
- const admission = runtime.admitHttp(request.headers, parsed)
1685
- if (admission._tag === "Rejected") {
1686
- return admission.response
1687
- }
1688
- const toResponse = (response: HttpServerResponse.HttpServerResponse) => {
1689
- // Completed responses may already contain notifications followed by the result.
1690
- const hasMultipleMessages = response.body._tag === "Uint8Array" &&
1691
- response.body.body.subarray(0, -1).includes(10)
1692
- return admission.isSubscription || response.body._tag === "Stream" || hasMultipleMessages
1693
- ? toServerSentEvents(response, admission.isSubscription)
1694
- : response
1695
- }
1696
- if (admission.acknowledge) {
1697
- return yield* Effect.catchCause(
1698
- Effect.map(httpEffect, toResponse),
1699
- () => Effect.succeed(HttpServerResponse.empty({ status: 202 }))
1700
- )
1856
+ }
1857
+ return yield* Effect.flatMap(httpEffect, (response) => {
1858
+ if (response.body._tag !== "Uint8Array" || response.body.body.length > 0) {
1859
+ return Effect.succeed(toResponse(response))
1701
1860
  }
1702
- return yield* Effect.flatMap(httpEffect, (response) => {
1703
- if (response.body._tag !== "Uint8Array" || response.body.body.length > 0) {
1704
- return Effect.succeed(toResponse(response))
1705
- }
1706
- // Only fully cancelled request POSTs may return an empty SSE response.
1707
- // https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#sending-messages-to-the-server
1708
- return httpPostResponses.get(request)?.expected === 0
1709
- ? Effect.succeed(HttpServerResponse.stream(Stream.empty, { contentType: "text/event-stream" }))
1710
- : Effect.die(new Error("MCP request ended without writing its response"))
1711
- })
1861
+ // Only fully cancelled request POSTs may return an empty SSE response.
1862
+ // https://modelcontextprotocol.io/specification/2025-11-25/basic/transports#sending-messages-to-the-server
1863
+ return httpPostResponses.get(request)?.expected === 0
1864
+ ? Effect.succeed(HttpServerResponse.stream(Stream.empty, { contentType: "text/event-stream" }))
1865
+ : Effect.die(new Error("MCP request ended without writing its response"))
1712
1866
  })
1713
1867
  })
1714
- return protocol
1715
- }))
1868
+ })
1869
+ })
1716
1870
 
1717
1871
  const mcpHttpSerialization: RpcSerialization.RpcSerialization["Service"] = (() => {
1718
1872
  const serialization = mcpJsonRpcSerialization()
@@ -2123,12 +2277,6 @@ export type ResourceCompletions<Schemas extends ReadonlyArray<Schema.Constraint>
2123
2277
  /**
2124
2278
  * Registers an MCP resource or resource template from an Effect program.
2125
2279
  *
2126
- * **When to use**
2127
- *
2128
- * Use when you are already inside an Effect program with an `McpServer`
2129
- * service and need to add a concrete resource or URI-template resource
2130
- * directly.
2131
- *
2132
2280
  * @see {@link resource} for the layer-based resource registration wrapper
2133
2281
  *
2134
2282
  * @stability unstable
@@ -2139,12 +2287,6 @@ export const registerResource: {
2139
2287
  /**
2140
2288
  * Registers an MCP resource or resource template from an Effect program.
2141
2289
  *
2142
- * **When to use**
2143
- *
2144
- * Use when you are already inside an Effect program with an `McpServer`
2145
- * service and need to add a concrete resource or URI-template resource
2146
- * directly.
2147
- *
2148
2290
  * @see {@link resource} for the layer-based resource registration wrapper
2149
2291
  *
2150
2292
  * @stability unstable
@@ -2170,12 +2312,6 @@ export const registerResource: {
2170
2312
  /**
2171
2313
  * Registers an MCP resource or resource template from an Effect program.
2172
2314
  *
2173
- * **When to use**
2174
- *
2175
- * Use when you are already inside an Effect program with an `McpServer`
2176
- * service and need to add a concrete resource or URI-template resource
2177
- * directly.
2178
- *
2179
2315
  * @see {@link resource} for the layer-based resource registration wrapper
2180
2316
  *
2181
2317
  * @stability unstable
@@ -2206,9 +2342,7 @@ export const registerResource: {
2206
2342
  | Schemas[number]["DecodingServices"]
2207
2343
  | Schemas[number]["EncodingServices"]
2208
2344
  | R
2209
- | (Completions[keyof Completions] extends (input: string) => infer Ret ?
2210
- Ret extends Effect.Effect<infer _A, infer _E, infer _R> ? _R : never
2211
- : never),
2345
+ | CompletionServices<Completions>,
2212
2346
  McpRequestContext
2213
2347
  >
2214
2348
  | McpServer
@@ -2337,10 +2471,6 @@ export const registerResource: {
2337
2471
  /**
2338
2472
  * Creates a layer that registers an MCP resource or resource template.
2339
2473
  *
2340
- * **When to use**
2341
- *
2342
- * Use to compose resource registration into an MCP server layer.
2343
- *
2344
2474
  * @see {@link registerResource} for the Effect-level resource registration API
2345
2475
  *
2346
2476
  * @stability unstable
@@ -2351,10 +2481,6 @@ export const resource: {
2351
2481
  /**
2352
2482
  * Creates a layer that registers an MCP resource or resource template.
2353
2483
  *
2354
- * **When to use**
2355
- *
2356
- * Use to compose resource registration into an MCP server layer.
2357
- *
2358
2484
  * @see {@link registerResource} for the Effect-level resource registration API
2359
2485
  *
2360
2486
  * @stability unstable
@@ -2379,10 +2505,6 @@ export const resource: {
2379
2505
  /**
2380
2506
  * Creates a layer that registers an MCP resource or resource template.
2381
2507
  *
2382
- * **When to use**
2383
- *
2384
- * Use to compose resource registration into an MCP server layer.
2385
- *
2386
2508
  * @see {@link registerResource} for the Effect-level resource registration API
2387
2509
  *
2388
2510
  * @stability unstable
@@ -2409,10 +2531,10 @@ export const resource: {
2409
2531
  never,
2410
2532
  never,
2411
2533
  Exclude<
2534
+ | Schemas[number]["DecodingServices"]
2535
+ | Schemas[number]["EncodingServices"]
2412
2536
  | R
2413
- | (Completions[keyof Completions] extends (input: string) => infer Ret ?
2414
- Ret extends Effect.Effect<infer _A, infer _E, infer _R> ? _R : never
2415
- : never),
2537
+ | CompletionServices<Completions>,
2416
2538
  McpRequestContext
2417
2539
  >
2418
2540
  >
@@ -2432,16 +2554,10 @@ export const resource: {
2432
2554
  /**
2433
2555
  * Registers an MCP prompt from an Effect program.
2434
2556
  *
2435
- * **When to use**
2436
- *
2437
- * Use when you are already inside an Effect program with an `McpServer`
2438
- * service and need to add a prompt handler directly.
2439
- *
2440
2557
  * **Details**
2441
2558
  *
2442
- * Parameters are decoded with the supplied schema, completion handlers encode
2443
- * per-parameter suggestions, and string prompt content is converted into a user
2444
- * text message.
2559
+ * Decodes parameters and encodes completion suggestions using their schemas.
2560
+ * String content becomes a user text message.
2445
2561
  *
2446
2562
  * @see {@link prompt} for the layer-based prompt registration wrapper
2447
2563
  *
@@ -2476,6 +2592,7 @@ export const registerPrompt = <
2476
2592
  never,
2477
2593
  | Exclude<
2478
2594
  | Schema.Struct.DecodingServices<Params>
2595
+ | Params[Extract<keyof Completions, keyof Params>]["EncodingServices"]
2479
2596
  | R
2480
2597
  | CompletionServices<Completions>,
2481
2598
  McpRequestContext
@@ -2511,7 +2628,13 @@ export const registerPrompt = <
2511
2628
  const registry = yield* McpServer
2512
2629
  const services = omitRequestServices(
2513
2630
  yield* Effect.context<
2514
- Exclude<R | Schema.Struct.DecodingServices<Params>, McpRequestContext>
2631
+ Exclude<
2632
+ | R
2633
+ | Schema.Struct.DecodingServices<Params>
2634
+ | Params[Extract<keyof Completions, keyof Params>]["EncodingServices"]
2635
+ | CompletionServices<Completions>,
2636
+ McpRequestContext
2637
+ >
2515
2638
  >()
2516
2639
  )
2517
2640
  const completions: Record<
@@ -2577,16 +2700,6 @@ export const registerPrompt = <
2577
2700
  /**
2578
2701
  * Creates a layer that registers an MCP prompt.
2579
2702
  *
2580
- * **When to use**
2581
- *
2582
- * Use to compose prompt registration into an MCP server layer.
2583
- *
2584
- * **Details**
2585
- *
2586
- * Parameters are decoded with the supplied schema, completion handlers encode
2587
- * per-parameter suggestions, and string prompt content is converted into a user
2588
- * text message.
2589
- *
2590
2703
  * @see {@link registerPrompt} for the Effect-level prompt registration API
2591
2704
  *
2592
2705
  * @stability unstable
@@ -2620,6 +2733,7 @@ export const prompt = <
2620
2733
  never,
2621
2734
  Exclude<
2622
2735
  | Schema.Struct.DecodingServices<Params>
2736
+ | Params[Extract<keyof Completions, keyof Params>]["EncodingServices"]
2623
2737
  | R
2624
2738
  | CompletionServices<Completions>,
2625
2739
  McpRequestContext