@animalabs/agent-framework 0.23.3 → 0.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (355) hide show
  1. package/README.md +212 -42
  2. package/dist/src/agent.d.ts +65 -9
  3. package/dist/src/agent.d.ts.map +1 -1
  4. package/dist/src/agent.js +98 -12
  5. package/dist/src/agent.js.map +1 -1
  6. package/dist/src/api/server.d.ts.map +1 -1
  7. package/dist/src/api/server.js +14 -12
  8. package/dist/src/api/server.js.map +1 -1
  9. package/dist/src/clock-rows.d.ts +115 -0
  10. package/dist/src/clock-rows.d.ts.map +1 -0
  11. package/dist/src/clock-rows.js +222 -0
  12. package/dist/src/clock-rows.js.map +1 -0
  13. package/dist/src/code-execution/engine.d.ts +177 -0
  14. package/dist/src/code-execution/engine.d.ts.map +1 -0
  15. package/dist/src/code-execution/engine.js +494 -0
  16. package/dist/src/code-execution/engine.js.map +1 -0
  17. package/dist/src/code-execution/index.d.ts +5 -10
  18. package/dist/src/code-execution/index.d.ts.map +1 -1
  19. package/dist/src/code-execution/index.js +5 -9
  20. package/dist/src/code-execution/index.js.map +1 -1
  21. package/dist/src/code-execution/isolate/calls.d.ts +114 -0
  22. package/dist/src/code-execution/isolate/calls.d.ts.map +1 -0
  23. package/dist/src/code-execution/isolate/calls.js +145 -0
  24. package/dist/src/code-execution/isolate/calls.js.map +1 -0
  25. package/dist/src/code-execution/isolate/child-entry.d.ts +2 -0
  26. package/dist/src/code-execution/isolate/child-entry.d.ts.map +1 -0
  27. package/dist/src/code-execution/isolate/child-entry.js +5 -0
  28. package/dist/src/code-execution/isolate/child-entry.js.map +1 -0
  29. package/dist/src/code-execution/isolate/child-main.d.ts +26 -0
  30. package/dist/src/code-execution/isolate/child-main.d.ts.map +1 -0
  31. package/dist/src/code-execution/isolate/child-main.js +132 -0
  32. package/dist/src/code-execution/isolate/child-main.js.map +1 -0
  33. package/dist/src/code-execution/isolate/child.d.ts +44 -0
  34. package/dist/src/code-execution/isolate/child.d.ts.map +1 -0
  35. package/dist/src/code-execution/isolate/child.js +315 -0
  36. package/dist/src/code-execution/isolate/child.js.map +1 -0
  37. package/dist/src/code-execution/isolate/frames.d.ts +80 -0
  38. package/dist/src/code-execution/isolate/frames.d.ts.map +1 -0
  39. package/dist/src/code-execution/isolate/frames.js +210 -0
  40. package/dist/src/code-execution/isolate/frames.js.map +1 -0
  41. package/dist/src/code-execution/isolate/output.d.ts +68 -0
  42. package/dist/src/code-execution/isolate/output.d.ts.map +1 -0
  43. package/dist/src/code-execution/isolate/output.js +143 -0
  44. package/dist/src/code-execution/isolate/output.js.map +1 -0
  45. package/dist/src/code-execution/isolate/prelude.d.ts +109 -0
  46. package/dist/src/code-execution/isolate/prelude.d.ts.map +1 -0
  47. package/dist/src/code-execution/isolate/prelude.js +401 -0
  48. package/dist/src/code-execution/isolate/prelude.js.map +1 -0
  49. package/dist/src/code-execution/isolate/protocol.d.ts +151 -0
  50. package/dist/src/code-execution/isolate/protocol.d.ts.map +1 -0
  51. package/dist/src/code-execution/isolate/protocol.js +150 -0
  52. package/dist/src/code-execution/isolate/protocol.js.map +1 -0
  53. package/dist/src/code-execution/isolate/render.d.ts +57 -0
  54. package/dist/src/code-execution/isolate/render.d.ts.map +1 -0
  55. package/dist/src/code-execution/isolate/render.js +214 -0
  56. package/dist/src/code-execution/isolate/render.js.map +1 -0
  57. package/dist/src/code-execution/isolate/runner.d.ts +250 -0
  58. package/dist/src/code-execution/isolate/runner.d.ts.map +1 -0
  59. package/dist/src/code-execution/isolate/runner.js +854 -0
  60. package/dist/src/code-execution/isolate/runner.js.map +1 -0
  61. package/dist/src/code-execution/isolate/scripts.d.ts +175 -0
  62. package/dist/src/code-execution/isolate/scripts.d.ts.map +1 -0
  63. package/dist/src/code-execution/isolate/scripts.js +357 -0
  64. package/dist/src/code-execution/isolate/scripts.js.map +1 -0
  65. package/dist/src/code-execution/quickjs.wasm +0 -0
  66. package/dist/src/code-execution/tool-definition.d.ts +93 -43
  67. package/dist/src/code-execution/tool-definition.d.ts.map +1 -1
  68. package/dist/src/code-execution/tool-definition.js +176 -142
  69. package/dist/src/code-execution/tool-definition.js.map +1 -1
  70. package/dist/src/deadline-timer.d.ts +3 -0
  71. package/dist/src/deadline-timer.d.ts.map +1 -1
  72. package/dist/src/deadline-timer.js +1 -1
  73. package/dist/src/deadline-timer.js.map +1 -1
  74. package/dist/src/framework.d.ts +1120 -457
  75. package/dist/src/framework.d.ts.map +1 -1
  76. package/dist/src/framework.js +4635 -2505
  77. package/dist/src/framework.js.map +1 -1
  78. package/dist/src/gate/event-gate.d.ts +28 -4
  79. package/dist/src/gate/event-gate.d.ts.map +1 -1
  80. package/dist/src/gate/event-gate.js +89 -13
  81. package/dist/src/gate/event-gate.js.map +1 -1
  82. package/dist/src/held-writes.d.ts +16 -3
  83. package/dist/src/held-writes.d.ts.map +1 -1
  84. package/dist/src/held-writes.js +16 -3
  85. package/dist/src/held-writes.js.map +1 -1
  86. package/dist/src/index.d.ts +8 -6
  87. package/dist/src/index.d.ts.map +1 -1
  88. package/dist/src/index.js +10 -8
  89. package/dist/src/index.js.map +1 -1
  90. package/dist/src/mcpl/channel-registry.d.ts +483 -115
  91. package/dist/src/mcpl/channel-registry.d.ts.map +1 -1
  92. package/dist/src/mcpl/channel-registry.js +1735 -425
  93. package/dist/src/mcpl/channel-registry.js.map +1 -1
  94. package/dist/src/mcpl/conversation-router.d.ts +19 -39
  95. package/dist/src/mcpl/conversation-router.d.ts.map +1 -1
  96. package/dist/src/mcpl/conversation-router.js +27 -59
  97. package/dist/src/mcpl/conversation-router.js.map +1 -1
  98. package/dist/src/mcpl/convert-block.d.ts.map +1 -1
  99. package/dist/src/mcpl/convert-block.js +9 -5
  100. package/dist/src/mcpl/convert-block.js.map +1 -1
  101. package/dist/src/mcpl/inbound-source.d.ts +50 -0
  102. package/dist/src/mcpl/inbound-source.d.ts.map +1 -1
  103. package/dist/src/mcpl/inbound-source.js +130 -0
  104. package/dist/src/mcpl/inbound-source.js.map +1 -1
  105. package/dist/src/mcpl/index.d.ts +2 -1
  106. package/dist/src/mcpl/index.d.ts.map +1 -1
  107. package/dist/src/mcpl/index.js +3 -2
  108. package/dist/src/mcpl/index.js.map +1 -1
  109. package/dist/src/mcpl/log-value.d.ts +6 -0
  110. package/dist/src/mcpl/log-value.d.ts.map +1 -1
  111. package/dist/src/mcpl/log-value.js +8 -0
  112. package/dist/src/mcpl/log-value.js.map +1 -1
  113. package/dist/src/mcpl/modern-connection.d.ts +15 -6
  114. package/dist/src/mcpl/modern-connection.d.ts.map +1 -1
  115. package/dist/src/mcpl/modern-connection.js +168 -53
  116. package/dist/src/mcpl/modern-connection.js.map +1 -1
  117. package/dist/src/mcpl/prose-grammar.d.ts +4 -5
  118. package/dist/src/mcpl/prose-grammar.d.ts.map +1 -1
  119. package/dist/src/mcpl/prose-grammar.js +4 -5
  120. package/dist/src/mcpl/prose-grammar.js.map +1 -1
  121. package/dist/src/mcpl/protocol-family.d.ts +97 -10
  122. package/dist/src/mcpl/protocol-family.d.ts.map +1 -1
  123. package/dist/src/mcpl/protocol-family.js +174 -17
  124. package/dist/src/mcpl/protocol-family.js.map +1 -1
  125. package/dist/src/mcpl/push-coalescer.d.ts +132 -14
  126. package/dist/src/mcpl/push-coalescer.d.ts.map +1 -1
  127. package/dist/src/mcpl/push-coalescer.js +227 -50
  128. package/dist/src/mcpl/push-coalescer.js.map +1 -1
  129. package/dist/src/mcpl/push-handler.d.ts +9 -20
  130. package/dist/src/mcpl/push-handler.d.ts.map +1 -1
  131. package/dist/src/mcpl/push-handler.js +7 -49
  132. package/dist/src/mcpl/push-handler.js.map +1 -1
  133. package/dist/src/mcpl/reference-fetcher.d.ts +2 -2
  134. package/dist/src/mcpl/reference-fetcher.d.ts.map +1 -1
  135. package/dist/src/mcpl/reference-fetcher.js +4 -4
  136. package/dist/src/mcpl/reference-fetcher.js.map +1 -1
  137. package/dist/src/mcpl/server-connection.d.ts +50 -21
  138. package/dist/src/mcpl/server-connection.d.ts.map +1 -1
  139. package/dist/src/mcpl/server-connection.js +158 -74
  140. package/dist/src/mcpl/server-connection.js.map +1 -1
  141. package/dist/src/mcpl/tags.d.ts +24 -0
  142. package/dist/src/mcpl/tags.d.ts.map +1 -1
  143. package/dist/src/mcpl/tags.js +33 -0
  144. package/dist/src/mcpl/tags.js.map +1 -1
  145. package/dist/src/mcpl/tool-result-normalize.d.ts +2 -1
  146. package/dist/src/mcpl/tool-result-normalize.d.ts.map +1 -1
  147. package/dist/src/mcpl/tool-result-normalize.js.map +1 -1
  148. package/dist/src/mcpl/transport.d.ts +55 -7
  149. package/dist/src/mcpl/transport.d.ts.map +1 -1
  150. package/dist/src/mcpl/transport.js +163 -34
  151. package/dist/src/mcpl/transport.js.map +1 -1
  152. package/dist/src/mcpl/types.d.ts +22 -6
  153. package/dist/src/mcpl/types.d.ts.map +1 -1
  154. package/dist/src/mcpl/types.js.map +1 -1
  155. package/dist/src/module-registry.d.ts +4 -2
  156. package/dist/src/module-registry.d.ts.map +1 -1
  157. package/dist/src/module-registry.js +100 -13
  158. package/dist/src/module-registry.js.map +1 -1
  159. package/dist/src/modules/discord/index.d.ts.map +1 -1
  160. package/dist/src/modules/discord/index.js +8 -13
  161. package/dist/src/modules/discord/index.js.map +1 -1
  162. package/dist/src/modules/history/index.d.ts.map +1 -1
  163. package/dist/src/modules/history/index.js +27 -4
  164. package/dist/src/modules/history/index.js.map +1 -1
  165. package/dist/src/modules/history/semantic.d.ts +15 -3
  166. package/dist/src/modules/history/semantic.d.ts.map +1 -1
  167. package/dist/src/modules/history/semantic.js +27 -5
  168. package/dist/src/modules/history/semantic.js.map +1 -1
  169. package/dist/src/modules/index.d.ts +1 -1
  170. package/dist/src/modules/index.d.ts.map +1 -1
  171. package/dist/src/modules/index.js.map +1 -1
  172. package/dist/src/modules/unknown-tool.d.ts +4 -1
  173. package/dist/src/modules/unknown-tool.d.ts.map +1 -1
  174. package/dist/src/modules/unknown-tool.js +4 -1
  175. package/dist/src/modules/unknown-tool.js.map +1 -1
  176. package/dist/src/modules/workspace/branch-intent.d.ts +3 -1
  177. package/dist/src/modules/workspace/branch-intent.d.ts.map +1 -1
  178. package/dist/src/modules/workspace/branch-intent.js +3 -1
  179. package/dist/src/modules/workspace/branch-intent.js.map +1 -1
  180. package/dist/src/modules/workspace/edit-plan.d.ts +265 -0
  181. package/dist/src/modules/workspace/edit-plan.d.ts.map +1 -0
  182. package/dist/src/modules/workspace/edit-plan.js +794 -0
  183. package/dist/src/modules/workspace/edit-plan.js.map +1 -0
  184. package/dist/src/modules/workspace/edit-text.d.ts +117 -0
  185. package/dist/src/modules/workspace/edit-text.d.ts.map +1 -0
  186. package/dist/src/modules/workspace/edit-text.js +584 -0
  187. package/dist/src/modules/workspace/edit-text.js.map +1 -0
  188. package/dist/src/modules/workspace/effects.d.ts +5 -4
  189. package/dist/src/modules/workspace/effects.d.ts.map +1 -1
  190. package/dist/src/modules/workspace/effects.js +78 -25
  191. package/dist/src/modules/workspace/effects.js.map +1 -1
  192. package/dist/src/modules/workspace/index.d.ts +493 -62
  193. package/dist/src/modules/workspace/index.d.ts.map +1 -1
  194. package/dist/src/modules/workspace/index.js +2216 -652
  195. package/dist/src/modules/workspace/index.js.map +1 -1
  196. package/dist/src/modules/workspace/observe.d.ts +213 -38
  197. package/dist/src/modules/workspace/observe.d.ts.map +1 -1
  198. package/dist/src/modules/workspace/observe.js +416 -36
  199. package/dist/src/modules/workspace/observe.js.map +1 -1
  200. package/dist/src/modules/workspace/reconcile.d.ts.map +1 -1
  201. package/dist/src/modules/workspace/reconcile.js +15 -8
  202. package/dist/src/modules/workspace/reconcile.js.map +1 -1
  203. package/dist/src/modules/workspace/text.d.ts +32 -0
  204. package/dist/src/modules/workspace/text.d.ts.map +1 -0
  205. package/dist/src/modules/workspace/text.js +67 -0
  206. package/dist/src/modules/workspace/text.js.map +1 -0
  207. package/dist/src/modules/workspace/types.d.ts +210 -6
  208. package/dist/src/modules/workspace/types.d.ts.map +1 -1
  209. package/dist/src/modules/workspace/types.js.map +1 -1
  210. package/dist/src/modules/workspace/watcher.d.ts +3 -2
  211. package/dist/src/modules/workspace/watcher.d.ts.map +1 -1
  212. package/dist/src/modules/workspace/watcher.js.map +1 -1
  213. package/dist/src/operator-log.d.ts +52 -24
  214. package/dist/src/operator-log.d.ts.map +1 -1
  215. package/dist/src/operator-log.js.map +1 -1
  216. package/dist/src/recovery/discord-awareness-outbox.d.ts +496 -72
  217. package/dist/src/recovery/discord-awareness-outbox.d.ts.map +1 -1
  218. package/dist/src/recovery/discord-awareness-outbox.js +1196 -289
  219. package/dist/src/recovery/discord-awareness-outbox.js.map +1 -1
  220. package/dist/src/recovery/offline-branch.d.ts +26 -1
  221. package/dist/src/recovery/offline-branch.d.ts.map +1 -1
  222. package/dist/src/recovery/offline-branch.js +164 -39
  223. package/dist/src/recovery/offline-branch.js.map +1 -1
  224. package/dist/src/recovery/recover-cli.js +23 -4
  225. package/dist/src/recovery/recover-cli.js.map +1 -1
  226. package/dist/src/send-tools.d.ts +11 -0
  227. package/dist/src/send-tools.d.ts.map +1 -0
  228. package/dist/src/send-tools.js +11 -0
  229. package/dist/src/send-tools.js.map +1 -0
  230. package/dist/src/timezone.d.ts +4 -2
  231. package/dist/src/timezone.d.ts.map +1 -1
  232. package/dist/src/timezone.js +4 -2
  233. package/dist/src/timezone.js.map +1 -1
  234. package/dist/src/tool-image-ledger.d.ts +46 -7
  235. package/dist/src/tool-image-ledger.d.ts.map +1 -1
  236. package/dist/src/tool-image-ledger.js +60 -7
  237. package/dist/src/tool-image-ledger.js.map +1 -1
  238. package/dist/src/tool-result-guard.d.ts +14 -11
  239. package/dist/src/tool-result-guard.d.ts.map +1 -1
  240. package/dist/src/tool-result-guard.js +17 -14
  241. package/dist/src/tool-result-guard.js.map +1 -1
  242. package/dist/src/tool-result-history.d.ts +3 -2
  243. package/dist/src/tool-result-history.d.ts.map +1 -1
  244. package/dist/src/tool-result-history.js +3 -2
  245. package/dist/src/tool-result-history.js.map +1 -1
  246. package/dist/src/tune-out/coordinator.d.ts +21 -0
  247. package/dist/src/tune-out/coordinator.d.ts.map +1 -1
  248. package/dist/src/tune-out/coordinator.js +142 -40
  249. package/dist/src/tune-out/coordinator.js.map +1 -1
  250. package/dist/src/types/agent.d.ts +31 -6
  251. package/dist/src/types/agent.d.ts.map +1 -1
  252. package/dist/src/types/events.d.ts +66 -9
  253. package/dist/src/types/events.d.ts.map +1 -1
  254. package/dist/src/types/framework.d.ts +69 -62
  255. package/dist/src/types/framework.d.ts.map +1 -1
  256. package/dist/src/types/module.d.ts +40 -8
  257. package/dist/src/types/module.d.ts.map +1 -1
  258. package/dist/src/types/trace.d.ts +111 -10
  259. package/dist/src/types/trace.d.ts.map +1 -1
  260. package/dist/src/usage/types.d.ts +16 -0
  261. package/dist/src/usage/types.d.ts.map +1 -1
  262. package/dist/src/usage/usage-tracker.d.ts +14 -1
  263. package/dist/src/usage/usage-tracker.d.ts.map +1 -1
  264. package/dist/src/usage/usage-tracker.js +81 -41
  265. package/dist/src/usage/usage-tracker.js.map +1 -1
  266. package/package.json +6 -8
  267. package/src/agent.ts +99 -12
  268. package/src/api/server.ts +14 -12
  269. package/src/clock-rows.ts +302 -0
  270. package/src/code-execution/engine.ts +595 -0
  271. package/src/code-execution/index.ts +5 -17
  272. package/src/code-execution/isolate/calls.ts +199 -0
  273. package/src/code-execution/isolate/child-entry.ts +5 -0
  274. package/src/code-execution/isolate/child-main.ts +132 -0
  275. package/src/code-execution/isolate/child.ts +327 -0
  276. package/src/code-execution/isolate/frames.ts +209 -0
  277. package/src/code-execution/isolate/output.ts +161 -0
  278. package/src/code-execution/isolate/prelude.ts +409 -0
  279. package/src/code-execution/isolate/protocol.ts +240 -0
  280. package/src/code-execution/isolate/render.ts +230 -0
  281. package/src/code-execution/isolate/runner.ts +911 -0
  282. package/src/code-execution/isolate/scripts.ts +479 -0
  283. package/src/code-execution/quickjs.wasm +0 -0
  284. package/src/code-execution/quickjs.wasm.LICENSES +149 -0
  285. package/src/code-execution/tool-definition.ts +236 -167
  286. package/src/deadline-timer.ts +1 -1
  287. package/src/framework.ts +4978 -2671
  288. package/src/gate/event-gate.ts +79 -17
  289. package/src/held-writes.ts +17 -3
  290. package/src/index.ts +32 -22
  291. package/src/mcpl/channel-registry.ts +1892 -471
  292. package/src/mcpl/conversation-router.ts +26 -72
  293. package/src/mcpl/convert-block.ts +9 -5
  294. package/src/mcpl/inbound-source.ts +131 -0
  295. package/src/mcpl/index.ts +4 -2
  296. package/src/mcpl/log-value.ts +9 -0
  297. package/src/mcpl/modern-connection.ts +162 -53
  298. package/src/mcpl/prose-grammar.ts +4 -5
  299. package/src/mcpl/protocol-family.ts +200 -22
  300. package/src/mcpl/push-coalescer.ts +306 -62
  301. package/src/mcpl/push-handler.ts +12 -54
  302. package/src/mcpl/reference-fetcher.ts +4 -4
  303. package/src/mcpl/server-connection.ts +180 -79
  304. package/src/mcpl/tags.ts +36 -0
  305. package/src/mcpl/tool-result-normalize.ts +2 -1
  306. package/src/mcpl/transport.ts +162 -33
  307. package/src/mcpl/types.ts +23 -6
  308. package/src/module-registry.ts +92 -13
  309. package/src/modules/discord/index.ts +8 -13
  310. package/src/modules/history/index.ts +25 -3
  311. package/src/modules/history/semantic.ts +29 -6
  312. package/src/modules/index.ts +1 -0
  313. package/src/modules/unknown-tool.ts +4 -1
  314. package/src/modules/workspace/branch-intent.ts +3 -1
  315. package/src/modules/workspace/edit-plan.ts +954 -0
  316. package/src/modules/workspace/edit-text.ts +618 -0
  317. package/src/modules/workspace/effects.ts +70 -19
  318. package/src/modules/workspace/index.ts +2293 -650
  319. package/src/modules/workspace/observe.ts +465 -56
  320. package/src/modules/workspace/reconcile.ts +14 -7
  321. package/src/modules/workspace/text.ts +68 -0
  322. package/src/modules/workspace/types.ts +211 -6
  323. package/src/modules/workspace/watcher.ts +3 -2
  324. package/src/operator-log.ts +47 -19
  325. package/src/recovery/discord-awareness-outbox.ts +1500 -356
  326. package/src/recovery/offline-branch.ts +189 -55
  327. package/src/recovery/recover-cli.ts +25 -4
  328. package/src/send-tools.ts +11 -0
  329. package/src/timezone.ts +4 -2
  330. package/src/tool-image-ledger.ts +62 -8
  331. package/src/tool-result-guard.ts +18 -15
  332. package/src/tool-result-history.ts +3 -2
  333. package/src/tune-out/coordinator.ts +166 -45
  334. package/src/types/agent.ts +32 -6
  335. package/src/types/events.ts +66 -9
  336. package/src/types/framework.ts +69 -62
  337. package/src/types/module.ts +40 -8
  338. package/src/types/trace.ts +121 -15
  339. package/src/usage/types.ts +16 -0
  340. package/src/usage/usage-tracker.ts +86 -43
  341. package/dist/src/code-execution/py-runner.d.ts +0 -191
  342. package/dist/src/code-execution/py-runner.d.ts.map +0 -1
  343. package/dist/src/code-execution/py-runner.js +0 -655
  344. package/dist/src/code-execution/py-runner.js.map +0 -1
  345. package/dist/src/code-execution/runtime-py.d.ts +0 -50
  346. package/dist/src/code-execution/runtime-py.d.ts.map +0 -1
  347. package/dist/src/code-execution/runtime-py.js +0 -677
  348. package/dist/src/code-execution/runtime-py.js.map +0 -1
  349. package/dist/src/mcpl/prose-stream-router.d.ts +0 -88
  350. package/dist/src/mcpl/prose-stream-router.d.ts.map +0 -1
  351. package/dist/src/mcpl/prose-stream-router.js +0 -291
  352. package/dist/src/mcpl/prose-stream-router.js.map +0 -1
  353. package/src/code-execution/py-runner.ts +0 -791
  354. package/src/code-execution/runtime-py.ts +0 -677
  355. package/src/mcpl/prose-stream-router.ts +0 -268
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/mcpl/index.ts"],"names":[],"mappings":"AAyFA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC,4BAA4B;AAC5B,OAAO,EACL,uBAAuB,EACvB,mBAAmB,EACnB,oBAAoB,EACpB,qBAAqB,EACrB,eAAe,EACf,mBAAmB,EACnB,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,mBAAmB,EACnB,cA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AmB,GAOpB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,qBAAqB,EACrB,oBAAoB,EACpB,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,GAIZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,0BAA0B;AAC1B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAGhD,0CAA0C;AAC1C,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,6EAA6E;AAC7E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAGxD,6EAA6E;AAC7E,+CAA+C;AAC/C,OAAO,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAQ/G,6DAA6D;AAC7D,2HAA2H;AAC3H,OAAO,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAYtF,8DAA8D;AAC9D,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC"}
@@ -49,6 +49,12 @@ export declare function logValue(value: unknown): string;
49
49
  * text holds nothing `redact` replaces prints exactly as logValue prints it.
50
50
  */
51
51
  export declare function logValueRedacted(value: unknown, redact: (text: string) => string): string;
52
+ /**
53
+ * A JSON-RPC error answer's code as a log line prints it: a number, as
54
+ * JSON-RPC says a code is, as logValue prints it; any other JSON value a
55
+ * server sends there redacted (logValueRedacted), since the server wrote it.
56
+ */
57
+ export declare function loggedCode(code: unknown, redact: (text: string) => string): string;
52
58
  /**
53
59
  * The host's own message, as the free text that ends a log line after its
54
60
  * fields: `reason=coalesce-invalid field=payload.content: "content must be an
@@ -1 +1 @@
1
- {"version":3,"file":"log-value.d.ts","sourceRoot":"","sources":["../../../src/mcpl/log-value.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE/C;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAEzF;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD"}
1
+ {"version":3,"file":"log-value.d.ts","sourceRoot":"","sources":["../../../src/mcpl/log-value.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAE/C;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAEzF;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,GAAG,MAAM,CAElF;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEhD"}
@@ -53,6 +53,14 @@ export function logValue(value) {
53
53
  export function logValueRedacted(value, redact) {
54
54
  return printed(redact(textOf(value)), FIELD);
55
55
  }
56
+ /**
57
+ * A JSON-RPC error answer's code as a log line prints it: a number, as
58
+ * JSON-RPC says a code is, as logValue prints it; any other JSON value a
59
+ * server sends there redacted (logValueRedacted), since the server wrote it.
60
+ */
61
+ export function loggedCode(code, redact) {
62
+ return typeof code === 'number' ? logValue(code) : logValueRedacted(code, redact);
63
+ }
56
64
  /**
57
65
  * The host's own message, as the free text that ends a log line after its
58
66
  * fields: `reason=coalesce-invalid field=payload.content: "content must be an
@@ -1 +1 @@
1
- {"version":3,"file":"log-value.js","sourceRoot":"","sources":["../../../src/mcpl/log-value.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAc;IACrC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,KAAK,CAAC,CAAC;AACvC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAc,EAAE,MAAgC;IAC/E,OAAO,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AAC/C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,SAAS,CAAC,KAAc;IACtC,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAQD,MAAM,KAAK,GAAS;IAClB,KAAK,EAAE,6DAA6D;IACpE,OAAO,EAAE,uDAAuD;CACjE,CAAC;AAEF,MAAM,MAAM,GAAS;IACnB,KAAK,EAAE,4DAA4D;IACnE,OAAO,EAAE,2DAA2D;CACrE,CAAC;AAEF,iEAAiE;AACjE,MAAM,WAAW,GAAG,GAAG,CAAC;AAExB,SAAS,OAAO,CAAC,IAAY,EAAE,IAAU;IACvC,IAAI,IAAI,CAAC,MAAM,IAAI,WAAW;QAAE,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACzF,IAAI,GAAG,GAAG,WAAW,CAAC;IACtB,MAAM,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACtC,IAAI,IAAI,IAAI,MAAM,IAAI,IAAI,IAAI,MAAM;QAAE,GA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CAAC;QAC3B,IAAI,CAAC;YACH,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAAC,MAAM,CAAC;YACP,kBAAkB;QACpB,CAAC;IACH,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,SAAS,WAAW,CAAC,KAAa;IAChC,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,GAAG,IAAI,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,EAAE,CAAC;IACxG,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -48,6 +48,10 @@ export declare class ModernMcpConnection extends EventEmitter {
48
48
  * connect() returns), delivered to the first listener. Bounded: the
49
49
  * newest lines are kept. */
50
50
  private stderrBacklog;
51
+ private redactor?;
52
+ /** The server's text with its configuration's credentials replaced, for
53
+ * the errors this connection hands its caller and its records. */
54
+ private get recorded();
51
55
  private constructor();
52
56
  private deliverStderr;
53
57
  /** The per-call deadline: `requestTimeoutMs`, validated positive. */
@@ -62,15 +66,18 @@ export declare class ModernMcpConnection extends EventEmitter {
62
66
  * While it's true the connection owns that child, so whatever registered
63
67
  * it keeps its id held; close() retries the reap. It's settled only once
64
68
  * a reap has finished: while a lost session's reap or a close runs, it
65
- * reads false, so read it once lossReaped() or close() has settled. */
69
+ * may not read true yet, so read it once lossReaped() or close() has
70
+ * settled. */
66
71
  get holdsUnreapedChild(): boolean;
67
72
  /** The reap of a session lost on its own, settled once it's done, whether
68
73
  * or not it confirmed the child exited (holdsUnreapedChild says which);
69
74
  * settled at once when no such reap is running. */
70
75
  lossReaped(): Promise<void>;
71
76
  /** A failed generation's cleanup couldn't reap its child: keep owning it,
72
- * and halt reconnecting until close() settles it. */
77
+ * and halt reconnecting until close() settles it. It's reported as an
78
+ * 'error' at once, unless the caller reports it later itself. */
73
79
  private holdUnreaped;
80
+ private reportUnreaped;
74
81
  /** The halt, as a permanent failure for the reconnect events. */
75
82
  private unreapedFailure;
76
83
  /**
@@ -126,7 +133,9 @@ export declare class ModernMcpConnection extends EventEmitter {
126
133
  private cancelRelisten;
127
134
  private scheduleRelisten;
128
135
  private reopenSubscription;
129
- /** The transport went away (child exit, or a closed HTTP client). */
136
+ /** The transport went away (child exit, or a closed HTTP client).
137
+ * `unreaped`: the child's pipe failed and it outlived SIGKILL, so its
138
+ * launch is already known unreaped. */
130
139
  private handleLost;
131
140
  /** The legacy engine's backoff: doubling from the base interval, capped,
132
141
  * with ±25% jitter, and never past the timer limit (a longer delay would
@@ -187,9 +196,9 @@ export declare class ModernMcpConnection extends EventEmitter {
187
196
  * The rules apply in this order. The call's answer is the server's final
188
197
  * one: an error or a `complete` result.
189
198
  * - nothing handed to the transport: `not-sent`, whatever was raised (a
190
- * pre-dispatch validation, a signal already aborted, no transport, a send
191
- * Connectome's stdio line refused before writing, an HTTP refusal before
192
- * any request went out);
199
+ * pre-dispatch validation, a signal already aborted, no transport, a
200
+ * message JSON can't write, a send Connectome's stdio line refused
201
+ * before writing);
193
202
  * - the most recent leg answered with a JSON-RPC error: `error-response`
194
203
  * with that error's data;
195
204
  * - the most recent leg answered with a complete result: the server
@@ -1 +1 @@
1
- {"version":3,"file":"modern-connection.d.ts","sourceRoot":"","sources":["../../../src/mcpl/modern-connection.ts"],"names":[],"mappings":"AAgDA,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,OAAO,EAUL,KAAK,cAAc,EAMpB,MAAM,8BAA8B,CAAC;AAKtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAatE;yEACyE;AACzE,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,cAAc,CAAC,SAAS,CAAC,CAAC;IACnC,OAAO,CAAC,EAAE,OAAO,CA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AC,cAAc;CA6IvB"}
@@ -50,9 +50,9 @@ import { EventEmitter } from 'node:events';
50
50
  import { Client, InsufficientScopeError, SdkError, SdkErrorCode, SdkHttpError, StreamableHTTPClientTransport, UnsupportedProtocolVersionError, parseJSONRPCMessage, } from '@modelcontextprotocol/client';
51
51
  import { StdioTransport } from './transport.js';
52
52
  import { McplProtocolVersionError, McplRequestError, McplUnreapedLaunchError } from './server-connection.js';
53
- import { LEGACY_MCP_PROTOCOL_VERSION, MAX_TIMER_MS, MODERN_MCP_PROTOCOL_VERSION, checkServerConfig, describeCredentialError, noteDialSent, redactServerText, serverTextRedactor } from './protocol-family.js';
53
+ import { LEGACY_MCP_PROTOCOL_VERSION, MAX_TIMER_MS, MODERN_MCP_PROTOCOL_VERSION, checkServerConfig, describeCredentialError, maskedError, noteDialSent, redactServerText, redactedData, serverTextRedactor } from './protocol-family.js';
54
54
  import { boundedForLog } from './errors.js';
55
- import { logDetail, logValue, logValueRedacted } from './log-value.js';
55
+ import { logDetail, logValue, logValueRedacted, loggedCode } from './log-value.js';
56
56
  const DEFAULT_REQUEST_TIMEOUT_MS = 60_000;
57
57
  /** Bound on establishing the connection (`server/discover`), like the legacy
58
58
  * engine's initialize timeout. */
@@ -78,6 +78,11 @@ class NotWrittenError extends Error {
78
78
  /** The logical request a send belongs to. The SDK hands each request to the
79
79
  * transport inside the caller's async chain, so the scope reaches `send`. */
80
80
  const wireScope = new AsyncLocalStorage();
81
+ /** A send in flight, its transport, and what that transport reported
82
+ * meanwhile, held until the send settles (ObservedTransport.send). A
83
+ * scope that names no transport, a notification's or a settled send's,
84
+ * holds nothing. */
85
+ const sendScope = new AsyncLocalStorage();
81
86
  /**
82
87
  * The boundary between the SDK and the actual transport. It records, for the
83
88
  * logical request in scope, each request of the observed method that it
@@ -117,14 +122,36 @@ class ObservedTransport {
117
122
  else
118
123
  this.onmessage?.(message, extra);
119
124
  };
120
- this.inner.onerror = (error) => this.onerror?.(error);
125
+ // An error this transport reports while one of its sends is in flight
126
+ // waits for that send to settle: the SDK's HTTP send reports a failure
127
+ // here and then throws it, and whoever sent it reports what it throws
128
+ // (#556). Anything else is reported at once, another transport's report
129
+ // made in a send's async context too.
130
+ this.inner.onerror = (error) => {
131
+ const sending = sendScope.getStore();
132
+ if (sending?.wire === this)
133
+ sending.held.push(error);
134
+ else
135
+ this.onerror?.(error);
136
+ };
121
137
  this.inner.onclose = () => this.onclose?.();
122
138
  await this.inner.start();
123
139
  }
124
140
  async send(message, options) {
141
+ if ('method' in message && !('id' in message)) {
142
+ // A notification's sender can swallow what its send throws (the SDK's
143
+ // listen teardown does), so what its transport reports is reported at
144
+ // once, whatever send it was made in.
145
+ await sendScope.run({ wire: null, held: [] }, () => this.inner.send(message, options));
146
+ return;
147
+ }
125
148
  const record = wireScope.getStore();
126
149
  let undo;
127
150
  if (record && 'method' in message && 'id' in message && message.method === record.method) {
151
+ // Every transport writes a message as JSON, so one JSON can't write (a
152
+ // BigInt, a cycle) never leaves this host: it's refused here, before
153
+ // it's marked handed off (#556).
154
+ JSON.stringify(message);
128
155
  const prior = { handedOff: record.handedOff, currentId: record.currentId, answer: record.answer, error: record.error };
129
156
  // Handed off from here on: past this point nothing proves it unsent,
130
157
  // unless the transport says it wrote nothing.
@@ -138,10 +165,17 @@ class ObservedTransport {
138
165
  Object.assign(record, prior);
139
166
  };
140
167
  }
168
+ // A request's or a response's sender reports what its send throws: a
169
+ // call through its outcome, the connect through its failure, the SDK
170
+ // through its own report. So what the transport reports meanwhile is held
171
+ // here, and the failure the send threw isn't reported a second time (#556).
172
+ const sending = { wire: this, held: [] };
173
+ let thrown;
141
174
  try {
142
- await this.inner.send(message, options);
175
+ await sendScope.run(sending, () => this.inner.send(message, options));
143
176
  }
144
177
  catch (error) {
178
+ thrown = error;
145
179
  // Refused before any write: this leg never reached the server, so the
146
180
  // record is as it was before it. Any other throw (an HTTP send can fail
147
181
  // after part of the request went out) leaves it handed off.
@@ -149,6 +183,17 @@ class ObservedTransport {
149
183
  undo?.();
150
184
  throw error;
151
185
  }
186
+ finally {
187
+ // Settled: what was held goes on, but for the failure the send threw,
188
+ // and the scope lets go of this transport, which work the send started
189
+ // still carries.
190
+ const { held } = sending;
191
+ sending.wire = null;
192
+ sending.held = [];
193
+ for (const error of held)
194
+ if (error !== thrown)
195
+ this.onerror?.(error);
196
+ }
152
197
  }
153
198
  async close() {
154
199
  await this.inner.close();
@@ -221,7 +266,7 @@ class SpawnerStdioTransport {
221
266
  constructor(config, onStderr,
222
267
  /** The child's pipe failed and it outlived SIGKILL too, so the line
223
268
  * stays open, owning it (the line's 'unreaped'): `reason` names the
224
- * pipe's error. */
269
+ * pipe's error, and `failure` is the reap's. */
225
270
  onUnreaped) {
226
271
  this.config = config;
227
272
  this.onStderr = onStderr;
@@ -259,14 +304,19 @@ class SpawnerStdioTransport {
259
304
  line.on('stderr', (text) => this.onStderr(text));
260
305
  line.on('error', (error) => this.onerror?.(error));
261
306
  line.on('close', () => this.onclose?.());
262
- line.on('unreaped', () => this.onUnreaped(`its stdio pipe failed with ${line.pipeFailure?.message ?? 'an error'}`));
307
+ line.on('unreaped', (failure) => this.onUnreaped(`its stdio pipe failed with ${line.pipeFailure?.message ?? 'an error'}`, failure));
308
+ }
309
+ /** The first error on the child's stdin or stdout, once there is one: the
310
+ * line is ending the child then, and writes nothing more to it. */
311
+ get pipeFailure() {
312
+ return this.line?.pipeFailure;
263
313
  }
264
314
  async send(message) {
265
315
  if (!this.line || this.line.closed)
266
316
  throw new NotWrittenError(`MCP server "${this.config.id}" stdio transport is closed`);
267
317
  // Once the child's stdin or stdout has failed, the line is ending it and
268
318
  // writes nothing more to it, so a message is refused here as not sent.
269
- const failed = this.line.pipeFailure;
319
+ const failed = this.pipeFailure;
270
320
  if (failed)
271
321
  throw new NotWrittenError(`MCP server "${this.config.id}" stdio pipe failed with ${failed.message}`, true);
272
322
  this.line.writeLine(JSON.stringify(message));
@@ -347,6 +397,12 @@ export class ModernMcpConnection extends EventEmitter {
347
397
  * connect() returns), delivered to the first listener. Bounded: the
348
398
  * newest lines are kept. */
349
399
  stderrBacklog = [];
400
+ redactor;
401
+ /** The server's text with its configuration's credentials replaced, for
402
+ * the errors this connection hands its caller and its records. */
403
+ get recorded() {
404
+ return (this.redactor ??= serverTextRedactor(this.config));
405
+ }
350
406
  constructor(config) {
351
407
  super();
352
408
  this.config = config;
@@ -404,7 +460,8 @@ export class ModernMcpConnection extends EventEmitter {
404
460
  * While it's true the connection owns that child, so whatever registered
405
461
  * it keeps its id held; close() retries the reap. It's settled only once
406
462
  * a reap has finished: while a lost session's reap or a close runs, it
407
- * reads false, so read it once lossReaped() or close() has settled. */
463
+ * may not read true yet, so read it once lossReaped() or close() has
464
+ * settled. */
408
465
  get holdsUnreapedChild() {
409
466
  return this.unreaped.length > 0;
410
467
  }
@@ -415,11 +472,16 @@ export class ModernMcpConnection extends EventEmitter {
415
472
  return this.losing?.done ?? Promise.resolve();
416
473
  }
417
474
  /** A failed generation's cleanup couldn't reap its child: keep owning it,
418
- * and halt reconnecting until close() settles it. */
419
- holdUnreaped(session, failure) {
475
+ * and halt reconnecting until close() settles it. It's reported as an
476
+ * 'error' at once, unless the caller reports it later itself. */
477
+ holdUnreaped(session, failure, report = true) {
420
478
  if (this.unreaped.some((held) => held.session === session))
421
479
  return;
422
480
  this.unreaped.push({ session, failure });
481
+ if (report)
482
+ this.reportUnreaped(failure);
483
+ }
484
+ reportUnreaped(failure) {
423
485
  this.emit('error', new Error(`MCP server "${this.id}": ${failure.message}. Not starting another launch while it may still be running; close the connection to retry the reap.`));
424
486
  }
425
487
  /** The halt, as a permanent failure for the reconnect events. */
@@ -467,11 +529,17 @@ export class ModernMcpConnection extends EventEmitter {
467
529
  this.reconnectEnabled = false;
468
530
  throw error;
469
531
  }
532
+ // Any other failure is the SDK's or the transport's: it goes on as its
533
+ // words alone, redacted, since its message can quote the url and its
534
+ // other properties, such as Bun's fetch error's `path` or a wrapper's
535
+ // `cause`, can carry it whole (maskedError). The protocol refusal
536
+ // above was built from redacted words.
537
+ const masked = maskedError(error, this.recorded);
470
538
  // A launch that couldn't be reaped halts reconnecting, so no retry
471
539
  // will come: the first connect fails, as one without reconnect does.
472
540
  if (!this.reconnectEnabled || this.holdsUnreapedChild)
473
- throw error;
474
- console.error(`MCP server "${this.id}" initial connect failed, will retry:`, redactServerText(error.message, this.config));
541
+ throw masked;
542
+ console.error(`MCP server "${this.id}" initial connect failed, will retry:`, masked.message);
475
543
  this.reconnectAttempts = 1;
476
544
  this.emit('connect-failed', { error: error.message, attempt: 0 });
477
545
  this.scheduleReconnect();
@@ -510,16 +578,18 @@ export class ModernMcpConnection extends EventEmitter {
510
578
  // reopen backs off from the base interval, not from the previous
511
579
  // generation's failures.
512
580
  this.relistenAttempts = 0;
513
- const inner = this.transportKind === 'stdio'
581
+ const stdio = this.transportKind === 'stdio'
514
582
  ? new SpawnerStdioTransport(this.config, (line) => { if (this.isCurrent(generation))
515
583
  this.deliverStderr(line); },
516
- // A child whose pipe failed and that outlived SIGKILL: a loss, whose
517
- // reap finds the child still running and holds the launch, as for any
518
- // launch it can't reap. During a connect there is no session to lose
519
- // yet: the connect's own cleanup holds it, once the connect fails.
520
- (reason) => { if (this.isCurrent(generation))
521
- this.handleLost(generation, reason); })
522
- : new StreamableHTTPClientTransport(new URL(this.config.url), { authProvider: bearerAuth(this.config) });
584
+ // A child whose pipe failed and that outlived SIGKILL: a loss whose
585
+ // launch is already known unreaped, so it's held as the loss is
586
+ // handled (handleLost). During a connect there is no session to lose
587
+ // yet: a connect whose pipe has failed fails, whether or not the SDK
588
+ // resolves it (establish), and its cleanup holds the launch.
589
+ (reason, failure) => { if (this.isCurrent(generation))
590
+ this.handleLost(generation, reason, failure); })
591
+ : null;
592
+ const inner = stdio ?? new StreamableHTTPClientTransport(new URL(this.config.url), { authProvider: bearerAuth(this.config) });
523
593
  const wire = new ObservedTransport(inner);
524
594
  const client = new Client({ name: 'agent-framework', version: '1.0.0' }, {
525
595
  versionNegotiation: { mode: { pin: MODERN_MCP_PROTOCOL_VERSION } },
@@ -535,7 +605,7 @@ export class ModernMcpConnection extends EventEmitter {
535
605
  },
536
606
  },
537
607
  });
538
- const session = { generation, client, wire, lost: false };
608
+ const session = { generation, client, wire, stdio, lost: false };
539
609
  client.onerror = (error) => {
540
610
  // The SDK reports late responses to deadline-abandoned calls here
541
611
  // ("unknown message ID"), and a list-change subscription it could not
@@ -585,17 +655,24 @@ export class ModernMcpConnection extends EventEmitter {
585
655
  this.holdUnreaped(session, failure);
586
656
  return;
587
657
  }
588
- if (session.lost) {
589
- // The transport closed while the client connected, such as a child
590
- // that exited at the connect-time list-change subscribe: the SDK
591
- // reports that subscribe's failure only as an error, and resolves the
592
- // connect anyway (R1-2). Adopted, the session would read as connected
593
- // with nothing behind it, and no later close would come to reconnect
594
- // it. So the connect failed.
658
+ // The transport closed while the client connected, such as a child that
659
+ // exited at the connect-time list-change subscribe, or the child's stdio
660
+ // pipe failed, such as that subscribe's write meeting EPIPE: the SDK
661
+ // reports the subscribe's failure only as an error, and resolves the
662
+ // connect anyway (R1-2). Adopted, the session would read as connected
663
+ // with nothing it can write to behind it, and from a child that outlived
664
+ // SIGKILL, whose 'unreaped' came while there was no session to lose, no
665
+ // later close would come to reconnect it. So the connect failed: its
666
+ // close reaps the child, and a child it can't reap is held. A failed
667
+ // pipe is named whether or not the child has exited by now.
668
+ const pipe = session.stdio?.pipeFailure;
669
+ if (session.lost || pipe) {
595
670
  const failure = await ModernMcpConnection.closeSession(session);
596
671
  if (failure)
597
672
  this.holdUnreaped(session, failure);
598
- throw new Error(`MCP server "${this.id}" closed its connection while connecting`);
673
+ throw new Error(pipe
674
+ ? `MCP server "${this.id}" stdio pipe failed with ${pipe.message} while connecting`
675
+ : `MCP server "${this.id}" closed its connection while connecting`);
599
676
  }
600
677
  this.session = session;
601
678
  this.protocolVersion = MODERN_MCP_PROTOCOL_VERSION;
@@ -611,7 +688,11 @@ export class ModernMcpConnection extends EventEmitter {
611
688
  versionVerdict(error) {
612
689
  if (!(error instanceof UnsupportedProtocolVersionError))
613
690
  return null;
614
- const data = error.data;
691
+ // The server's words and data, redacted before they're bounded or kept:
692
+ // the error goes to the host. One build for all of them, so a
693
+ // configuration that can't be read is read once.
694
+ const redact = this.recorded.now();
695
+ const data = redactedData(error.data, redact);
615
696
  const supported = Array.isArray(data?.supported) && data.supported.every((v) => typeof v === 'string')
616
697
  ? data.supported
617
698
  : null;
@@ -624,8 +705,8 @@ export class ModernMcpConnection extends EventEmitter {
624
705
  ? ` It speaks legacy MCP: configure it without protocol: 'modern'.`
625
706
  : ` It speaks only legacy MCP, which this client reaches over stdio or WebSocket (ws://, wss://), not http(s).`;
626
707
  return new McplProtocolVersionError(`MCP server "${this.id}" does not support MCP ${MODERN_MCP_PROTOCOL_VERSION}` +
627
- (supported ? ` (it supports: ${supported.join(', ') || 'none listed'}).` : ` (${error.message}).`) +
628
- legacyHint, 'rejected', null, supported, error.code === undefined ? undefined : Number(error.code), error.data, MODERN_MCP_PROTOCOL_VERSION);
708
+ (supported ? ` (it supports: ${boundedForLog(supported.join(', ')) || 'none listed'}).` : ` (${boundedForLog(redact(error.message))}).`) +
709
+ legacyHint, 'rejected', null, supported, error.code === undefined ? undefined : Number(error.code), data, MODERN_MCP_PROTOCOL_VERSION);
629
710
  }
630
711
  /**
631
712
  * Keep list-change awareness while this generation lives. The SDK opens the
@@ -690,8 +771,10 @@ export class ModernMcpConnection extends EventEmitter {
690
771
  this.scheduleRelisten(generation);
691
772
  }
692
773
  }
693
- /** The transport went away (child exit, or a closed HTTP client). */
694
- handleLost(generation, reason) {
774
+ /** The transport went away (child exit, or a closed HTTP client).
775
+ * `unreaped`: the child's pipe failed and it outlived SIGKILL, so its
776
+ * launch is already known unreaped. */
777
+ handleLost(generation, reason, unreaped) {
695
778
  const session = this.session;
696
779
  if (session?.generation !== generation)
697
780
  return;
@@ -704,21 +787,42 @@ export class ModernMcpConnection extends EventEmitter {
704
787
  // reconnect's does, and is a permanent failure, as that one is: no
705
788
  // later attempt will come. The reap starts, and is recorded, before
706
789
  // 'close' is emitted, so a listener that throws can't skip it.
790
+ const permanent = () => this.emit('reconnect-failed', { error: `${reason}; ${this.unreapedFailure()}`, attempt: Math.max(1, this.reconnectAttempts), permanent: true });
707
791
  const done = ModernMcpConnection.closeSession(session).then((failure) => {
708
792
  if (this.losing?.session === session)
709
793
  this.losing = null;
794
+ // A close() the host made meanwhile reports the failure itself.
795
+ if (unreaped) {
796
+ // Held as the loss was handled, whatever the reap found now.
797
+ if (!this.closedByHost)
798
+ permanent();
799
+ return;
800
+ }
710
801
  if (failure) {
711
802
  this.holdUnreaped(session, failure);
712
- // A close() the host made meanwhile reports the failure itself.
713
- if (!this.closedByHost) {
714
- this.emit('reconnect-failed', { error: `${reason}; ${this.unreapedFailure()}`, attempt: Math.max(1, this.reconnectAttempts), permanent: true });
715
- }
803
+ if (!this.closedByHost)
804
+ permanent();
716
805
  }
717
806
  else if (this.willReconnect)
718
807
  this.scheduleReconnect();
719
808
  });
720
809
  this.losing = { session, done };
721
- this.emit('close', { reason });
810
+ // A launch already known unreaped is held now, before 'close', so the
811
+ // calls the reap's close ends, which classify their failure only once
812
+ // this returns, and any made meanwhile, read that this host won't
813
+ // reconnect, as the legacy engine has it (#540's review, R1-1). It's
814
+ // reported after 'close', which is where the other route reports a hold
815
+ // too, whatever the 'close' listeners do, so a listener that throws can
816
+ // skip neither 'close' nor the report.
817
+ if (unreaped)
818
+ this.holdUnreaped(session, unreaped, false);
819
+ try {
820
+ this.emit('close', { reason });
821
+ }
822
+ finally {
823
+ if (unreaped)
824
+ this.reportUnreaped(unreaped);
825
+ }
722
826
  }
723
827
  /** The legacy engine's backoff: doubling from the base interval, capped,
724
828
  * with ±25% jitter, and never past the timer limit (a longer delay would
@@ -944,9 +1048,9 @@ export class ModernMcpConnection extends EventEmitter {
944
1048
  * The rules apply in this order. The call's answer is the server's final
945
1049
  * one: an error or a `complete` result.
946
1050
  * - nothing handed to the transport: `not-sent`, whatever was raised (a
947
- * pre-dispatch validation, a signal already aborted, no transport, a send
948
- * Connectome's stdio line refused before writing, an HTTP refusal before
949
- * any request went out);
1051
+ * pre-dispatch validation, a signal already aborted, no transport, a
1052
+ * message JSON can't write, a send Connectome's stdio line refused
1053
+ * before writing);
950
1054
  * - the most recent leg answered with a JSON-RPC error: `error-response`
951
1055
  * with that error's data;
952
1056
  * - the most recent leg answered with a complete result: the server
@@ -982,7 +1086,10 @@ export class ModernMcpConnection extends EventEmitter {
982
1086
  requestFailure(what, record, error, timeoutMs, lost = false) {
983
1087
  const server = `the "${this.id}" server`;
984
1088
  const Server = `The "${this.id}" server`;
985
- const message = redactServerText(error instanceof Error ? error.message : String(error), this.config);
1089
+ // One build of the redactor for all of this failure's texts, so a
1090
+ // configuration that can't be read is read once.
1091
+ const redact = this.recorded.now();
1092
+ const message = redact(error instanceof Error ? error.message : String(error));
986
1093
  const log = (line) => console.error(`MCP server "${this.id}" ${line}`);
987
1094
  const listing = record.method === 'tools/list';
988
1095
  // What a failure whose effect is in doubt says: for a tool call, that the
@@ -1003,15 +1110,18 @@ export class ModernMcpConnection extends EventEmitter {
1003
1110
  }
1004
1111
  if (record.answer === 'error' && record.error) {
1005
1112
  const { code, message: wireMessage, data } = record.error;
1006
- // A JSON-RPC answer reaches the caller unredacted (redactServerText's
1007
- // scope). The log is a record of the server's text, so the message is
1008
- // redacted there, whatever JSON value it is, as every other line this
1009
- // connection writes is.
1010
- log(`answered ${what} with error ${logValue(code)}: ${logValueRedacted(wireMessage, (text) => redactServerText(text, this.config))}`);
1011
- // The server's own words, bounded as errors.ts says. Only a string is
1012
- // words: a message of any other JSON value reads as none.
1013
- const said = typeof wireMessage === 'string' ? boundedForLog(wireMessage.trim()) : '';
1014
- return new McplRequestError(said ? `${Server} answered with an error: ${said}` : unknown(`${Server} answered with an error without saying what went wrong`), 'error-response', data);
1113
+ // The log is a record of the server's text, so the code (loggedCode)
1114
+ // and the message are redacted there, whatever JSON values they are,
1115
+ // as every other line this connection writes is.
1116
+ log(`answered ${what} with error ${loggedCode(code, redact)}: ${logValueRedacted(wireMessage, redact)}`);
1117
+ // The server's own words, redacted and then bounded as errors.ts says,
1118
+ // since they're in an error the caller gets (redactServerText's
1119
+ // scope), and its data's strings redacted too. It's trimmed after it's
1120
+ // redacted, so a credential that ends in a space is whole when it's
1121
+ // matched. Only a string is words: a message of any other JSON value
1122
+ // reads as none.
1123
+ const said = typeof wireMessage === 'string' ? boundedForLog(redact(wireMessage).trim()) : '';
1124
+ return new McplRequestError(said ? `${Server} answered with an error: ${said}` : unknown(`${Server} answered with an error without saying what went wrong`), 'error-response', redactedData(data, redact));
1015
1125
  }
1016
1126
  if (record.answer === 'complete') {
1017
1127
  log(`answered ${what} with a result this host can't use: ${logDetail(message)}`);
@@ -1050,7 +1160,12 @@ export class ModernMcpConnection extends EventEmitter {
1050
1160
  // The response body (the SDK's `text`) is the server's text and can
1051
1161
  // echo the request's url, so it's left out of the data; the status stays.
1052
1162
  const { text: _body, ...data } = (error instanceof SdkHttpError && error.data && typeof error.data === 'object' ? error.data : {});
1053
- return new McplRequestError(`${Server} refused this host access, so the request didn't run. If you need it, ask whoever runs this host.`, 'error-response', { ...data, httpStatus: refusedWith });
1163
+ const redacted = redactedData(data, redact);
1164
+ return new McplRequestError(`${Server} refused this host access, so the request didn't run. If you need it, ask whoever runs this host.`, 'error-response',
1165
+ // The status is this host's own, so it's added after the server's
1166
+ // data is redacted, and it stays when a configuration that can't be
1167
+ // read withholds that data.
1168
+ { ...(redacted !== null && typeof redacted === 'object' ? redacted : {}), httpStatus: refusedWith });
1054
1169
  }
1055
1170
  if (deadline) {
1056
1171
  log(`didn't answer ${what}${within}; cancellation requested`);