@workerstack/clients 0.0.0-stage → 1.0.0-rc.24

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 (558) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +619 -2
  3. package/bin/honey-clients.js +94 -0
  4. package/dist/cli.d.ts +102 -0
  5. package/dist/cli.js +190 -0
  6. package/dist/emit/cli/channels.d.ts +73 -0
  7. package/dist/emit/cli/channels.js +197 -0
  8. package/dist/emit/cli/commands.d.ts +27 -0
  9. package/dist/emit/cli/commands.js +187 -0
  10. package/dist/emit/cli/discovery.d.ts +35 -0
  11. package/dist/emit/cli/discovery.js +202 -0
  12. package/dist/emit/cli/flags.d.ts +59 -0
  13. package/dist/emit/cli/flags.js +186 -0
  14. package/dist/emit/cli/index.d.ts +1 -0
  15. package/dist/emit/cli/index.js +1 -0
  16. package/dist/emit/cli/install.d.ts +37 -0
  17. package/dist/emit/cli/install.js +88 -0
  18. package/dist/emit/cli/layout.d.ts +23 -0
  19. package/dist/emit/cli/layout.js +118 -0
  20. package/dist/emit/cli/module.d.ts +30 -0
  21. package/dist/emit/cli/module.js +186 -0
  22. package/dist/emit/cli/release.d.ts +40 -0
  23. package/dist/emit/cli/release.js +183 -0
  24. package/dist/emit/cli/skills.d.ts +11 -0
  25. package/dist/emit/cli/skills.js +56 -0
  26. package/dist/emit/csharp/errors.d.ts +7 -0
  27. package/dist/emit/csharp/errors.js +69 -0
  28. package/dist/emit/csharp/index.d.ts +1 -0
  29. package/dist/emit/csharp/index.js +1 -0
  30. package/dist/emit/csharp/json.d.ts +13 -0
  31. package/dist/emit/csharp/json.js +113 -0
  32. package/dist/emit/csharp/realtime.d.ts +10 -0
  33. package/dist/emit/csharp/realtime.js +33 -0
  34. package/dist/emit/csharp/sdk-answer.d.ts +48 -0
  35. package/dist/emit/csharp/sdk-answer.js +85 -0
  36. package/dist/emit/csharp/sdk-body.d.ts +10 -0
  37. package/dist/emit/csharp/sdk-body.js +87 -0
  38. package/dist/emit/csharp/sdk-client.d.ts +32 -0
  39. package/dist/emit/csharp/sdk-client.js +177 -0
  40. package/dist/emit/csharp/sdk-csproj.d.ts +36 -0
  41. package/dist/emit/csharp/sdk-csproj.js +136 -0
  42. package/dist/emit/csharp/sdk-doc.d.ts +12 -0
  43. package/dist/emit/csharp/sdk-doc.js +35 -0
  44. package/dist/emit/csharp/sdk-method.d.ts +26 -0
  45. package/dist/emit/csharp/sdk-method.js +187 -0
  46. package/dist/emit/csharp/sdk-plan.d.ts +38 -0
  47. package/dist/emit/csharp/sdk-plan.js +1 -0
  48. package/dist/emit/csharp/sdk.d.ts +40 -0
  49. package/dist/emit/csharp/sdk.js +105 -0
  50. package/dist/emit/csharp/sse.d.ts +18 -0
  51. package/dist/emit/csharp/sse.js +29 -0
  52. package/dist/emit/csharp/transport.d.ts +11 -0
  53. package/dist/emit/csharp/transport.js +67 -0
  54. package/dist/emit/csharp/types-enum.d.ts +19 -0
  55. package/dist/emit/csharp/types-enum.js +63 -0
  56. package/dist/emit/csharp/types-names.d.ts +33 -0
  57. package/dist/emit/csharp/types-names.js +182 -0
  58. package/dist/emit/csharp/types-record.d.ts +25 -0
  59. package/dist/emit/csharp/types-record.js +65 -0
  60. package/dist/emit/csharp/types-union.d.ts +27 -0
  61. package/dist/emit/csharp/types-union.js +113 -0
  62. package/dist/emit/csharp/types.d.ts +36 -0
  63. package/dist/emit/csharp/types.js +126 -0
  64. package/dist/emit/csharp/ws.d.ts +20 -0
  65. package/dist/emit/csharp/ws.js +14 -0
  66. package/dist/emit/go/errors.d.ts +7 -0
  67. package/dist/emit/go/errors.js +44 -0
  68. package/dist/emit/go/http.d.ts +11 -0
  69. package/dist/emit/go/http.js +50 -0
  70. package/dist/emit/go/index.d.ts +1 -0
  71. package/dist/emit/go/index.js +1 -0
  72. package/dist/emit/go/module-path.d.ts +2 -0
  73. package/dist/emit/go/module-path.js +27 -0
  74. package/dist/emit/go/sdk-answer.d.ts +28 -0
  75. package/dist/emit/go/sdk-answer.js +41 -0
  76. package/dist/emit/go/sdk-body.d.ts +24 -0
  77. package/dist/emit/go/sdk-body.js +76 -0
  78. package/dist/emit/go/sdk-client.d.ts +29 -0
  79. package/dist/emit/go/sdk-client.js +141 -0
  80. package/dist/emit/go/sdk-method.d.ts +68 -0
  81. package/dist/emit/go/sdk-method.js +172 -0
  82. package/dist/emit/go/sdk-mirror.d.ts +23 -0
  83. package/dist/emit/go/sdk-mirror.js +97 -0
  84. package/dist/emit/go/sdk-opts.d.ts +55 -0
  85. package/dist/emit/go/sdk-opts.js +100 -0
  86. package/dist/emit/go/sdk.d.ts +26 -0
  87. package/dist/emit/go/sdk.js +111 -0
  88. package/dist/emit/go/sse.d.ts +16 -0
  89. package/dist/emit/go/sse.js +26 -0
  90. package/dist/emit/go/types-codec.d.ts +15 -0
  91. package/dist/emit/go/types-codec.js +171 -0
  92. package/dist/emit/go/types-names.d.ts +14 -0
  93. package/dist/emit/go/types-names.js +64 -0
  94. package/dist/emit/go/types-struct.d.ts +29 -0
  95. package/dist/emit/go/types-struct.js +65 -0
  96. package/dist/emit/go/types-union.d.ts +17 -0
  97. package/dist/emit/go/types-union.js +84 -0
  98. package/dist/emit/go/types.d.ts +32 -0
  99. package/dist/emit/go/types.js +177 -0
  100. package/dist/emit/go/ws.d.ts +12 -0
  101. package/dist/emit/go/ws.js +70 -0
  102. package/dist/emit/java/gradle.d.ts +57 -0
  103. package/dist/emit/java/gradle.js +221 -0
  104. package/dist/emit/java/index.d.ts +2 -0
  105. package/dist/emit/java/index.js +2 -0
  106. package/dist/emit/java/json.d.ts +13 -0
  107. package/dist/emit/java/json.js +84 -0
  108. package/dist/emit/java/layout-ast.d.ts +146 -0
  109. package/dist/emit/java/layout-ast.js +102 -0
  110. package/dist/emit/java/layout-decl.d.ts +20 -0
  111. package/dist/emit/java/layout-decl.js +155 -0
  112. package/dist/emit/java/layout-doc.d.ts +55 -0
  113. package/dist/emit/java/layout-doc.js +166 -0
  114. package/dist/emit/java/layout-dot.d.ts +18 -0
  115. package/dist/emit/java/layout-dot.js +127 -0
  116. package/dist/emit/java/layout-strings.d.ts +8 -0
  117. package/dist/emit/java/layout-strings.js +76 -0
  118. package/dist/emit/java/layout-types.d.ts +11 -0
  119. package/dist/emit/java/layout-types.js +95 -0
  120. package/dist/emit/java/layout-visitor.d.ts +38 -0
  121. package/dist/emit/java/layout-visitor.js +232 -0
  122. package/dist/emit/java/layout.d.ts +61 -0
  123. package/dist/emit/java/layout.js +121 -0
  124. package/dist/emit/java/models-enum.d.ts +17 -0
  125. package/dist/emit/java/models-enum.js +51 -0
  126. package/dist/emit/java/models-names.d.ts +29 -0
  127. package/dist/emit/java/models-names.js +97 -0
  128. package/dist/emit/java/models-record.d.ts +24 -0
  129. package/dist/emit/java/models-record.js +79 -0
  130. package/dist/emit/java/models-union.d.ts +27 -0
  131. package/dist/emit/java/models-union.js +86 -0
  132. package/dist/emit/java/models.d.ts +28 -0
  133. package/dist/emit/java/models.js +118 -0
  134. package/dist/emit/java/realtime.d.ts +50 -0
  135. package/dist/emit/java/realtime.js +69 -0
  136. package/dist/emit/java/sdk-client.d.ts +66 -0
  137. package/dist/emit/java/sdk-client.js +207 -0
  138. package/dist/emit/java/sdk-decl.d.ts +11 -0
  139. package/dist/emit/java/sdk-decl.js +63 -0
  140. package/dist/emit/java/sdk-errors.d.ts +13 -0
  141. package/dist/emit/java/sdk-errors.js +141 -0
  142. package/dist/emit/java/sdk-headers.d.ts +12 -0
  143. package/dist/emit/java/sdk-headers.js +74 -0
  144. package/dist/emit/java/sdk-mirror.d.ts +14 -0
  145. package/dist/emit/java/sdk-mirror.js +107 -0
  146. package/dist/emit/java/sdk-models.d.ts +16 -0
  147. package/dist/emit/java/sdk-models.js +68 -0
  148. package/dist/emit/java/sdk-op.d.ts +57 -0
  149. package/dist/emit/java/sdk-op.js +216 -0
  150. package/dist/emit/java/sdk-params.d.ts +38 -0
  151. package/dist/emit/java/sdk-params.js +133 -0
  152. package/dist/emit/java/sdk-plan.d.ts +52 -0
  153. package/dist/emit/java/sdk-plan.js +1 -0
  154. package/dist/emit/java/sdk-record.d.ts +16 -0
  155. package/dist/emit/java/sdk-record.js +99 -0
  156. package/dist/emit/java/sdk.d.ts +49 -0
  157. package/dist/emit/java/sdk.js +216 -0
  158. package/dist/emit/java/sse.d.ts +35 -0
  159. package/dist/emit/java/sse.js +57 -0
  160. package/dist/emit/java/ws.d.ts +27 -0
  161. package/dist/emit/java/ws.js +31 -0
  162. package/dist/emit/mcp/annotations.d.ts +15 -0
  163. package/dist/emit/mcp/annotations.js +15 -0
  164. package/dist/emit/mcp/files.d.ts +18 -0
  165. package/dist/emit/mcp/files.js +42 -0
  166. package/dist/emit/mcp/index.d.ts +3 -0
  167. package/dist/emit/mcp/index.js +3 -0
  168. package/dist/emit/mcp/literal.d.ts +2 -0
  169. package/dist/emit/mcp/literal.js +33 -0
  170. package/dist/emit/mcp/mounted.d.ts +21 -0
  171. package/dist/emit/mcp/mounted.js +89 -0
  172. package/dist/emit/mcp/output-schema.d.ts +18 -0
  173. package/dist/emit/mcp/output-schema.js +38 -0
  174. package/dist/emit/mcp/registry.d.ts +23 -0
  175. package/dist/emit/mcp/registry.js +83 -0
  176. package/dist/emit/mcp/runtime.d.ts +10 -0
  177. package/dist/emit/mcp/runtime.js +47 -0
  178. package/dist/emit/mcp/schema.d.ts +19 -0
  179. package/dist/emit/mcp/schema.js +88 -0
  180. package/dist/emit/mcp/server.d.ts +30 -0
  181. package/dist/emit/mcp/server.js +246 -0
  182. package/dist/emit/mcp/tools.d.ts +51 -0
  183. package/dist/emit/mcp/tools.js +153 -0
  184. package/dist/emit/python/errors.d.ts +8 -0
  185. package/dist/emit/python/errors.js +68 -0
  186. package/dist/emit/python/index.d.ts +1 -0
  187. package/dist/emit/python/index.js +1 -0
  188. package/dist/emit/python/realtime.d.ts +10 -0
  189. package/dist/emit/python/realtime.js +33 -0
  190. package/dist/emit/python/sdk-answer.d.ts +49 -0
  191. package/dist/emit/python/sdk-answer.js +89 -0
  192. package/dist/emit/python/sdk-body.d.ts +11 -0
  193. package/dist/emit/python/sdk-body.js +40 -0
  194. package/dist/emit/python/sdk-client.d.ts +36 -0
  195. package/dist/emit/python/sdk-client.js +163 -0
  196. package/dist/emit/python/sdk-doc.d.ts +9 -0
  197. package/dist/emit/python/sdk-doc.js +32 -0
  198. package/dist/emit/python/sdk-imports.d.ts +14 -0
  199. package/dist/emit/python/sdk-imports.js +38 -0
  200. package/dist/emit/python/sdk-method.d.ts +29 -0
  201. package/dist/emit/python/sdk-method.js +183 -0
  202. package/dist/emit/python/sdk-plan.d.ts +33 -0
  203. package/dist/emit/python/sdk-plan.js +1 -0
  204. package/dist/emit/python/sdk-pyproject.d.ts +27 -0
  205. package/dist/emit/python/sdk-pyproject.js +103 -0
  206. package/dist/emit/python/sdk.d.ts +22 -0
  207. package/dist/emit/python/sdk.js +154 -0
  208. package/dist/emit/python/sse.d.ts +12 -0
  209. package/dist/emit/python/sse.js +23 -0
  210. package/dist/emit/python/transport.d.ts +15 -0
  211. package/dist/emit/python/transport.js +60 -0
  212. package/dist/emit/python/types-dict.d.ts +31 -0
  213. package/dist/emit/python/types-dict.js +45 -0
  214. package/dist/emit/python/types-names.d.ts +16 -0
  215. package/dist/emit/python/types-names.js +52 -0
  216. package/dist/emit/python/types-union.d.ts +32 -0
  217. package/dist/emit/python/types-union.js +46 -0
  218. package/dist/emit/python/types.d.ts +36 -0
  219. package/dist/emit/python/types.js +128 -0
  220. package/dist/emit/python/ws.d.ts +14 -0
  221. package/dist/emit/python/ws.js +16 -0
  222. package/dist/emit/rust/errors.d.ts +7 -0
  223. package/dist/emit/rust/errors.js +107 -0
  224. package/dist/emit/rust/http.d.ts +13 -0
  225. package/dist/emit/rust/http.js +67 -0
  226. package/dist/emit/rust/index.d.ts +1 -0
  227. package/dist/emit/rust/index.js +1 -0
  228. package/dist/emit/rust/realtime.d.ts +11 -0
  229. package/dist/emit/rust/realtime.js +29 -0
  230. package/dist/emit/rust/sdk-body.d.ts +19 -0
  231. package/dist/emit/rust/sdk-body.js +53 -0
  232. package/dist/emit/rust/sdk-cargo.d.ts +43 -0
  233. package/dist/emit/rust/sdk-cargo.js +178 -0
  234. package/dist/emit/rust/sdk-client.d.ts +25 -0
  235. package/dist/emit/rust/sdk-client.js +108 -0
  236. package/dist/emit/rust/sdk-method.d.ts +15 -0
  237. package/dist/emit/rust/sdk-method.js +119 -0
  238. package/dist/emit/rust/sdk-opts.d.ts +58 -0
  239. package/dist/emit/rust/sdk-opts.js +117 -0
  240. package/dist/emit/rust/sdk-plan.d.ts +33 -0
  241. package/dist/emit/rust/sdk-plan.js +1 -0
  242. package/dist/emit/rust/sdk.d.ts +23 -0
  243. package/dist/emit/rust/sdk.js +111 -0
  244. package/dist/emit/rust/sse.d.ts +19 -0
  245. package/dist/emit/rust/sse.js +20 -0
  246. package/dist/emit/rust/types-enum.d.ts +13 -0
  247. package/dist/emit/rust/types-enum.js +62 -0
  248. package/dist/emit/rust/types-names.d.ts +19 -0
  249. package/dist/emit/rust/types-names.js +66 -0
  250. package/dist/emit/rust/types-struct.d.ts +21 -0
  251. package/dist/emit/rust/types-struct.js +59 -0
  252. package/dist/emit/rust/types-union.d.ts +24 -0
  253. package/dist/emit/rust/types-union.js +97 -0
  254. package/dist/emit/rust/types.d.ts +34 -0
  255. package/dist/emit/rust/types.js +105 -0
  256. package/dist/emit/rust/ws.d.ts +21 -0
  257. package/dist/emit/rust/ws.js +20 -0
  258. package/dist/emit/shared/escape.d.ts +55 -0
  259. package/dist/emit/shared/escape.js +144 -0
  260. package/dist/emit/shared/format.d.ts +24 -0
  261. package/dist/emit/shared/format.js +23 -0
  262. package/dist/emit/shared/gofmt.d.ts +3 -0
  263. package/dist/emit/shared/gofmt.js +26 -0
  264. package/dist/emit/shared/lang.d.ts +60 -0
  265. package/dist/emit/shared/lang.js +233 -0
  266. package/dist/emit/shared/literals.d.ts +4 -0
  267. package/dist/emit/shared/literals.js +31 -0
  268. package/dist/emit/shared/metadata.d.ts +106 -0
  269. package/dist/emit/shared/metadata.js +130 -0
  270. package/dist/emit/shared/mirror.d.ts +22 -0
  271. package/dist/emit/shared/mirror.js +26 -0
  272. package/dist/emit/shared/ruff.d.ts +3 -0
  273. package/dist/emit/shared/ruff.js +31 -0
  274. package/dist/emit/shared/rustfmt.d.ts +3 -0
  275. package/dist/emit/shared/rustfmt.js +32 -0
  276. package/dist/emit/shared/status-keys.d.ts +7 -0
  277. package/dist/emit/shared/status-keys.js +67 -0
  278. package/dist/emit/shared/type-emitter.d.ts +19 -0
  279. package/dist/emit/shared/type-emitter.js +100 -0
  280. package/dist/emit/ts/app-client.d.ts +4 -0
  281. package/dist/emit/ts/app-client.js +68 -0
  282. package/dist/emit/ts/http.d.ts +20 -0
  283. package/dist/emit/ts/http.js +74 -0
  284. package/dist/emit/ts/package.d.ts +36 -0
  285. package/dist/emit/ts/package.js +126 -0
  286. package/dist/emit/ts/route-tree.d.ts +68 -0
  287. package/dist/emit/ts/route-tree.js +240 -0
  288. package/dist/emit/ts/sdk-types-preamble.d.ts +14 -0
  289. package/dist/emit/ts/sdk-types-preamble.js +123 -0
  290. package/dist/emit/ts/sdk-types.d.ts +13 -0
  291. package/dist/emit/ts/sdk-types.js +213 -0
  292. package/dist/emit/ts/sdk.d.ts +21 -0
  293. package/dist/emit/ts/sdk.js +173 -0
  294. package/dist/emit/ts/service-map.d.ts +40 -0
  295. package/dist/emit/ts/service-map.js +171 -0
  296. package/dist/emit/ts/tanstack-query.d.ts +12 -0
  297. package/dist/emit/ts/tanstack-query.js +156 -0
  298. package/dist/emit/ts/type-gen.d.ts +26 -0
  299. package/dist/emit/ts/type-gen.js +255 -0
  300. package/dist/emit/ts/webhooks.d.ts +19 -0
  301. package/dist/emit/ts/webhooks.js +81 -0
  302. package/dist/extract/chain.d.ts +34 -0
  303. package/dist/extract/chain.js +84 -0
  304. package/dist/extract/extract.d.ts +41 -0
  305. package/dist/extract/extract.js +191 -0
  306. package/dist/extract/serialize.d.ts +34 -0
  307. package/dist/extract/serialize.js +295 -0
  308. package/dist/extract/walk.d.ts +47 -0
  309. package/dist/extract/walk.js +109 -0
  310. package/dist/gen/args.d.ts +28 -0
  311. package/dist/gen/args.js +133 -0
  312. package/dist/gen/formatters.d.ts +62 -0
  313. package/dist/gen/formatters.js +146 -0
  314. package/dist/gen/process.d.ts +13 -0
  315. package/dist/gen/process.js +35 -0
  316. package/dist/gen/shipped.d.ts +17 -0
  317. package/dist/gen/shipped.js +55 -0
  318. package/dist/gen/targets.d.ts +93 -0
  319. package/dist/gen/targets.js +171 -0
  320. package/dist/gen/write.d.ts +33 -0
  321. package/dist/gen/write.js +118 -0
  322. package/dist/index.d.ts +13 -0
  323. package/dist/index.js +15 -0
  324. package/dist/ir/build.d.ts +37 -0
  325. package/dist/ir/build.js +152 -0
  326. package/dist/ir/load.d.ts +11 -0
  327. package/dist/ir/load.js +112 -0
  328. package/dist/ir/model.d.ts +206 -0
  329. package/dist/ir/model.js +5 -0
  330. package/dist/ir/resolve-refs.d.ts +11 -0
  331. package/dist/ir/resolve-refs.js +66 -0
  332. package/dist/ir/resource-tree.d.ts +9 -0
  333. package/dist/ir/resource-tree.js +53 -0
  334. package/dist/ir/route-tree-intern.d.ts +18 -0
  335. package/dist/ir/route-tree-intern.js +174 -0
  336. package/dist/ir/schema.d.ts +11 -0
  337. package/dist/ir/schema.js +192 -0
  338. package/dist/ir/sdk-model.d.ts +86 -0
  339. package/dist/ir/sdk-model.js +204 -0
  340. package/dist/ir/slots.d.ts +42 -0
  341. package/dist/ir/slots.js +245 -0
  342. package/dist/runtime/cli/body.go +176 -0
  343. package/dist/runtime/cli/config.go +243 -0
  344. package/dist/runtime/cli/discovery.go +147 -0
  345. package/dist/runtime/cli/format.go +174 -0
  346. package/dist/runtime/cli/log.go +117 -0
  347. package/dist/runtime/cli/output.go +247 -0
  348. package/dist/runtime/cli/params.go +197 -0
  349. package/dist/runtime/cli/run.go +226 -0
  350. package/dist/runtime/cli/socket.go +60 -0
  351. package/dist/runtime/cli/stream.go +217 -0
  352. package/dist/runtime/cli/target.go +117 -0
  353. package/dist/runtime/csharp/Adapters.cs +183 -0
  354. package/dist/runtime/csharp/Auth.cs +56 -0
  355. package/dist/runtime/csharp/Body.cs +135 -0
  356. package/dist/runtime/csharp/Config.cs +161 -0
  357. package/dist/runtime/csharp/Envelope.cs +149 -0
  358. package/dist/runtime/csharp/Errors.cs +194 -0
  359. package/dist/runtime/csharp/Events.cs +155 -0
  360. package/dist/runtime/csharp/Exchange.cs +247 -0
  361. package/dist/runtime/csharp/Handler.cs +103 -0
  362. package/dist/runtime/csharp/Hooks.cs +128 -0
  363. package/dist/runtime/csharp/Invalidation.cs +102 -0
  364. package/dist/runtime/csharp/Json.cs +144 -0
  365. package/dist/runtime/csharp/Log.cs +48 -0
  366. package/dist/runtime/csharp/Operation.cs +33 -0
  367. package/dist/runtime/csharp/Path.cs +65 -0
  368. package/dist/runtime/csharp/Query.cs +72 -0
  369. package/dist/runtime/csharp/Realtime.cs +118 -0
  370. package/dist/runtime/csharp/RealtimeLoop.cs +236 -0
  371. package/dist/runtime/csharp/Redirect.cs +53 -0
  372. package/dist/runtime/csharp/Result.cs +57 -0
  373. package/dist/runtime/csharp/Sse.cs +122 -0
  374. package/dist/runtime/csharp/Stale.cs +151 -0
  375. package/dist/runtime/csharp/Transport.cs +143 -0
  376. package/dist/runtime/csharp/TransportLongPoll.cs +63 -0
  377. package/dist/runtime/csharp/TransportSse.cs +54 -0
  378. package/dist/runtime/csharp/TransportWs.cs +40 -0
  379. package/dist/runtime/csharp/Wire.cs +109 -0
  380. package/dist/runtime/csharp/Ws.cs +300 -0
  381. package/dist/runtime/csharp/WsDial.cs +127 -0
  382. package/dist/runtime/go/auth.go +127 -0
  383. package/dist/runtime/go/body.go +129 -0
  384. package/dist/runtime/go/config.go +75 -0
  385. package/dist/runtime/go/errors.go +185 -0
  386. package/dist/runtime/go/export.go +37 -0
  387. package/dist/runtime/go/hooks.go +53 -0
  388. package/dist/runtime/go/invalidation.go +112 -0
  389. package/dist/runtime/go/log.go +92 -0
  390. package/dist/runtime/go/nullable.go +64 -0
  391. package/dist/runtime/go/options.go +118 -0
  392. package/dist/runtime/go/path.go +156 -0
  393. package/dist/runtime/go/query.go +147 -0
  394. package/dist/runtime/go/realtime.go +239 -0
  395. package/dist/runtime/go/realtime_loop.go +208 -0
  396. package/dist/runtime/go/redirect.go +124 -0
  397. package/dist/runtime/go/request.go +222 -0
  398. package/dist/runtime/go/result.go +86 -0
  399. package/dist/runtime/go/sse.go +186 -0
  400. package/dist/runtime/go/stale.go +229 -0
  401. package/dist/runtime/go/stream.go +105 -0
  402. package/dist/runtime/go/transport.go +242 -0
  403. package/dist/runtime/go/transport_longpoll.go +121 -0
  404. package/dist/runtime/go/transport_sse.go +175 -0
  405. package/dist/runtime/go/ws.go +205 -0
  406. package/dist/runtime/java/Answer.java +107 -0
  407. package/dist/runtime/java/ApiException.java +110 -0
  408. package/dist/runtime/java/BinaryBody.java +36 -0
  409. package/dist/runtime/java/Body.java +105 -0
  410. package/dist/runtime/java/Call.java +23 -0
  411. package/dist/runtime/java/CallLog.java +51 -0
  412. package/dist/runtime/java/ClientConfig.java +233 -0
  413. package/dist/runtime/java/ConnectionState.java +12 -0
  414. package/dist/runtime/java/Credential.java +58 -0
  415. package/dist/runtime/java/Deadline.java +38 -0
  416. package/dist/runtime/java/Decode.java +181 -0
  417. package/dist/runtime/java/Envelope.java +141 -0
  418. package/dist/runtime/java/ErrorEnvelope.java +23 -0
  419. package/dist/runtime/java/EventStream.java +129 -0
  420. package/dist/runtime/java/Exchange.java +62 -0
  421. package/dist/runtime/java/FilePart.java +5 -0
  422. package/dist/runtime/java/Flight.java +306 -0
  423. package/dist/runtime/java/HoneyException.java +14 -0
  424. package/dist/runtime/java/Hooks.java +47 -0
  425. package/dist/runtime/java/Hops.java +133 -0
  426. package/dist/runtime/java/InvalidationConfig.java +73 -0
  427. package/dist/runtime/java/Json.java +23 -0
  428. package/dist/runtime/java/Keepalive.java +60 -0
  429. package/dist/runtime/java/LogEntry.java +14 -0
  430. package/dist/runtime/java/LongPollAdapter.java +68 -0
  431. package/dist/runtime/java/Operation.java +21 -0
  432. package/dist/runtime/java/Opt.java +121 -0
  433. package/dist/runtime/java/Pump.java +160 -0
  434. package/dist/runtime/java/RawResponse.java +48 -0
  435. package/dist/runtime/java/Realtime.java +152 -0
  436. package/dist/runtime/java/RealtimeLoop.java +371 -0
  437. package/dist/runtime/java/RedirectPolicy.java +13 -0
  438. package/dist/runtime/java/Redirects.java +126 -0
  439. package/dist/runtime/java/RequestContext.java +78 -0
  440. package/dist/runtime/java/RequestHook.java +9 -0
  441. package/dist/runtime/java/RequestOptions.java +91 -0
  442. package/dist/runtime/java/ResponseContext.java +70 -0
  443. package/dist/runtime/java/ResponseHook.java +12 -0
  444. package/dist/runtime/java/Result.java +32 -0
  445. package/dist/runtime/java/ResumableConnection.java +165 -0
  446. package/dist/runtime/java/SdkException.java +11 -0
  447. package/dist/runtime/java/Socket.java +301 -0
  448. package/dist/runtime/java/Sse.java +171 -0
  449. package/dist/runtime/java/SseAdapter.java +61 -0
  450. package/dist/runtime/java/SseEvent.java +10 -0
  451. package/dist/runtime/java/StaleMeta.java +16 -0
  452. package/dist/runtime/java/StaleTracker.java +287 -0
  453. package/dist/runtime/java/Transport.java +16 -0
  454. package/dist/runtime/java/TransportAdapter.java +14 -0
  455. package/dist/runtime/java/TransportConnection.java +15 -0
  456. package/dist/runtime/java/TransportKind.java +12 -0
  457. package/dist/runtime/java/TransportMessage.java +9 -0
  458. package/dist/runtime/java/TransportOptions.java +138 -0
  459. package/dist/runtime/java/TypedWebSocket.java +83 -0
  460. package/dist/runtime/java/UrlPath.java +49 -0
  461. package/dist/runtime/java/UrlQuery.java +99 -0
  462. package/dist/runtime/java/WsAdapter.java +52 -0
  463. package/dist/runtime/java/WsClose.java +47 -0
  464. package/dist/runtime/java/WsDial.java +148 -0
  465. package/dist/runtime/java/WsMessage.java +18 -0
  466. package/dist/runtime/mcp/call.ts +167 -0
  467. package/dist/runtime/mcp/files.ts +183 -0
  468. package/dist/runtime/mcp/guard.ts +176 -0
  469. package/dist/runtime/mcp/http.ts +159 -0
  470. package/dist/runtime/mcp/jsonrpc.ts +50 -0
  471. package/dist/runtime/mcp/listen.ts +76 -0
  472. package/dist/runtime/mcp/mount.ts +123 -0
  473. package/dist/runtime/mcp/protocol.ts +219 -0
  474. package/dist/runtime/mcp/reader.ts +57 -0
  475. package/dist/runtime/mcp/result.ts +85 -0
  476. package/dist/runtime/mcp/stdio.ts +79 -0
  477. package/dist/runtime/mcp/stream.ts +62 -0
  478. package/dist/runtime/python/__init__.py +2 -0
  479. package/dist/runtime/python/auth.py +67 -0
  480. package/dist/runtime/python/body.py +83 -0
  481. package/dist/runtime/python/config.py +139 -0
  482. package/dist/runtime/python/errors.py +213 -0
  483. package/dist/runtime/python/events.py +152 -0
  484. package/dist/runtime/python/exchange.py +298 -0
  485. package/dist/runtime/python/hooks.py +86 -0
  486. package/dist/runtime/python/invalidation.py +57 -0
  487. package/dist/runtime/python/log.py +60 -0
  488. package/dist/runtime/python/operation.py +25 -0
  489. package/dist/runtime/python/path.py +41 -0
  490. package/dist/runtime/python/query.py +48 -0
  491. package/dist/runtime/python/realtime.py +244 -0
  492. package/dist/runtime/python/redirect.py +93 -0
  493. package/dist/runtime/python/result.py +58 -0
  494. package/dist/runtime/python/send_async.py +189 -0
  495. package/dist/runtime/python/send_sync.py +105 -0
  496. package/dist/runtime/python/sse.py +81 -0
  497. package/dist/runtime/python/stale.py +94 -0
  498. package/dist/runtime/python/transport.py +157 -0
  499. package/dist/runtime/python/transport_longpoll.py +60 -0
  500. package/dist/runtime/python/transport_sse.py +60 -0
  501. package/dist/runtime/python/transport_ws.py +57 -0
  502. package/dist/runtime/python/ws.py +276 -0
  503. package/dist/runtime/rust/Cargo.lock +1763 -0
  504. package/dist/runtime/rust/answer.rs +120 -0
  505. package/dist/runtime/rust/auth.rs +80 -0
  506. package/dist/runtime/rust/body.rs +150 -0
  507. package/dist/runtime/rust/call.rs +200 -0
  508. package/dist/runtime/rust/config.rs +254 -0
  509. package/dist/runtime/rust/envelope.rs +84 -0
  510. package/dist/runtime/rust/errors.rs +235 -0
  511. package/dist/runtime/rust/events.rs +177 -0
  512. package/dist/runtime/rust/exchange.rs +287 -0
  513. package/dist/runtime/rust/hooks.rs +63 -0
  514. package/dist/runtime/rust/invalidation.rs +84 -0
  515. package/dist/runtime/rust/log.rs +88 -0
  516. package/dist/runtime/rust/nullable.rs +13 -0
  517. package/dist/runtime/rust/path.rs +83 -0
  518. package/dist/runtime/rust/query.rs +84 -0
  519. package/dist/runtime/rust/realtime.rs +182 -0
  520. package/dist/runtime/rust/realtime_loop.rs +177 -0
  521. package/dist/runtime/rust/redirect.rs +121 -0
  522. package/dist/runtime/rust/request.rs +178 -0
  523. package/dist/runtime/rust/result.rs +101 -0
  524. package/dist/runtime/rust/sse.rs +104 -0
  525. package/dist/runtime/rust/stale.rs +209 -0
  526. package/dist/runtime/rust/transport.rs +221 -0
  527. package/dist/runtime/rust/transport_longpoll.rs +108 -0
  528. package/dist/runtime/rust/transport_sse.rs +91 -0
  529. package/dist/runtime/rust/transport_ws.rs +75 -0
  530. package/dist/runtime/rust/ws.rs +322 -0
  531. package/dist/runtime/ts/app-types.ts +200 -0
  532. package/dist/runtime/ts/app.ts +104 -0
  533. package/dist/runtime/ts/config.ts +124 -0
  534. package/dist/runtime/ts/defaults.ts +48 -0
  535. package/dist/runtime/ts/error.ts +113 -0
  536. package/dist/runtime/ts/hooks.ts +92 -0
  537. package/dist/runtime/ts/http.ts +228 -0
  538. package/dist/runtime/ts/media-type.ts +36 -0
  539. package/dist/runtime/ts/path.ts +152 -0
  540. package/dist/runtime/ts/realtime-connection.ts +296 -0
  541. package/dist/runtime/ts/realtime-transports.ts +149 -0
  542. package/dist/runtime/ts/realtime.ts +293 -0
  543. package/dist/runtime/ts/redirect-policy.ts +17 -0
  544. package/dist/runtime/ts/redirects.ts +74 -0
  545. package/dist/runtime/ts/request.ts +239 -0
  546. package/dist/runtime/ts/response.ts +219 -0
  547. package/dist/runtime/ts/sdk-realtime.ts +10 -0
  548. package/dist/runtime/ts/sdk-sse.ts +55 -0
  549. package/dist/runtime/ts/sdk-ws.ts +21 -0
  550. package/dist/runtime/ts/sdk.ts +242 -0
  551. package/dist/runtime/ts/sse.ts +175 -0
  552. package/dist/runtime/ts/stale.ts +137 -0
  553. package/dist/runtime/ts/stream.ts +87 -0
  554. package/dist/runtime/ts/webhook.ts +116 -0
  555. package/dist/runtime/ts/ws.ts +155 -0
  556. package/dist/runtime/ts-tanstack-query/invalidate.ts +152 -0
  557. package/dist/runtime/ts-tanstack-query/query.ts +261 -0
  558. package/package.json +135 -5
@@ -0,0 +1,123 @@
1
+ /**
2
+ * MCP mounted in the app itself (bit 21 e), web-standard: each request served over http.ts by tools bound to an SDK
3
+ * client of its own, whose fetch dispatches in-process to the app. Only the request headers its security schemes name
4
+ * go on each inner request, and only to the app's own origin: a call off it is refused, never sent. An inner 401, or
5
+ * a 403 for insufficient_scope, is the endpoint's own answer with its challenge, never a tool's result. Bit 21 g: the
6
+ * file-uploads extension advertised for a file tool; the app's uploads (bound to the request's credential headers) and
7
+ * URL fetch reach each call; without the fetch no file argument shows its `{url}` value.
8
+ */
9
+ import { bindTools, type SdkClient, type ToolSpec } from "./call.ts"
10
+ import { type FetchFile, filesCapability, type Uploads } from "./files.ts"
11
+ import { serveHttp } from "./http.ts"
12
+ import { createProtocol, type ServerInfo } from "./protocol.ts"
13
+ import { BYTES_MAX } from "./result.ts"
14
+
15
+ /** The SDK config a mounted call runs under. */
16
+ export type MountConfig = {
17
+ readonly baseURL: string
18
+ readonly fetch: typeof fetch
19
+ readonly maxResponseBytes: number
20
+ readonly onResponse?: (() => undefined)[]
21
+ readonly redirect: "same-origin"
22
+ readonly timeout: number
23
+ }
24
+
25
+ /**
26
+ * What a mount hands each request: the in-process dispatch, the origins served beside its own, the body cap, and the
27
+ * app's opt-ins: its uploads for this request, its URL fetch.
28
+ */
29
+ export type Mount = {
30
+ readonly dispatch: (request: Request) => Promise<Response>
31
+ readonly origins?: readonly string[]
32
+ readonly max?: number
33
+ readonly uploads?: Uploads | undefined
34
+ readonly fetchFile?: FetchFile | undefined
35
+ }
36
+
37
+ /** `schema`, a file argument's, without its `{url}` value. */
38
+ const urlless = (schema: Record<string, unknown>) => ({
39
+ ...schema,
40
+ anyOf: (schema.anyOf as { properties?: { url?: unknown } }[]).filter((value) => !value.properties?.url),
41
+ })
42
+
43
+ /** `spec` with no file argument showing a `{url}` value. */
44
+ function fetchless(spec: ToolSpec): ToolSpec {
45
+ if (spec.parts === undefined) return spec
46
+ const properties = { ...(spec.inputSchema.properties as Record<string, Record<string, unknown>>) }
47
+ for (const [property, , kind] of spec.parts)
48
+ if (kind !== "text") {
49
+ const own = properties[property] as Record<string, unknown>
50
+ properties[property] =
51
+ kind === "file" ? urlless(own) : { ...own, items: urlless(own.items as Record<string, unknown>) }
52
+ }
53
+ return { ...spec, inputSchema: { ...spec.inputSchema, properties } }
54
+ }
55
+
56
+ /** The generated handler: whether any tool's operation needs a credential, the scheme a 401 names, the endpoint. */
57
+ export type Mounted = {
58
+ readonly secured: boolean
59
+ readonly challenge: string
60
+ readonly fetch: (request: Request, mount: Mount) => Promise<Response>
61
+ }
62
+
63
+ /** A mounted server: its tools and SDK, the credential headers, its server path. */
64
+ export type Mounting = {
65
+ readonly info: ServerInfo
66
+ readonly specs: readonly ToolSpec[]
67
+ readonly client: (config: MountConfig) => SdkClient
68
+ readonly credentials: readonly string[]
69
+ readonly secured: boolean
70
+ readonly challenge: string
71
+ readonly server: string
72
+ }
73
+
74
+ /** The handler serving `mounting`'s tools at a mount, each call bound to 30 s. */
75
+ export function mountedMcp(mounting: Mounting): Mounted {
76
+ const { challenge, client, credentials, info, secured, server } = mounting
77
+ const timeout = 30_000
78
+ const extensions = mounting.specs.some((spec) => spec.parts?.some(([, , kind]) => kind !== "text"))
79
+ ? filesCapability(BYTES_MAX)
80
+ : undefined
81
+ const shown = mounting.specs.map(fetchless)
82
+ return {
83
+ challenge,
84
+ fetch: async (request, { dispatch, fetchFile, max, origins, uploads }) => {
85
+ const origin = new URL(request.url).origin
86
+ const carried = credentials.flatMap((name) => {
87
+ const value = request.headers.get(name)
88
+ return value === null ? [] : [[name, value] as const]
89
+ })
90
+ let refused: Response | undefined
91
+ const inner = async (input: RequestInfo | URL, init?: RequestInit) => {
92
+ const sent = new Request(input, init)
93
+ if (new URL(sent.url).origin !== origin) throw new TypeError("Refused: a call off this app's origin")
94
+ for (const [name, value] of carried) sent.headers.set(name, value)
95
+ const answer = await dispatch(sent)
96
+ const scope = answer.status === 403 && /insufficient_scope/.test(answer.headers.get("www-authenticate") ?? "")
97
+ if (answer.status === 401 || scope) refused ??= answer
98
+ return answer
99
+ }
100
+ const config: MountConfig = {
101
+ baseURL: origin + server,
102
+ fetch: inner as typeof fetch,
103
+ maxResponseBytes: BYTES_MAX,
104
+ redirect: "same-origin",
105
+ timeout,
106
+ }
107
+ const tools = bindTools(fetchFile ? mounting.specs : shown, client(config), {
108
+ opening: (seen) => client({ ...config, onResponse: [() => void seen()] }),
109
+ /* each credential as sent, and its token after the scheme */
110
+ secrets: carried.flatMap(([, value]) => [value, value.replace(/^\S+ +/, "")]),
111
+ timeout,
112
+ })
113
+ const credential = carried.map(([name, value]) => `${name}: ${value}`).join("\n")
114
+ const files = { credential, ...(fetchFile && { fetch: fetchFile }), ...(uploads && { uploads }) }
115
+ const answer = await serveHttp(createProtocol(info, tools, extensions), { files, max, origins })(request)
116
+ if (refused === undefined) return answer
117
+ await answer.body?.cancel()
118
+ const named = refused.headers.get("www-authenticate") ?? challenge
119
+ return new Response(null, { headers: { "www-authenticate": named }, status: refused.status })
120
+ },
121
+ secured,
122
+ }
123
+ }
@@ -0,0 +1,219 @@
1
+ /**
2
+ * The MCP server's protocol (bit 18; dual-era, bit 21 b), whatever the transport. A request whose `_meta` names its
3
+ * revision is modern (2026-07-28), served from itself alone: server/discover, tools/list (cached) and tools/call, each
4
+ * result complete; another revision refused naming those served. Any other is legacy: initialize negotiates 2025-11-25
5
+ * down to 2025-03-26 into the connection, then ping, tools/list and tools/call; under 2025-03-26 no outputSchema, no
6
+ * structuredContent, and only there a batch. A fault answers at once, a call when done; a tool's failure is its result.
7
+ * A call with a progressToken may report progress, each step a notifications/progress before its result. A transport
8
+ * that reads files (bit 21 c: stdio) hands each call its reader; a mount its uploads and fetch, a modern call its
9
+ * params, so it may answer an input request or refuse its state (bit 21 g). `extensions` are advertised in both eras.
10
+ */
11
+ import type { Files } from "./files.ts"
12
+ import { ErrorCode, failure, type Id, isId, type Message, type Reply, result } from "./jsonrpc.ts"
13
+
14
+ /** The revisions served, newest first: the modern, then each an initialize may negotiate, the newest by default. */
15
+ export const PROTOCOL_VERSIONS = ["2026-07-28", "2025-11-25", "2025-06-18", "2025-03-26"] as const
16
+
17
+ /* the one with per-request _meta; the first with outputSchema and structuredContent; the last with batches */
18
+ export const [MODERN, LEGACY, STRUCTURED_SINCE, BATCHED] = PROTOCOL_VERSIONS
19
+ export const VERSION = "io.modelcontextprotocol/protocolVersion"
20
+ const CAPABILITIES = "io.modelcontextprotocol/clientCapabilities"
21
+
22
+ /* a modern result is complete; a list cached by its caller alone, 5 minutes */
23
+ const COMPLETE = { resultType: "complete" }
24
+ const CACHED = { ...COMPLETE, cacheScope: "private", ttlMs: 300_000 }
25
+
26
+ /** A tool's result: its content, its structured value when it has an outputSchema, and whether it failed. */
27
+ export type ToolResult = {
28
+ readonly content: readonly Record<string, unknown>[]
29
+ readonly structuredContent?: Record<string, unknown>
30
+ readonly isError?: true
31
+ readonly _meta?: Record<string, unknown>
32
+ }
33
+
34
+ /** A call's answer: its result, a modern call's input request, or its params refused. */
35
+ export type Outcome = ToolResult | { readonly inputRequired: Record<string, unknown> } | { readonly invalid: string }
36
+
37
+ /** A tool: what tools/list shows of it, and what tools/call runs. */
38
+ export type Tool = {
39
+ readonly name: string
40
+ readonly description?: string
41
+ readonly inputSchema: Record<string, unknown>
42
+ readonly outputSchema?: Record<string, unknown>
43
+ readonly annotations?: Record<string, boolean>
44
+ readonly call: (
45
+ args: Record<string, unknown>,
46
+ signal: AbortSignal,
47
+ progress: (done: number) => void,
48
+ files?: Files,
49
+ ) => Promise<Outcome>
50
+ }
51
+
52
+ /** Who the server is, as initialize and server/discover answer. */
53
+ export type ServerInfo = { readonly name: string; readonly version: string }
54
+
55
+ /** A connection's legacy revision, once its initialize negotiated one. */
56
+ export type Connection = { version?: string }
57
+
58
+ /** A message's abort, where its notifications go, its connection, and its transport's files. */
59
+ export type Context = {
60
+ readonly signal: AbortSignal
61
+ readonly notify: (message: object) => void
62
+ readonly connection: Connection
63
+ readonly files?: Files
64
+ }
65
+
66
+ /** Each message's reply, a batch's, or none; a promise only for a call, never rejected. */
67
+ export type Protocol = {
68
+ readonly answer: (
69
+ message: unknown,
70
+ context: Context,
71
+ ) => Reply | Reply[] | undefined | Promise<Reply | Reply[] | undefined>
72
+ }
73
+
74
+ /** Whether `value` is a JSON object. */
75
+ export const isObject = (value: unknown): value is Record<string, unknown> =>
76
+ typeof value === "object" && value !== null && !Array.isArray(value)
77
+
78
+ /** The tools/list entry for `tool`: its outputSchema only when `structured`. */
79
+ function listed(tool: Tool, structured: boolean): Record<string, unknown> {
80
+ return {
81
+ name: tool.name,
82
+ ...(tool.description === undefined ? {} : { description: tool.description }),
83
+ inputSchema: tool.inputSchema,
84
+ ...(structured && tool.outputSchema !== undefined ? { outputSchema: tool.outputSchema } : {}),
85
+ ...(tool.annotations === undefined ? {} : { annotations: tool.annotations }),
86
+ }
87
+ }
88
+
89
+ /** `outcome` without structuredContent unless `structured`. */
90
+ function shaped(outcome: ToolResult, structured: boolean): ToolResult {
91
+ if (structured || outcome.structuredContent === undefined) return outcome
92
+ const { structuredContent: _, ...rest } = outcome
93
+ return rest
94
+ }
95
+
96
+ /** A modern request's `_meta`: one that names its revision. */
97
+ export function claimed(params: Record<string, unknown>): Record<string, unknown> | undefined {
98
+ const meta = params._meta
99
+ return isObject(meta) && VERSION in meta ? meta : undefined
100
+ }
101
+
102
+ /** A request as a tools/call reads it: its id and its params. */
103
+ type Asked = { readonly id: Id; readonly params: Record<string, unknown> }
104
+
105
+ /** A modern request's refusal: a `_meta` without its revision or the client's capabilities, or a revision not served. */
106
+ export function unserved(id: Id, meta: Record<string, unknown>): Reply | undefined {
107
+ const asked = meta[VERSION]
108
+ if (typeof asked !== "string" || !isObject(meta[CAPABILITIES]))
109
+ return failure(id, ErrorCode.InvalidParams, `Invalid params: needs ${VERSION} and ${CAPABILITIES}`)
110
+ if (asked !== MODERN)
111
+ return failure(id, ErrorCode.UnsupportedProtocolVersion, "Unsupported protocol version", {
112
+ requested: asked,
113
+ supported: PROTOCOL_VERSIONS,
114
+ })
115
+ return undefined
116
+ }
117
+
118
+ /** A tools/call of `tool` under `version`: a fault at once, else its result when done; a handler's fault internal. */
119
+ function called({ id, params }: Asked, tool: Tool | undefined, version: string, context: Context) {
120
+ if (tool === undefined) return failure(id, ErrorCode.InvalidParams, `Unknown tool: ${String(params.name)}`)
121
+ const args = params.arguments ?? {}
122
+ if (!isObject(args)) return failure(id, ErrorCode.InvalidParams, "Tool arguments must be an object")
123
+ const token = (params._meta as { progressToken?: unknown } | undefined)?.progressToken
124
+ const progress = (done: number) =>
125
+ (typeof token === "string" || typeof token === "number") &&
126
+ context.notify({
127
+ jsonrpc: "2.0",
128
+ method: "notifications/progress",
129
+ params: { progress: done, progressToken: token },
130
+ })
131
+ const modern = version === MODERN
132
+ const client = modern ? (claimed(params)?.[CAPABILITIES] as Files["client"]) : undefined
133
+ return tool
134
+ .call(args, context.signal, progress, modern ? { ...context.files, asked: params, client } : context.files)
135
+ .then(
136
+ (outcome) =>
137
+ "invalid" in outcome
138
+ ? failure(id, ErrorCode.InvalidParams, `Invalid params: ${outcome.invalid}`)
139
+ : result(
140
+ id,
141
+ "inputRequired" in outcome
142
+ ? { ...outcome.inputRequired, resultType: "input_required" }
143
+ : { ...shaped(outcome, version >= STRUCTURED_SINCE), ...(modern && COMPLETE) },
144
+ ),
145
+ () => failure(id, ErrorCode.InternalError, "Internal error"),
146
+ )
147
+ }
148
+
149
+ /** A batch's replies, `one` answering each: only 2025-03-26 has batches, every later revision dropped them. */
150
+ function batch(
151
+ one: (message: unknown, context: Context) => Reply | Promise<Reply> | undefined,
152
+ messages: unknown[],
153
+ context: Context,
154
+ ) {
155
+ if (messages.length === 0 || context.connection.version !== BATCHED)
156
+ return failure(null, ErrorCode.InvalidRequest, "Invalid Request")
157
+ return Promise.all(messages.map((message) => one(message, context))).then((replies) => {
158
+ const answered = replies.filter((reply) => reply !== undefined) as Reply[]
159
+ return answered.length === 0 ? undefined : answered
160
+ })
161
+ }
162
+
163
+ /** The protocol over `tools`, as `info` names the server, advertising `extensions`. */
164
+ export function createProtocol(info: ServerInfo, tools: readonly Tool[], extensions?: object): Protocol {
165
+ const capabilities = { tools: {}, ...(extensions && { extensions }) }
166
+ const byName = new Map(tools.map((tool) => [tool.name, tool]))
167
+ /* `method` under `version`: each era's own methods, and the tools in both; undefined for any other method */
168
+ const served = (request: Asked, method: string, version: string, context: Context) => {
169
+ const { id, params } = request
170
+ const modern = version === MODERN
171
+ switch (modern ? method : `legacy ${method}`) {
172
+ case "server/discover":
173
+ return result(id, {
174
+ _meta: { "io.modelcontextprotocol/serverInfo": info },
175
+ capabilities,
176
+ supportedVersions: PROTOCOL_VERSIONS,
177
+ ...CACHED,
178
+ })
179
+ case "legacy initialize":
180
+ context.connection.version =
181
+ PROTOCOL_VERSIONS.slice(1).find((each) => each === params.protocolVersion) ?? LEGACY
182
+ return result(id, {
183
+ capabilities,
184
+ protocolVersion: context.connection.version,
185
+ serverInfo: info,
186
+ })
187
+ case "legacy ping":
188
+ return result(id, {})
189
+ case "tools/list":
190
+ case "legacy tools/list":
191
+ return result(id, {
192
+ tools: tools.map((tool) => listed(tool, version >= STRUCTURED_SINCE)),
193
+ ...(modern && CACHED),
194
+ })
195
+ case "tools/call":
196
+ case "legacy tools/call":
197
+ return called(request, byName.get(String(params.name)), version, context)
198
+ }
199
+ return undefined
200
+ }
201
+ const one = (message: unknown, context: Context): Reply | Promise<Reply> | undefined => {
202
+ const { id, jsonrpc, method, params: given } = (isObject(message) ? message : {}) as Message
203
+ if (jsonrpc !== "2.0" || typeof method !== "string")
204
+ return failure(isId(id) ? id : null, ErrorCode.InvalidRequest, "Invalid Request")
205
+ if (!isId(id)) return undefined
206
+ const params = isObject(given) ? given : {}
207
+ /* a modern request's revision is its own `_meta`'s, never the connection's */
208
+ const meta = claimed(params)
209
+ const version = meta === undefined ? (context.connection.version ?? LEGACY) : MODERN
210
+ return (
211
+ (meta && unserved(id, meta)) ??
212
+ served({ id, params }, method, version, context) ??
213
+ failure(id, ErrorCode.MethodNotFound, `Method not found: ${method}`)
214
+ )
215
+ }
216
+ return {
217
+ answer: (message, context) => (Array.isArray(message) ? batch(one, message, context) : one(message, context)),
218
+ }
219
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The stdio server's file reader (bit 21 c): a path read under a hard root, realpath'd (no `..` or symlink out), opened
3
+ * following no last link and never blocking, its descriptor a regular file, the one realpath named (device and inode),
4
+ * within the cap, read to exactly its size. A hard link to outside the root is no path check's to see. A refusal names
5
+ * its rule, never a path.
6
+ */
7
+ import { constants, realpathSync, statSync } from "node:fs"
8
+ import { open, realpath, stat } from "node:fs/promises"
9
+ import { resolve, sep } from "node:path"
10
+
11
+ /** The calls a read makes: node's, or a test's around them. */
12
+ export type Disk = { readonly open: typeof open; readonly realpath: typeof realpath; readonly stat: typeof stat }
13
+
14
+ /* no last link followed, a FIFO never waited on */
15
+ const FLAGS = constants.O_RDONLY | constants.O_NOFOLLOW | constants.O_NONBLOCK
16
+
17
+ /** Throws `rule`, the reason a read is refused. */
18
+ const refuse = (rule: string): never => {
19
+ throw new Error(rule)
20
+ }
21
+
22
+ /** A reader under `root`, `max` bytes a file; none when `root` is no directory. */
23
+ export function fileReader(root: string, max: number, disk: Disk = { open, realpath, stat }) {
24
+ let base: string
25
+ try {
26
+ base = realpathSync(root)
27
+ if (!statSync(base).isDirectory()) return undefined
28
+ /* a root that resolves to nothing is no directory either */
29
+ } catch {
30
+ return undefined
31
+ }
32
+ const under = base.endsWith(sep) ? base : base + sep
33
+ return async (path: string): Promise<Uint8Array> => {
34
+ const none = () => refuse("names no file under the file root")
35
+ /* nothing there, or a NUL byte: node's own error would name the path */
36
+ const real = await disk.realpath(resolve(base, path)).catch(none)
37
+ if (!real.startsWith(under)) refuse("leaves the file root")
38
+ /* gone since realpath: no file */
39
+ const seen = await disk.stat(real).catch(none)
40
+ /* a socket, or a last link swapped in, opens not */
41
+ const handle = await disk.open(real, FLAGS).catch(() => refuse("is no regular file"))
42
+ try {
43
+ const fd = await handle.stat()
44
+ if (!fd.isFile()) refuse("is no regular file")
45
+ if (fd.dev !== seen.dev || fd.ino !== seen.ino) refuse("changed while it was opened")
46
+ if (fd.size > max) refuse(`is past the ${max}-byte file cap`)
47
+ /* a byte past its size, which a grown file fills */
48
+ const bytes = new Uint8Array(fd.size + 1)
49
+ let got = 0
50
+ for (let read = 1; read > 0 && got < bytes.length; got += read)
51
+ ({ bytesRead: read } = await handle.read(bytes, got, bytes.length - got, got))
52
+ return got === fd.size ? bytes.subarray(0, got) : refuse("changed while it was read")
53
+ } finally {
54
+ await handle.close()
55
+ }
56
+ }
57
+ }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * A tool's result (bit 18 phase d, D1), from the TS SDK's safe answer: JSON as text, and as structuredContent
3
+ * when the tool has an outputSchema; text as text; bytes as image, audio or an embedded resource. A failure is
4
+ * `isError`: an answer outside 2xx or a body the SDK refused (past 1 MiB) its status and error, no answer
5
+ * `transport` or `timeout`. Text is cut past 100,000 characters, a note saying so.
6
+ */
7
+ import { encoded } from "./files.ts"
8
+ import type { ToolResult } from "./protocol.ts"
9
+
10
+ /** The most characters a result's text holds. */
11
+ export const TEXT_MAX = 100_000
12
+
13
+ /** The most bytes a result or a body argument holds. */
14
+ export const BYTES_MAX = 1 << 20
15
+
16
+ /** The TS SDK's safe answer to a call: its Result. */
17
+ export type Answer = { ok: boolean; data?: unknown; error?: unknown; response: Response; headers?: object }
18
+
19
+ /** A result of one text block, cut at TEXT_MAX. */
20
+ export const text = (value: string, isError?: true): ToolResult => ({
21
+ content: [
22
+ {
23
+ text:
24
+ value.length > TEXT_MAX
25
+ ? `${value.slice(0, TEXT_MAX)}\n[cut: ${TEXT_MAX} of ${value.length} characters]`
26
+ : value,
27
+ type: "text",
28
+ },
29
+ ],
30
+ ...(isError ? { isError } : {}),
31
+ })
32
+
33
+ /** A result of `value` as JSON text. */
34
+ export const json = (value: unknown, isError?: true): ToolResult => text(JSON.stringify(value ?? null), isError)
35
+
36
+ /** `bytes` of the media type `type` as the tool's content: an image, audio, or an embedded resource. */
37
+ function bytesResult(bytes: Uint8Array, type: string, tool: string): ToolResult {
38
+ const mimeType = type.split(";")[0]?.trim().toLowerCase() || "application/octet-stream"
39
+ const data = encoded(bytes)
40
+ const kind = mimeType.split("/")[0]
41
+ return {
42
+ content: [
43
+ kind === "image" || kind === "audio"
44
+ ? { data, mimeType, type: kind }
45
+ : { resource: { blob: data, mimeType, uri: `honey://${tool}/result` }, type: "resource" },
46
+ ],
47
+ }
48
+ }
49
+
50
+ /** A scrubber of the API key from a value's strings (guard.ts `redactor`). */
51
+ type Scrub = (value: unknown) => unknown
52
+
53
+ /** The result of a 2xx `answer` for `tool`, structured as its outputSchema says, scrubbed by `scrub`. */
54
+ export function successOf(
55
+ tool: { name: string; outputSchema?: object; wrap?: true },
56
+ answer: Answer,
57
+ scrub: Scrub,
58
+ ): ToolResult {
59
+ const data = answer.data instanceof Uint8Array ? answer.data : scrub(answer.data)
60
+ if (data instanceof Uint8Array) return bytesResult(data, answer.response.headers.get("content-type") ?? "", tool.name)
61
+ if (tool.outputSchema === undefined) return typeof data === "string" ? text(data) : json(data)
62
+ const value = tool.wrap ? { result: data, ...(answer.headers ? { headers: scrub(answer.headers) } : {}) } : data
63
+ if (typeof value !== "object" || value === null || Array.isArray(value))
64
+ return json({ message: "The API answered something other than the object its schema declares" }, true)
65
+ return { ...json(value), structuredContent: value as Record<string, unknown> }
66
+ }
67
+
68
+ /** The result of an `answer` outside 2xx: its status, with honey's error envelope its key and message, else its body. */
69
+ export function failureOf({ error, status }: { error: unknown; status: number }, scrub: Scrub): ToolResult {
70
+ if (error instanceof Error)
71
+ return json(scrub({ status, message: error.message, body: (error as { body?: unknown }).body }), true)
72
+ const { error_key, message } = (error ?? {}) as { error_key?: unknown; message?: unknown }
73
+ const value =
74
+ typeof error_key === "string"
75
+ ? { status, error_key, message }
76
+ : { status, message: `The API answered ${status}`, body: error }
77
+ return json(scrub(value), true)
78
+ }
79
+
80
+ /** The result of a call that got no answer, `error` what it threw: a timeout, else a transport failure. */
81
+ export function unanswered(error: unknown, scrub: Scrub): ToolResult {
82
+ const message = error instanceof Error ? error.message : String(error)
83
+ const kind = (error as { name?: unknown } | null)?.name === "TimeoutError" ? "timeout" : "transport"
84
+ return json(scrub({ kind, message }), true)
85
+ }
@@ -0,0 +1,79 @@
1
+ /**
2
+ * MCP's stdio transport (bit 18): each message one line of JSON on standard input, each reply one line on standard
3
+ * output, nothing else ever written there; a line that is not JSON answered as a parse error. Each message is answered
4
+ * as it comes: a fault at once, in the order it came, a call when it is done, matched by its id, so calls run side by
5
+ * side. One writer writes each reply whole. Bit 21 b: the connection keeps its negotiated legacy revision; a
6
+ * notifications/cancelled aborts the call it names, nothing more written for it. Bit 21 c: `read`, the file reader,
7
+ * reaches every call. The session ends when standard input
8
+ * does, once every reply is written, or when `stop` aborts: every call in flight is aborted with it and settles, and
9
+ * no reply after is written.
10
+ */
11
+ import { ErrorCode, failure, isId } from "./jsonrpc.ts"
12
+ import type { Read } from "./files.ts"
13
+ import type { Connection, Protocol } from "./protocol.ts"
14
+
15
+ /** Where the transport reads and writes: by default the process's standard input and output. */
16
+ export type Stdio = {
17
+ readonly input: NodeJS.ReadableStream
18
+ readonly write: (line: string) => void
19
+ }
20
+
21
+ /** The process's own standard input and output. */
22
+ const processStdio = (): Stdio => ({ input: process.stdin, write: (line) => void process.stdout.write(line) })
23
+
24
+ /** Serves `protocol` over `stdio` until its input ends or `stopped` aborts; settles once the last reply is written. */
25
+ export function serveStdio(
26
+ protocol: Protocol,
27
+ stdio: Stdio = processStdio(),
28
+ stopped?: AbortSignal,
29
+ read?: Read,
30
+ ): Promise<void> {
31
+ const stop = new AbortController()
32
+ const connection: Connection = {}
33
+ /* each call in flight by its id: its own abort */
34
+ const calls = new Map<unknown, AbortController>()
35
+ let pending = ""
36
+ const inFlight = new Set<Promise<void>>()
37
+ const writer = (signal: AbortSignal) => (reply: unknown) =>
38
+ void (signal.aborted || stdio.write(`${JSON.stringify(reply)}\n`))
39
+ const take = (line: string) => {
40
+ let message: { id?: unknown; method?: unknown; params?: { requestId?: unknown } } | null
41
+ try {
42
+ message = JSON.parse(line) as typeof message
43
+ } catch {
44
+ return writer(stop.signal)(failure(null, ErrorCode.ParseError, "Parse error"))
45
+ }
46
+ if (message?.method === "notifications/cancelled") return void calls.get(message.params?.requestId)?.abort()
47
+ const call = new AbortController()
48
+ const signal = AbortSignal.any([stop.signal, call.signal])
49
+ const send = writer(signal)
50
+ const id = message?.id
51
+ const done = (reply: unknown) =>
52
+ void (calls.get(id) === call && calls.delete(id), reply === undefined || send(reply))
53
+ const answer = protocol.answer(message, { connection, files: read && { read }, notify: send, signal })
54
+ if (!(answer instanceof Promise)) return done(answer)
55
+ if (isId(id)) calls.set(id, call)
56
+ const answered: Promise<void> = answer.then(done)
57
+ inFlight.add(answered)
58
+ void answered.then(() => inFlight.delete(answered))
59
+ }
60
+ return new Promise((settle) => {
61
+ stopped?.addEventListener("abort", () => {
62
+ stop.abort()
63
+ void Promise.all(inFlight).then(() => settle())
64
+ })
65
+ stdio.input.setEncoding("utf8")
66
+ stdio.input.on("data", (chunk: string) => {
67
+ pending += chunk
68
+ for (let end = pending.indexOf("\n"); end >= 0; end = pending.indexOf("\n")) {
69
+ const line = pending.slice(0, end).trim()
70
+ pending = pending.slice(end + 1)
71
+ if (line !== "") take(line)
72
+ }
73
+ })
74
+ stdio.input.on("end", () => {
75
+ if (pending.trim() !== "") take(pending.trim())
76
+ void Promise.all(inFlight).then(() => settle())
77
+ })
78
+ })
79
+ }
@@ -0,0 +1,62 @@
1
+ /**
2
+ * An event stream as a tool (bit 18 phase e, Q6): one bounded collect, never a loop the agent does not see. It gathers
3
+ * events until the stream ends, `max_events` arrive, the whole would pass 100,000 characters, or the call's timeout
4
+ * from its start passes, and says which (`ended`), with the last event id to resume from; each event a progress step.
5
+ * A cut is a success. Only a stream that never opened in time, its own client having had no answer, is a timeout.
6
+ */
7
+ import { json, TEXT_MAX } from "./result.ts"
8
+ import type { ToolResult } from "./protocol.ts"
9
+
10
+ /** One event as the TS SDK yields it. */
11
+ type Event = { readonly data: unknown; readonly event?: string; readonly id?: string }
12
+
13
+ /** A collect's call: its abort and timeout, whether its stream opened, each event's progress step and scrubber. */
14
+ type CollectCall = {
15
+ readonly signal: AbortSignal
16
+ readonly timeout: number
17
+ readonly opened: () => boolean
18
+ readonly progress: (done: number) => void
19
+ readonly scrub: (value: unknown) => unknown
20
+ }
21
+
22
+ /** `iterator`'s events until it ends, `max` arrive, the cap, or `bound` aborts; and why it stopped. */
23
+ async function gather(iterator: AsyncIterator<Event>, max: number, bound: AbortSignal, at: CollectCall) {
24
+ const cut = new Promise<"timeout">((settle) => bound.addEventListener("abort", () => settle("timeout")))
25
+ const events: object[] = []
26
+ let last: string | null = null
27
+ let chars = 0
28
+ for (;;) {
29
+ const next = bound.aborted ? "timeout" : await Promise.race([iterator.next(), cut])
30
+ if (next === "timeout" || next.done)
31
+ return { ended: next === "timeout" ? "timeout" : "end", events, last_event_id: last }
32
+ const { data, event, id } = next.value
33
+ const one = at.scrub({ data, ...(event === undefined ? {} : { event }), ...(id === undefined ? {} : { id }) })
34
+ chars += JSON.stringify(one).length
35
+ if (chars > TEXT_MAX) return { ended: "cap", events, last_event_id: last }
36
+ events.push(one as object)
37
+ last = id ?? last
38
+ at.progress(events.length)
39
+ if (events.length >= max) return { ended: "max_events", events, last_event_id: last }
40
+ }
41
+ }
42
+
43
+ /** The collect `send` opens, reading its `[max_events, last_event_id]` properties of `args`. */
44
+ export async function collected(
45
+ [max, lastEventId]: readonly [string, string],
46
+ args: Record<string, unknown>,
47
+ send: (more: object) => unknown,
48
+ at: CollectCall,
49
+ ): Promise<ToolResult> {
50
+ const bound = AbortSignal.any([at.signal, AbortSignal.timeout(at.timeout)])
51
+ const resume = typeof args[lastEventId] === "string" ? { lastEventId: args[lastEventId] } : {}
52
+ const iterator = ((await send({ ...resume, signal: bound })) as AsyncIterable<Event>)[Symbol.asyncIterator]()
53
+ try {
54
+ const value = await gather(iterator, (args[max] as number | undefined) ?? 20, bound, at)
55
+ if (value.ended === "timeout" && value.events.length === 0 && !at.opened())
56
+ return json({ kind: "timeout", message: "The stream did not open within the call's timeout" }, true)
57
+ return { ...json(value), structuredContent: value }
58
+ } finally {
59
+ /* closes the stream's body; a read still pending settles once the bound has aborted the request */
60
+ void iterator.return?.().catch(() => undefined)
61
+ }
62
+ }
@@ -0,0 +1,2 @@
1
+ # @generated by honey. DO NOT EDIT.
2
+ """The vendored runtime, one module per concern."""