bantou 0.1.0 → 0.2.0

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 (515) hide show
  1. package/.output/nitro.json +13 -0
  2. package/.output/public/_nuxt/BmGsA4i2.js +1 -0
  3. package/.output/public/_nuxt/D_G6gzEa.js +1 -0
  4. package/.output/public/_nuxt/builds/latest.json +1 -0
  5. package/.output/public/_nuxt/builds/meta/1a8fc623-6671-445b-bdd3-c3d073520a3a.json +1 -0
  6. package/.output/public/_nuxt/entry.CZSvzYhH.css +1 -0
  7. package/.output/public/_nuxt/error-404.C3wqHTJz.css +1 -0
  8. package/.output/public/_nuxt/error-500.D6rBzoDj.css +1 -0
  9. package/.output/public/_nuxt/pdFQkwM_.js +4 -0
  10. package/.output/server/chunks/_/error-500.mjs +20 -0
  11. package/.output/server/chunks/_/error-500.mjs.map +1 -0
  12. package/.output/server/chunks/nitro/nitro.mjs +5870 -0
  13. package/.output/server/chunks/nitro/nitro.mjs.map +1 -0
  14. package/.output/server/chunks/routes/mcp.mjs +22 -0
  15. package/.output/server/chunks/routes/mcp.mjs.map +1 -0
  16. package/.output/server/chunks/routes/renderer.mjs +462 -0
  17. package/.output/server/chunks/routes/renderer.mjs.map +1 -0
  18. package/.output/server/chunks/virtual/_virtual_spa-template.mjs +4 -0
  19. package/.output/server/chunks/virtual/_virtual_spa-template.mjs.map +1 -0
  20. package/.output/server/chunks/virtual/precomputed.mjs +4 -0
  21. package/.output/server/chunks/virtual/precomputed.mjs.map +1 -0
  22. package/.output/server/index.mjs +18 -0
  23. package/.output/server/index.mjs.map +1 -0
  24. package/.output/server/node_modules/@babel/parser/lib/index.js +14657 -0
  25. package/.output/server/node_modules/@babel/parser/package.json +50 -0
  26. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/helpers.js +64 -0
  27. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/interfaces.js +16 -0
  28. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/mcp-server.js +32 -0
  29. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/experimental/tasks/server.js +246 -0
  30. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/package.json +1 -0
  31. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/completable.js +41 -0
  32. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/index.js +429 -0
  33. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/mcp.js +971 -0
  34. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/requestBody.js +58 -0
  35. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/sseKeepAlive.js +13 -0
  36. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/webStandardStreamableHttp.js +961 -0
  37. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-compat.js +228 -0
  38. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/server/zod-json-schema-compat.js +51 -0
  39. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js +57 -0
  40. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js +1137 -0
  41. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/toolNameValidation.js +92 -0
  42. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/uriTemplate.js +239 -0
  43. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/types.js +2065 -0
  44. package/.output/server/node_modules/@modelcontextprotocol/sdk/dist/esm/validation/ajv-provider.js +87 -0
  45. package/.output/server/node_modules/@modelcontextprotocol/sdk/package.json +165 -0
  46. package/.output/server/node_modules/@parcel/watcher-wasm/index.mjs +349 -0
  47. package/.output/server/node_modules/@parcel/watcher-wasm/package.json +44 -0
  48. package/.output/server/node_modules/@parcel/watcher-wasm/watcher.wasm +0 -0
  49. package/.output/server/node_modules/@parcel/watcher-wasm/wrapper.js +88 -0
  50. package/.output/server/node_modules/@unagents/messenger-broker/dist/index.mjs +12 -0
  51. package/.output/server/node_modules/@unagents/messenger-broker/dist/shared/messenger-broker.B8W77sqB.mjs +1177 -0
  52. package/.output/server/node_modules/@unagents/messenger-broker/package.json +37 -0
  53. package/.output/server/node_modules/@unagents/messenger-client/dist/index.mjs +9 -0
  54. package/.output/server/node_modules/@unagents/messenger-client/dist/shared/messenger-client.CfQVmH_Z.mjs +975 -0
  55. package/.output/server/node_modules/@unagents/messenger-client/dist/shared/messenger-client.CoDKzubj.mjs +1000 -0
  56. package/.output/server/node_modules/@unagents/messenger-client/package.json +37 -0
  57. package/.output/server/node_modules/@unagents/messenger-protocol/dist/index.mjs +103 -0
  58. package/.output/server/node_modules/@unagents/messenger-protocol/package.json +29 -0
  59. package/.output/server/node_modules/@vue/compiler-core/dist/compiler-core.cjs.prod.js +6802 -0
  60. package/.output/server/node_modules/@vue/compiler-core/package.json +58 -0
  61. package/.output/server/node_modules/@vue/compiler-dom/dist/compiler-dom.cjs.prod.js +729 -0
  62. package/.output/server/node_modules/@vue/compiler-dom/package.json +57 -0
  63. package/.output/server/node_modules/@vue/compiler-ssr/dist/compiler-ssr.cjs.js +1420 -0
  64. package/.output/server/node_modules/@vue/compiler-ssr/package.json +34 -0
  65. package/.output/server/node_modules/@vue/reactivity/dist/reactivity.cjs.prod.js +1933 -0
  66. package/.output/server/node_modules/@vue/reactivity/package.json +55 -0
  67. package/.output/server/node_modules/@vue/runtime-core/dist/runtime-core.cjs.prod.js +7085 -0
  68. package/.output/server/node_modules/@vue/runtime-core/package.json +52 -0
  69. package/.output/server/node_modules/@vue/runtime-dom/dist/runtime-dom.cjs.prod.js +1917 -0
  70. package/.output/server/node_modules/@vue/runtime-dom/package.json +60 -0
  71. package/.output/server/node_modules/@vue/server-renderer/dist/server-renderer.cjs.prod.js +951 -0
  72. package/.output/server/node_modules/@vue/server-renderer/package.json +53 -0
  73. package/.output/server/node_modules/@vue/shared/dist/shared.cjs.prod.js +655 -0
  74. package/.output/server/node_modules/@vue/shared/package.json +47 -0
  75. package/.output/server/node_modules/ajv/dist/ajv.js +50 -0
  76. package/.output/server/node_modules/ajv/dist/compile/codegen/code.js +156 -0
  77. package/.output/server/node_modules/ajv/dist/compile/codegen/index.js +697 -0
  78. package/.output/server/node_modules/ajv/dist/compile/codegen/scope.js +143 -0
  79. package/.output/server/node_modules/ajv/dist/compile/errors.js +123 -0
  80. package/.output/server/node_modules/ajv/dist/compile/index.js +242 -0
  81. package/.output/server/node_modules/ajv/dist/compile/names.js +28 -0
  82. package/.output/server/node_modules/ajv/dist/compile/ref_error.js +12 -0
  83. package/.output/server/node_modules/ajv/dist/compile/resolve.js +155 -0
  84. package/.output/server/node_modules/ajv/dist/compile/rules.js +26 -0
  85. package/.output/server/node_modules/ajv/dist/compile/util.js +178 -0
  86. package/.output/server/node_modules/ajv/dist/compile/validate/applicability.js +19 -0
  87. package/.output/server/node_modules/ajv/dist/compile/validate/boolSchema.js +50 -0
  88. package/.output/server/node_modules/ajv/dist/compile/validate/dataType.js +203 -0
  89. package/.output/server/node_modules/ajv/dist/compile/validate/defaults.js +35 -0
  90. package/.output/server/node_modules/ajv/dist/compile/validate/index.js +520 -0
  91. package/.output/server/node_modules/ajv/dist/compile/validate/keyword.js +124 -0
  92. package/.output/server/node_modules/ajv/dist/compile/validate/subschema.js +81 -0
  93. package/.output/server/node_modules/ajv/dist/core.js +618 -0
  94. package/.output/server/node_modules/ajv/dist/refs/data.json +13 -0
  95. package/.output/server/node_modules/ajv/dist/refs/json-schema-draft-07.json +151 -0
  96. package/.output/server/node_modules/ajv/dist/runtime/equal.js +7 -0
  97. package/.output/server/node_modules/ajv/dist/runtime/ucs2length.js +24 -0
  98. package/.output/server/node_modules/ajv/dist/runtime/uri.js +6 -0
  99. package/.output/server/node_modules/ajv/dist/runtime/validation_error.js +11 -0
  100. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/additionalItems.js +49 -0
  101. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/additionalProperties.js +106 -0
  102. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/allOf.js +23 -0
  103. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/anyOf.js +12 -0
  104. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/contains.js +95 -0
  105. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/dependencies.js +85 -0
  106. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/if.js +66 -0
  107. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/index.js +44 -0
  108. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/items.js +52 -0
  109. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/items2020.js +30 -0
  110. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/not.js +26 -0
  111. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/oneOf.js +60 -0
  112. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/patternProperties.js +75 -0
  113. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/prefixItems.js +12 -0
  114. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/properties.js +54 -0
  115. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/propertyNames.js +38 -0
  116. package/.output/server/node_modules/ajv/dist/vocabularies/applicator/thenElse.js +13 -0
  117. package/.output/server/node_modules/ajv/dist/vocabularies/code.js +131 -0
  118. package/.output/server/node_modules/ajv/dist/vocabularies/core/id.js +10 -0
  119. package/.output/server/node_modules/ajv/dist/vocabularies/core/index.js +16 -0
  120. package/.output/server/node_modules/ajv/dist/vocabularies/core/ref.js +122 -0
  121. package/.output/server/node_modules/ajv/dist/vocabularies/discriminator/index.js +104 -0
  122. package/.output/server/node_modules/ajv/dist/vocabularies/discriminator/types.js +9 -0
  123. package/.output/server/node_modules/ajv/dist/vocabularies/draft7.js +17 -0
  124. package/.output/server/node_modules/ajv/dist/vocabularies/format/format.js +92 -0
  125. package/.output/server/node_modules/ajv/dist/vocabularies/format/index.js +6 -0
  126. package/.output/server/node_modules/ajv/dist/vocabularies/metadata.js +18 -0
  127. package/.output/server/node_modules/ajv/dist/vocabularies/validation/const.js +25 -0
  128. package/.output/server/node_modules/ajv/dist/vocabularies/validation/enum.js +48 -0
  129. package/.output/server/node_modules/ajv/dist/vocabularies/validation/index.js +33 -0
  130. package/.output/server/node_modules/ajv/dist/vocabularies/validation/limitItems.js +24 -0
  131. package/.output/server/node_modules/ajv/dist/vocabularies/validation/limitLength.js +27 -0
  132. package/.output/server/node_modules/ajv/dist/vocabularies/validation/limitNumber.js +27 -0
  133. package/.output/server/node_modules/ajv/dist/vocabularies/validation/limitProperties.js +24 -0
  134. package/.output/server/node_modules/ajv/dist/vocabularies/validation/multipleOf.js +26 -0
  135. package/.output/server/node_modules/ajv/dist/vocabularies/validation/pattern.js +33 -0
  136. package/.output/server/node_modules/ajv/dist/vocabularies/validation/required.js +79 -0
  137. package/.output/server/node_modules/ajv/dist/vocabularies/validation/uniqueItems.js +64 -0
  138. package/.output/server/node_modules/ajv/package.json +126 -0
  139. package/.output/server/node_modules/ajv-formats/dist/formats.js +208 -0
  140. package/.output/server/node_modules/ajv-formats/dist/index.js +37 -0
  141. package/.output/server/node_modules/ajv-formats/dist/limit.js +69 -0
  142. package/.output/server/node_modules/ajv-formats/package.json +74 -0
  143. package/.output/server/node_modules/consola/dist/chunks/prompt.mjs +280 -0
  144. package/.output/server/node_modules/consola/dist/core.mjs +512 -0
  145. package/.output/server/node_modules/consola/dist/index.mjs +651 -0
  146. package/.output/server/node_modules/consola/dist/shared/consola.DRwqZj3T.mjs +72 -0
  147. package/.output/server/node_modules/consola/dist/shared/consola.DXBYu-KD.mjs +288 -0
  148. package/.output/server/node_modules/consola/dist/utils.mjs +54 -0
  149. package/.output/server/node_modules/consola/package.json +136 -0
  150. package/.output/server/node_modules/content-type/index.js +225 -0
  151. package/.output/server/node_modules/content-type/package.json +42 -0
  152. package/.output/server/node_modules/cookie-es/dist/index.mjs +268 -0
  153. package/.output/server/node_modules/cookie-es/package.json +46 -0
  154. package/.output/server/node_modules/crossws/dist/_chunks/_request.mjs +83 -0
  155. package/.output/server/node_modules/crossws/dist/_chunks/adapter.mjs +234 -0
  156. package/.output/server/node_modules/crossws/dist/_chunks/error.mjs +7 -0
  157. package/.output/server/node_modules/crossws/dist/_chunks/libs/ws.mjs +6 -0
  158. package/.output/server/node_modules/crossws/dist/_chunks/node.mjs +220 -0
  159. package/.output/server/node_modules/crossws/dist/_chunks/peer.mjs +208 -0
  160. package/.output/server/node_modules/crossws/dist/adapters/node.mjs +1 -0
  161. package/.output/server/node_modules/crossws/package.json +115 -0
  162. package/.output/server/node_modules/defu/dist/defu.mjs +69 -0
  163. package/.output/server/node_modules/defu/package.json +48 -0
  164. package/.output/server/node_modules/destr/dist/index.mjs +72 -0
  165. package/.output/server/node_modules/destr/package.json +47 -0
  166. package/.output/server/node_modules/devalue/index.js +17 -0
  167. package/.output/server/node_modules/devalue/package.json +39 -0
  168. package/.output/server/node_modules/devalue/src/base64.js +60 -0
  169. package/.output/server/node_modules/devalue/src/constants.js +12 -0
  170. package/.output/server/node_modules/devalue/src/operations.js +221 -0
  171. package/.output/server/node_modules/devalue/src/parse.js +279 -0
  172. package/.output/server/node_modules/devalue/src/stringify.js +433 -0
  173. package/.output/server/node_modules/devalue/src/uneval.js +698 -0
  174. package/.output/server/node_modules/devalue/src/utils.js +190 -0
  175. package/.output/server/node_modules/entities/dist/commonjs/decode-codepoint.js +77 -0
  176. package/.output/server/node_modules/entities/dist/commonjs/decode.js +568 -0
  177. package/.output/server/node_modules/entities/dist/commonjs/generated/decode-data-html.js +7 -0
  178. package/.output/server/node_modules/entities/dist/commonjs/generated/decode-data-xml.js +7 -0
  179. package/.output/server/node_modules/entities/dist/commonjs/internal/bin-trie-flags.js +21 -0
  180. package/.output/server/node_modules/entities/dist/commonjs/internal/decode-shared.js +31 -0
  181. package/.output/server/node_modules/entities/dist/commonjs/package.json +3 -0
  182. package/.output/server/node_modules/entities/package.json +120 -0
  183. package/.output/server/node_modules/estree-walker/dist/umd/estree-walker.js +344 -0
  184. package/.output/server/node_modules/estree-walker/package.json +37 -0
  185. package/.output/server/node_modules/fast-deep-equal/index.js +46 -0
  186. package/.output/server/node_modules/fast-deep-equal/package.json +61 -0
  187. package/.output/server/node_modules/fast-uri/index.js +711 -0
  188. package/.output/server/node_modules/fast-uri/lib/schemes.js +272 -0
  189. package/.output/server/node_modules/fast-uri/lib/utils.js +799 -0
  190. package/.output/server/node_modules/fast-uri/package.json +68 -0
  191. package/.output/server/node_modules/get-port-please/dist/index.mjs +430 -0
  192. package/.output/server/node_modules/get-port-please/package.json +39 -0
  193. package/.output/server/node_modules/h3/dist/index.mjs +2498 -0
  194. package/.output/server/node_modules/h3/package.json +75 -0
  195. package/.output/server/node_modules/hookable/dist/index.mjs +257 -0
  196. package/.output/server/node_modules/hookable/package.json +54 -0
  197. package/.output/server/node_modules/http-shutdown/index.js +85 -0
  198. package/.output/server/node_modules/http-shutdown/package.json +32 -0
  199. package/.output/server/node_modules/iron-webcrypto/dist/index.js +298 -0
  200. package/.output/server/node_modules/iron-webcrypto/package.json +72 -0
  201. package/.output/server/node_modules/is-extglob/index.js +20 -0
  202. package/.output/server/node_modules/is-extglob/package.json +69 -0
  203. package/.output/server/node_modules/is-glob/index.js +150 -0
  204. package/.output/server/node_modules/is-glob/package.json +81 -0
  205. package/.output/server/node_modules/jiti/dist/jiti.cjs +1 -0
  206. package/.output/server/node_modules/jiti/lib/jiti.mjs +29 -0
  207. package/.output/server/node_modules/jiti/package.json +146 -0
  208. package/.output/server/node_modules/json-schema-traverse/index.js +93 -0
  209. package/.output/server/node_modules/json-schema-traverse/package.json +43 -0
  210. package/.output/server/node_modules/listhen/dist/chunks/xdg-open.mjs +1069 -0
  211. package/.output/server/node_modules/listhen/dist/index.mjs +19 -0
  212. package/.output/server/node_modules/listhen/dist/shared/listhen.tqe5I1Rl.mjs +1040 -0
  213. package/.output/server/node_modules/listhen/package.json +84 -0
  214. package/.output/server/node_modules/napi-wasm/index.mjs +1371 -0
  215. package/.output/server/node_modules/napi-wasm/package.json +33 -0
  216. package/.output/server/node_modules/node-forge/lib/aes.js +1091 -0
  217. package/.output/server/node_modules/node-forge/lib/aesCipherSuites.js +282 -0
  218. package/.output/server/node_modules/node-forge/lib/asn1-validator.js +91 -0
  219. package/.output/server/node_modules/node-forge/lib/asn1.js +1522 -0
  220. package/.output/server/node_modules/node-forge/lib/baseN.js +186 -0
  221. package/.output/server/node_modules/node-forge/lib/cipher.js +230 -0
  222. package/.output/server/node_modules/node-forge/lib/cipherModes.js +1027 -0
  223. package/.output/server/node_modules/node-forge/lib/des.js +496 -0
  224. package/.output/server/node_modules/node-forge/lib/ed25519.js +1091 -0
  225. package/.output/server/node_modules/node-forge/lib/forge.js +13 -0
  226. package/.output/server/node_modules/node-forge/lib/hmac.js +146 -0
  227. package/.output/server/node_modules/node-forge/lib/index.js +33 -0
  228. package/.output/server/node_modules/node-forge/lib/jsbn.js +1294 -0
  229. package/.output/server/node_modules/node-forge/lib/kem.js +168 -0
  230. package/.output/server/node_modules/node-forge/lib/log.js +319 -0
  231. package/.output/server/node_modules/node-forge/lib/md.all.js +13 -0
  232. package/.output/server/node_modules/node-forge/lib/md.js +11 -0
  233. package/.output/server/node_modules/node-forge/lib/md5.js +289 -0
  234. package/.output/server/node_modules/node-forge/lib/mgf.js +12 -0
  235. package/.output/server/node_modules/node-forge/lib/mgf1.js +57 -0
  236. package/.output/server/node_modules/node-forge/lib/oids.js +180 -0
  237. package/.output/server/node_modules/node-forge/lib/pbe.js +1029 -0
  238. package/.output/server/node_modules/node-forge/lib/pbkdf2.js +211 -0
  239. package/.output/server/node_modules/node-forge/lib/pem.js +413 -0
  240. package/.output/server/node_modules/node-forge/lib/pkcs1.js +276 -0
  241. package/.output/server/node_modules/node-forge/lib/pkcs12.js +1081 -0
  242. package/.output/server/node_modules/node-forge/lib/pkcs7.js +1260 -0
  243. package/.output/server/node_modules/node-forge/lib/pkcs7asn1.js +410 -0
  244. package/.output/server/node_modules/node-forge/lib/pki.js +102 -0
  245. package/.output/server/node_modules/node-forge/lib/prime.js +297 -0
  246. package/.output/server/node_modules/node-forge/lib/prng.js +419 -0
  247. package/.output/server/node_modules/node-forge/lib/pss.js +241 -0
  248. package/.output/server/node_modules/node-forge/lib/random.js +191 -0
  249. package/.output/server/node_modules/node-forge/lib/rc2.js +410 -0
  250. package/.output/server/node_modules/node-forge/lib/rsa.js +2014 -0
  251. package/.output/server/node_modules/node-forge/lib/sha1.js +319 -0
  252. package/.output/server/node_modules/node-forge/lib/sha256.js +327 -0
  253. package/.output/server/node_modules/node-forge/lib/sha512.js +561 -0
  254. package/.output/server/node_modules/node-forge/lib/ssh.js +236 -0
  255. package/.output/server/node_modules/node-forge/lib/tls.js +4334 -0
  256. package/.output/server/node_modules/node-forge/lib/util.js +2652 -0
  257. package/.output/server/node_modules/node-forge/lib/x509.js +3257 -0
  258. package/.output/server/node_modules/node-forge/package.json +123 -0
  259. package/.output/server/node_modules/node-mock-http/dist/_polyfill/buffer/node.mjs +1 -0
  260. package/.output/server/node_modules/node-mock-http/dist/_polyfill/events/node.mjs +1 -0
  261. package/.output/server/node_modules/node-mock-http/dist/index.mjs +1 -0
  262. package/.output/server/node_modules/node-mock-http/package.json +63 -0
  263. package/.output/server/node_modules/nostics/dist/formatters/ansi.mjs +19 -0
  264. package/.output/server/node_modules/nostics/dist/index.mjs +194 -0
  265. package/.output/server/node_modules/nostics/package.json +126 -0
  266. package/.output/server/node_modules/pathe/dist/index.mjs +19 -0
  267. package/.output/server/node_modules/pathe/dist/shared/pathe.M-eThtNZ.mjs +249 -0
  268. package/.output/server/node_modules/pathe/package.json +61 -0
  269. package/.output/server/node_modules/picomatch/index.js +17 -0
  270. package/.output/server/node_modules/picomatch/lib/constants.js +184 -0
  271. package/.output/server/node_modules/picomatch/lib/parse.js +1425 -0
  272. package/.output/server/node_modules/picomatch/lib/picomatch.js +361 -0
  273. package/.output/server/node_modules/picomatch/lib/scan.js +403 -0
  274. package/.output/server/node_modules/picomatch/lib/utils.js +72 -0
  275. package/.output/server/node_modules/picomatch/package.json +83 -0
  276. package/.output/server/node_modules/radix3/dist/index.mjs +262 -0
  277. package/.output/server/node_modules/radix3/package.json +52 -0
  278. package/.output/server/node_modules/source-map-js/lib/array-set.js +121 -0
  279. package/.output/server/node_modules/source-map-js/lib/base64-vlq.js +140 -0
  280. package/.output/server/node_modules/source-map-js/lib/base64.js +67 -0
  281. package/.output/server/node_modules/source-map-js/lib/binary-search.js +111 -0
  282. package/.output/server/node_modules/source-map-js/lib/mapping-list.js +79 -0
  283. package/.output/server/node_modules/source-map-js/lib/quick-sort.js +141 -0
  284. package/.output/server/node_modules/source-map-js/lib/source-map-consumer.js +1236 -0
  285. package/.output/server/node_modules/source-map-js/lib/source-map-generator.js +446 -0
  286. package/.output/server/node_modules/source-map-js/lib/source-node.js +420 -0
  287. package/.output/server/node_modules/source-map-js/lib/util.js +594 -0
  288. package/.output/server/node_modules/source-map-js/package.json +71 -0
  289. package/.output/server/node_modules/source-map-js/source-map.js +8 -0
  290. package/.output/server/node_modules/std-env/dist/index.mjs +1 -0
  291. package/.output/server/node_modules/std-env/package.json +43 -0
  292. package/.output/server/node_modules/tinyclip/dist/index.js +143 -0
  293. package/.output/server/node_modules/tinyclip/package.json +48 -0
  294. package/.output/server/node_modules/ufo/dist/index.mjs +645 -0
  295. package/.output/server/node_modules/ufo/package.json +48 -0
  296. package/.output/server/node_modules/uncrypto/dist/crypto.node.mjs +16 -0
  297. package/.output/server/node_modules/uncrypto/package.json +60 -0
  298. package/.output/server/node_modules/unhead/dist/client.mjs +22 -0
  299. package/.output/server/node_modules/unhead/dist/legacy.mjs +33 -0
  300. package/.output/server/node_modules/unhead/dist/minify.mjs +183 -0
  301. package/.output/server/node_modules/unhead/dist/parser.mjs +518 -0
  302. package/.output/server/node_modules/unhead/dist/plugins.mjs +782 -0
  303. package/.output/server/node_modules/unhead/dist/server.mjs +99 -0
  304. package/.output/server/node_modules/unhead/dist/shared/unhead.BEmVMkeA.mjs +673 -0
  305. package/.output/server/node_modules/unhead/dist/shared/unhead.Bf_fPVYA.mjs +6 -0
  306. package/.output/server/node_modules/unhead/dist/shared/unhead.Bm4Y6XQI.mjs +17 -0
  307. package/.output/server/node_modules/unhead/dist/shared/unhead.C5Bksi2B.mjs +49 -0
  308. package/.output/server/node_modules/unhead/dist/shared/unhead.CGPOfp5O.mjs +32 -0
  309. package/.output/server/node_modules/unhead/dist/shared/unhead.CHEy9ana.mjs +7 -0
  310. package/.output/server/node_modules/unhead/dist/shared/unhead.C_7zwq8E.mjs +11 -0
  311. package/.output/server/node_modules/unhead/dist/shared/unhead.CaeaMM5q.mjs +19 -0
  312. package/.output/server/node_modules/unhead/dist/shared/unhead.D7HkBzZn.mjs +59 -0
  313. package/.output/server/node_modules/unhead/dist/shared/unhead.D9VfQWNo.mjs +240 -0
  314. package/.output/server/node_modules/unhead/dist/shared/unhead.DD4N5B4k.mjs +224 -0
  315. package/.output/server/node_modules/unhead/dist/shared/unhead.DGl9jcjg.mjs +196 -0
  316. package/.output/server/node_modules/unhead/dist/shared/unhead.DJuZwX9c.mjs +400 -0
  317. package/.output/server/node_modules/unhead/dist/shared/unhead.DkxnqlHC.mjs +264 -0
  318. package/.output/server/node_modules/unhead/dist/shared/unhead.DspMpm6y.mjs +48 -0
  319. package/.output/server/node_modules/unhead/dist/shared/unhead.o8j9utSy.mjs +208 -0
  320. package/.output/server/node_modules/unhead/dist/stream/client.mjs +33 -0
  321. package/.output/server/node_modules/unhead/dist/stream/iife.mjs +2 -0
  322. package/.output/server/node_modules/unhead/dist/stream/server.mjs +446 -0
  323. package/.output/server/node_modules/unhead/dist/utils.mjs +7 -0
  324. package/.output/server/node_modules/unhead/package.json +179 -0
  325. package/.output/server/node_modules/untun/dist/_chunks/cloudflared.mjs +179 -0
  326. package/.output/server/node_modules/untun/dist/_chunks/log.mjs +27 -0
  327. package/.output/server/node_modules/untun/dist/index.mjs +47 -0
  328. package/.output/server/node_modules/untun/package.json +44 -0
  329. package/.output/server/node_modules/uqr/dist/index.mjs +739 -0
  330. package/.output/server/node_modules/uqr/package.json +69 -0
  331. package/.output/server/node_modules/vue/dist/vue.cjs.js +80 -0
  332. package/.output/server/node_modules/vue/dist/vue.cjs.prod.js +66 -0
  333. package/.output/server/node_modules/vue/index.js +7 -0
  334. package/.output/server/node_modules/vue/index.mjs +1 -0
  335. package/.output/server/node_modules/vue/package.json +112 -0
  336. package/.output/server/node_modules/vue/server-renderer/index.mjs +1 -0
  337. package/.output/server/node_modules/vue-bundle-renderer/dist/runtime.mjs +687 -0
  338. package/.output/server/node_modules/vue-bundle-renderer/package.json +66 -0
  339. package/.output/server/node_modules/zod/index.js +7 -0
  340. package/.output/server/node_modules/zod/package.json +147 -0
  341. package/.output/server/node_modules/zod/v3/ZodError.js +143 -0
  342. package/.output/server/node_modules/zod/v3/errors.js +9 -0
  343. package/.output/server/node_modules/zod/v3/external.js +6 -0
  344. package/.output/server/node_modules/zod/v3/helpers/errorUtil.js +6 -0
  345. package/.output/server/node_modules/zod/v3/helpers/parseUtil.js +109 -0
  346. package/.output/server/node_modules/zod/v3/helpers/typeAliases.js +1 -0
  347. package/.output/server/node_modules/zod/v3/helpers/util.js +133 -0
  348. package/.output/server/node_modules/zod/v3/index.js +4 -0
  349. package/.output/server/node_modules/zod/v3/locales/en.js +109 -0
  350. package/.output/server/node_modules/zod/v3/package.json +7 -0
  351. package/.output/server/node_modules/zod/v3/types.js +3697 -0
  352. package/.output/server/node_modules/zod/v4/classic/checks.js +1 -0
  353. package/.output/server/node_modules/zod/v4/classic/coerce.js +17 -0
  354. package/.output/server/node_modules/zod/v4/classic/compat.js +31 -0
  355. package/.output/server/node_modules/zod/v4/classic/deep-partial.js +13 -0
  356. package/.output/server/node_modules/zod/v4/classic/errors.js +57 -0
  357. package/.output/server/node_modules/zod/v4/classic/external.js +17 -0
  358. package/.output/server/node_modules/zod/v4/classic/from-json-schema.js +881 -0
  359. package/.output/server/node_modules/zod/v4/classic/in-out.js +36 -0
  360. package/.output/server/node_modules/zod/v4/classic/index.js +4 -0
  361. package/.output/server/node_modules/zod/v4/classic/iso.js +15 -0
  362. package/.output/server/node_modules/zod/v4/classic/package.json +7 -0
  363. package/.output/server/node_modules/zod/v4/classic/parse.js +16 -0
  364. package/.output/server/node_modules/zod/v4/classic/schemas.js +1535 -0
  365. package/.output/server/node_modules/zod/v4/core/api.js +1107 -0
  366. package/.output/server/node_modules/zod/v4/core/checks.js +516 -0
  367. package/.output/server/node_modules/zod/v4/core/compile.js +1866 -0
  368. package/.output/server/node_modules/zod/v4/core/core.js +141 -0
  369. package/.output/server/node_modules/zod/v4/core/doc.js +38 -0
  370. package/.output/server/node_modules/zod/v4/core/errors.js +267 -0
  371. package/.output/server/node_modules/zod/v4/core/index.js +19 -0
  372. package/.output/server/node_modules/zod/v4/core/json-schema-generator.js +99 -0
  373. package/.output/server/node_modules/zod/v4/core/json-schema-processors.js +843 -0
  374. package/.output/server/node_modules/zod/v4/core/json-schema.js +1 -0
  375. package/.output/server/node_modules/zod/v4/core/memoizer.js +311 -0
  376. package/.output/server/node_modules/zod/v4/core/package.json +7 -0
  377. package/.output/server/node_modules/zod/v4/core/parse.js +175 -0
  378. package/.output/server/node_modules/zod/v4/core/regexes.js +156 -0
  379. package/.output/server/node_modules/zod/v4/core/registries.js +51 -0
  380. package/.output/server/node_modules/zod/v4/core/schemas.js +2636 -0
  381. package/.output/server/node_modules/zod/v4/core/to-json-schema.js +651 -0
  382. package/.output/server/node_modules/zod/v4/core/util.js +873 -0
  383. package/.output/server/node_modules/zod/v4/core/versions.js +5 -0
  384. package/.output/server/node_modules/zod/v4/core/visit.js +169 -0
  385. package/.output/server/node_modules/zod/v4/index.js +4 -0
  386. package/.output/server/node_modules/zod/v4/locales/ar.js +111 -0
  387. package/.output/server/node_modules/zod/v4/locales/az.js +110 -0
  388. package/.output/server/node_modules/zod/v4/locales/be.js +168 -0
  389. package/.output/server/node_modules/zod/v4/locales/bg.js +125 -0
  390. package/.output/server/node_modules/zod/v4/locales/bn.js +113 -0
  391. package/.output/server/node_modules/zod/v4/locales/ca.js +112 -0
  392. package/.output/server/node_modules/zod/v4/locales/ckb.js +133 -0
  393. package/.output/server/node_modules/zod/v4/locales/cs.js +116 -0
  394. package/.output/server/node_modules/zod/v4/locales/da.js +120 -0
  395. package/.output/server/node_modules/zod/v4/locales/de.js +113 -0
  396. package/.output/server/node_modules/zod/v4/locales/el.js +112 -0
  397. package/.output/server/node_modules/zod/v4/locales/en.js +125 -0
  398. package/.output/server/node_modules/zod/v4/locales/eo.js +114 -0
  399. package/.output/server/node_modules/zod/v4/locales/es.js +136 -0
  400. package/.output/server/node_modules/zod/v4/locales/fa.js +119 -0
  401. package/.output/server/node_modules/zod/v4/locales/fi.js +117 -0
  402. package/.output/server/node_modules/zod/v4/locales/fr-CA.js +112 -0
  403. package/.output/server/node_modules/zod/v4/locales/fr.js +129 -0
  404. package/.output/server/node_modules/zod/v4/locales/gu.js +113 -0
  405. package/.output/server/node_modules/zod/v4/locales/he.js +221 -0
  406. package/.output/server/node_modules/zod/v4/locales/hi.js +111 -0
  407. package/.output/server/node_modules/zod/v4/locales/hr.js +126 -0
  408. package/.output/server/node_modules/zod/v4/locales/hu.js +113 -0
  409. package/.output/server/node_modules/zod/v4/locales/hy.js +158 -0
  410. package/.output/server/node_modules/zod/v4/locales/id.js +111 -0
  411. package/.output/server/node_modules/zod/v4/locales/index.js +63 -0
  412. package/.output/server/node_modules/zod/v4/locales/is.js +114 -0
  413. package/.output/server/node_modules/zod/v4/locales/it.js +113 -0
  414. package/.output/server/node_modules/zod/v4/locales/ja.js +112 -0
  415. package/.output/server/node_modules/zod/v4/locales/ka.js +117 -0
  416. package/.output/server/node_modules/zod/v4/locales/kh.js +5 -0
  417. package/.output/server/node_modules/zod/v4/locales/km.js +115 -0
  418. package/.output/server/node_modules/zod/v4/locales/kn.js +116 -0
  419. package/.output/server/node_modules/zod/v4/locales/ko.js +116 -0
  420. package/.output/server/node_modules/zod/v4/locales/lt.js +207 -0
  421. package/.output/server/node_modules/zod/v4/locales/mk.js +114 -0
  422. package/.output/server/node_modules/zod/v4/locales/ms.js +112 -0
  423. package/.output/server/node_modules/zod/v4/locales/ne.js +111 -0
  424. package/.output/server/node_modules/zod/v4/locales/nl.js +115 -0
  425. package/.output/server/node_modules/zod/v4/locales/nn.js +113 -0
  426. package/.output/server/node_modules/zod/v4/locales/no.js +113 -0
  427. package/.output/server/node_modules/zod/v4/locales/ota.js +114 -0
  428. package/.output/server/node_modules/zod/v4/locales/package.json +7 -0
  429. package/.output/server/node_modules/zod/v4/locales/pl.js +114 -0
  430. package/.output/server/node_modules/zod/v4/locales/ps.js +119 -0
  431. package/.output/server/node_modules/zod/v4/locales/pt-BR.js +143 -0
  432. package/.output/server/node_modules/zod/v4/locales/pt.js +142 -0
  433. package/.output/server/node_modules/zod/v4/locales/ro.js +122 -0
  434. package/.output/server/node_modules/zod/v4/locales/ru.js +168 -0
  435. package/.output/server/node_modules/zod/v4/locales/sk.js +116 -0
  436. package/.output/server/node_modules/zod/v4/locales/sl.js +114 -0
  437. package/.output/server/node_modules/zod/v4/locales/sv.js +115 -0
  438. package/.output/server/node_modules/zod/v4/locales/ta.js +115 -0
  439. package/.output/server/node_modules/zod/v4/locales/tg.js +117 -0
  440. package/.output/server/node_modules/zod/v4/locales/th.js +115 -0
  441. package/.output/server/node_modules/zod/v4/locales/tk.js +107 -0
  442. package/.output/server/node_modules/zod/v4/locales/tr.js +110 -0
  443. package/.output/server/node_modules/zod/v4/locales/ua.js +5 -0
  444. package/.output/server/node_modules/zod/v4/locales/uk.js +113 -0
  445. package/.output/server/node_modules/zod/v4/locales/ur.js +115 -0
  446. package/.output/server/node_modules/zod/v4/locales/uz.js +113 -0
  447. package/.output/server/node_modules/zod/v4/locales/vi.js +113 -0
  448. package/.output/server/node_modules/zod/v4/locales/yo.js +112 -0
  449. package/.output/server/node_modules/zod/v4/locales/zh-CN.js +114 -0
  450. package/.output/server/node_modules/zod/v4/locales/zh-TW.js +112 -0
  451. package/.output/server/node_modules/zod/v4/mini/checks.js +1 -0
  452. package/.output/server/node_modules/zod/v4/mini/coerce.js +22 -0
  453. package/.output/server/node_modules/zod/v4/mini/deep-partial.js +13 -0
  454. package/.output/server/node_modules/zod/v4/mini/external.js +16 -0
  455. package/.output/server/node_modules/zod/v4/mini/in-out.js +36 -0
  456. package/.output/server/node_modules/zod/v4/mini/iso.js +34 -0
  457. package/.output/server/node_modules/zod/v4/mini/package.json +7 -0
  458. package/.output/server/node_modules/zod/v4/mini/parse.js +1 -0
  459. package/.output/server/node_modules/zod/v4/mini/schemas.js +1002 -0
  460. package/.output/server/node_modules/zod/v4/package.json +7 -0
  461. package/.output/server/node_modules/zod/v4-mini/index.js +3 -0
  462. package/.output/server/node_modules/zod/v4-mini/package.json +7 -0
  463. package/.output/server/node_modules/zod-to-json-schema/dist/esm/Options.js +46 -0
  464. package/.output/server/node_modules/zod-to-json-schema/dist/esm/Refs.js +22 -0
  465. package/.output/server/node_modules/zod-to-json-schema/dist/esm/errorMessages.js +14 -0
  466. package/.output/server/node_modules/zod-to-json-schema/dist/esm/getRelativePath.js +8 -0
  467. package/.output/server/node_modules/zod-to-json-schema/dist/esm/index.js +40 -0
  468. package/.output/server/node_modules/zod-to-json-schema/dist/esm/package.json +1 -0
  469. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parseDef.js +62 -0
  470. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parseTypes.js +1 -0
  471. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/any.js +17 -0
  472. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/array.js +26 -0
  473. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/bigint.js +49 -0
  474. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/boolean.js +5 -0
  475. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/branded.js +4 -0
  476. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/catch.js +4 -0
  477. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/date.js +46 -0
  478. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/default.js +7 -0
  479. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/effects.js +7 -0
  480. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/enum.js +6 -0
  481. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/intersection.js +52 -0
  482. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/literal.js +21 -0
  483. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/map.js +26 -0
  484. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/nativeEnum.js +16 -0
  485. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/never.js +11 -0
  486. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/null.js +10 -0
  487. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/nullable.js +33 -0
  488. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/number.js +52 -0
  489. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/object.js +72 -0
  490. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/optional.js +21 -0
  491. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/pipeline.js +20 -0
  492. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/promise.js +4 -0
  493. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/readonly.js +4 -0
  494. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/record.js +61 -0
  495. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/set.js +20 -0
  496. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/string.js +352 -0
  497. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/tuple.js +32 -0
  498. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/undefined.js +6 -0
  499. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/union.js +80 -0
  500. package/.output/server/node_modules/zod-to-json-schema/dist/esm/parsers/unknown.js +4 -0
  501. package/.output/server/node_modules/zod-to-json-schema/dist/esm/selectParser.js +105 -0
  502. package/.output/server/node_modules/zod-to-json-schema/dist/esm/zodToJsonSchema.js +87 -0
  503. package/.output/server/node_modules/zod-to-json-schema/package.json +85 -0
  504. package/.output/server/package.json +64 -0
  505. package/README.md +227 -24
  506. package/bin/bantou.mjs +33 -0
  507. package/package.json +18 -8
  508. package/protocol/PROTOCOL.md +26 -0
  509. package/protocol/protocol.json +92 -0
  510. package/dist/cap.js +0 -7
  511. package/dist/cli.js +0 -27
  512. package/dist/config.js +0 -23
  513. package/dist/daemon.js +0 -23
  514. package/dist/session.js +0 -7
  515. package/dist/workspace.js +0 -8
@@ -0,0 +1,961 @@
1
+ /**
2
+ * Web Standards Streamable HTTP Server Transport
3
+ *
4
+ * This is the core transport implementation using Web Standard APIs (Request, Response, ReadableStream).
5
+ * It can run on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.
6
+ *
7
+ * For Node.js Express/HTTP compatibility, use `StreamableHTTPServerTransport` which wraps this transport.
8
+ */
9
+ import { isJsonContentType } from '../shared/mediaType.js';
10
+ import { MAX_BATCH_SIZE, readRequestBody, requestBodyTooLargeMessage, resolveMaxRequestBodySize } from './requestBody.js';
11
+ import { armSseKeepAlive, DEFAULT_SSE_KEEP_ALIVE_MS } from './sseKeepAlive.js';
12
+ import { isInitializeRequest, isJSONRPCErrorResponse, isJSONRPCRequest, isJSONRPCResultResponse, JSONRPCMessageSchema, SUPPORTED_PROTOCOL_VERSIONS, DEFAULT_NEGOTIATED_PROTOCOL_VERSION } from '../types.js';
13
+ /**
14
+ * Server transport for Web Standards Streamable HTTP: this implements the MCP Streamable HTTP transport specification
15
+ * using Web Standard APIs (Request, Response, ReadableStream).
16
+ *
17
+ * This transport works on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.
18
+ *
19
+ * Usage example:
20
+ *
21
+ * ```typescript
22
+ * // Stateful mode - server sets the session ID
23
+ * const statefulTransport = new WebStandardStreamableHTTPServerTransport({
24
+ * sessionIdGenerator: () => crypto.randomUUID(),
25
+ * });
26
+ *
27
+ * // Stateless mode - explicitly set session ID to undefined
28
+ * const statelessTransport = new WebStandardStreamableHTTPServerTransport({
29
+ * sessionIdGenerator: undefined,
30
+ * });
31
+ *
32
+ * // Hono.js usage
33
+ * app.all('/mcp', async (c) => {
34
+ * return transport.handleRequest(c.req.raw);
35
+ * });
36
+ *
37
+ * // Cloudflare Workers usage
38
+ * export default {
39
+ * async fetch(request: Request): Promise<Response> {
40
+ * return transport.handleRequest(request);
41
+ * }
42
+ * };
43
+ * ```
44
+ *
45
+ * In stateful mode:
46
+ * - Session ID is generated and included in response headers
47
+ * - Session ID is always included in initialization responses
48
+ * - Requests with invalid session IDs are rejected with 404 Not Found
49
+ * - Non-initialization requests without a session ID are rejected with 400 Bad Request
50
+ * - State is maintained in-memory (connections, message history)
51
+ *
52
+ * In stateless mode:
53
+ * - No Session ID is included in any responses
54
+ * - No session validation is performed
55
+ */
56
+ export class WebStandardStreamableHTTPServerTransport {
57
+ constructor(options = {}) {
58
+ this._started = false;
59
+ this._hasHandledRequest = false;
60
+ this._streamMapping = new Map();
61
+ this._requestToStreamMapping = new Map();
62
+ /**
63
+ * Request streams whose client holds a Last-Event-ID cursor (at least one
64
+ * id-bearing event was delivered on them), so a stored response can be
65
+ * replayed on resume.
66
+ */
67
+ this._resumableStreams = new Set();
68
+ this._requestResponseMap = new Map();
69
+ this._initialized = false;
70
+ this._enableJsonResponse = false;
71
+ this._standaloneSseStreamId = '_GET_stream';
72
+ this._closed = false;
73
+ this.sessionIdGenerator = options.sessionIdGenerator;
74
+ this._enableJsonResponse = options.enableJsonResponse ?? false;
75
+ this._eventStore = options.eventStore;
76
+ this._onsessioninitialized = options.onsessioninitialized;
77
+ this._onsessionclosed = options.onsessionclosed;
78
+ this._allowedHosts = options.allowedHosts;
79
+ this._allowedOrigins = options.allowedOrigins;
80
+ this._enableDnsRebindingProtection = options.enableDnsRebindingProtection ?? false;
81
+ this._retryInterval = options.retryInterval;
82
+ this._keepAliveMs = options.keepAliveMs ?? DEFAULT_SSE_KEEP_ALIVE_MS;
83
+ this._maxRequestBodySize = resolveMaxRequestBodySize(options.maxRequestBodySize);
84
+ }
85
+ /**
86
+ * Arms a keep-alive interval for an SSE stream that periodically writes an SSE
87
+ * comment frame so intermediaries and idle timeouts don't kill the connection.
88
+ * The returned timer is owned by the stream it was armed for: the stream's
89
+ * cancel/cleanup callbacks must clear it. The interval clears itself if a
90
+ * write fails (stream already closed/cancelled).
91
+ */
92
+ startKeepAlive(controller, encoder) {
93
+ // After close() nothing may arm: the stream cleanups have already run.
94
+ if (this._closed)
95
+ return undefined;
96
+ const timer = armSseKeepAlive(this._keepAliveMs, () => {
97
+ try {
98
+ controller.enqueue(encoder.encode(': keepalive\n\n'));
99
+ }
100
+ catch {
101
+ if (timer !== undefined)
102
+ clearInterval(timer);
103
+ }
104
+ });
105
+ return timer;
106
+ }
107
+ /**
108
+ * Starts the transport. This is required by the Transport interface but is a no-op
109
+ * for the Streamable HTTP transport as connections are managed per-request.
110
+ */
111
+ async start() {
112
+ if (this._started) {
113
+ throw new Error('Transport already started');
114
+ }
115
+ this._started = true;
116
+ }
117
+ /**
118
+ * Helper to create a JSON error response
119
+ */
120
+ createJsonErrorResponse(status, code, message, options) {
121
+ const error = { code, message };
122
+ if (options?.data !== undefined) {
123
+ error.data = options.data;
124
+ }
125
+ return new Response(JSON.stringify({
126
+ jsonrpc: '2.0',
127
+ error,
128
+ id: null
129
+ }), {
130
+ status,
131
+ headers: {
132
+ 'Content-Type': 'application/json',
133
+ ...options?.headers
134
+ }
135
+ });
136
+ }
137
+ /**
138
+ * Validates request headers for DNS rebinding protection.
139
+ * @returns Error response if validation fails, undefined if validation passes.
140
+ */
141
+ validateRequestHeaders(req) {
142
+ // Skip validation if protection is not enabled
143
+ if (!this._enableDnsRebindingProtection) {
144
+ return undefined;
145
+ }
146
+ // Validate Host header if allowedHosts is configured
147
+ if (this._allowedHosts && this._allowedHosts.length > 0) {
148
+ const hostHeader = req.headers.get('host');
149
+ if (!hostHeader || !this._allowedHosts.includes(hostHeader)) {
150
+ const error = `Invalid Host header: ${hostHeader}`;
151
+ this.onerror?.(new Error(error));
152
+ return this.createJsonErrorResponse(403, -32000, error);
153
+ }
154
+ }
155
+ // Validate Origin header if allowedOrigins is configured
156
+ if (this._allowedOrigins && this._allowedOrigins.length > 0) {
157
+ const originHeader = req.headers.get('origin');
158
+ if (originHeader && !this._allowedOrigins.includes(originHeader)) {
159
+ const error = `Invalid Origin header: ${originHeader}`;
160
+ this.onerror?.(new Error(error));
161
+ return this.createJsonErrorResponse(403, -32000, error);
162
+ }
163
+ }
164
+ return undefined;
165
+ }
166
+ /**
167
+ * Handles an incoming HTTP request, whether GET, POST, or DELETE
168
+ * Returns a Response object (Web Standard)
169
+ */
170
+ async handleRequest(req, options) {
171
+ if (this._closed) {
172
+ return this.createJsonErrorResponse(404, -32001, 'Session not found');
173
+ }
174
+ // In stateless mode (no sessionIdGenerator), each request must use a fresh transport.
175
+ // Reusing a stateless transport causes message ID collisions between clients.
176
+ if (!this.sessionIdGenerator && this._hasHandledRequest) {
177
+ throw new Error('Stateless transport cannot be reused across requests. Create a new transport per request.');
178
+ }
179
+ this._hasHandledRequest = true;
180
+ // Validate request headers for DNS rebinding protection
181
+ const validationError = this.validateRequestHeaders(req);
182
+ if (validationError) {
183
+ return validationError;
184
+ }
185
+ switch (req.method) {
186
+ case 'POST':
187
+ return this.handlePostRequest(req, options);
188
+ case 'GET':
189
+ return this.handleGetRequest(req);
190
+ case 'DELETE':
191
+ return this.handleDeleteRequest(req);
192
+ default:
193
+ return this.handleUnsupportedRequest();
194
+ }
195
+ }
196
+ /**
197
+ * Writes a priming event to establish resumption capability.
198
+ * Only sends if eventStore is configured (opt-in for resumability) and
199
+ * the client's protocol version supports empty SSE data (>= 2025-11-25).
200
+ */
201
+ async writePrimingEvent(controller, encoder, streamId, protocolVersion) {
202
+ if (!this._eventStore) {
203
+ return;
204
+ }
205
+ // Priming events have empty data which older clients cannot handle.
206
+ // Only send priming events to clients with protocol version >= 2025-11-25
207
+ // which includes the fix for handling empty SSE data.
208
+ if (protocolVersion < '2025-11-25') {
209
+ return;
210
+ }
211
+ const primingEventId = await this._eventStore.storeEvent(streamId, {});
212
+ let primingEvent = `id: ${primingEventId}\ndata: \n\n`;
213
+ if (this._retryInterval !== undefined) {
214
+ primingEvent = `id: ${primingEventId}\nretry: ${this._retryInterval}\ndata: \n\n`;
215
+ }
216
+ controller.enqueue(encoder.encode(primingEvent));
217
+ this._resumableStreams.add(streamId);
218
+ }
219
+ /**
220
+ * Handles GET requests for SSE stream
221
+ */
222
+ async handleGetRequest(req) {
223
+ // The client MUST include an Accept header, listing text/event-stream as a supported content type.
224
+ const acceptHeader = req.headers.get('accept');
225
+ if (!acceptHeader?.includes('text/event-stream')) {
226
+ this.onerror?.(new Error('Not Acceptable: Client must accept text/event-stream'));
227
+ return this.createJsonErrorResponse(406, -32000, 'Not Acceptable: Client must accept text/event-stream');
228
+ }
229
+ // If an Mcp-Session-Id is returned by the server during initialization,
230
+ // clients using the Streamable HTTP transport MUST include it
231
+ // in the Mcp-Session-Id header on all of their subsequent HTTP requests.
232
+ const sessionError = this.validateSession(req);
233
+ if (sessionError) {
234
+ return sessionError;
235
+ }
236
+ const protocolError = this.validateProtocolVersion(req);
237
+ if (protocolError) {
238
+ return protocolError;
239
+ }
240
+ // Handle resumability: check for Last-Event-ID header
241
+ if (this._eventStore) {
242
+ const lastEventId = req.headers.get('last-event-id');
243
+ if (lastEventId) {
244
+ return this.replayEvents(lastEventId);
245
+ }
246
+ }
247
+ // Check if there's already an active standalone SSE stream for this session
248
+ if (this._streamMapping.get(this._standaloneSseStreamId) !== undefined) {
249
+ // Only one GET SSE stream is allowed per session
250
+ this.onerror?.(new Error('Conflict: Only one SSE stream is allowed per session'));
251
+ return this.createJsonErrorResponse(409, -32000, 'Conflict: Only one SSE stream is allowed per session');
252
+ }
253
+ const encoder = new TextEncoder();
254
+ let streamController;
255
+ let keepAliveTimer = undefined;
256
+ // Create a ReadableStream with a controller we can use to push SSE events
257
+ const readable = new ReadableStream({
258
+ start: controller => {
259
+ streamController = controller;
260
+ },
261
+ cancel: () => {
262
+ // Stream was cancelled by client. Only tear down the mapping if it
263
+ // still points at this stream — a stale cancel arriving after a
264
+ // reconnect re-registered the id must not tear down the successor.
265
+ if (keepAliveTimer !== undefined) {
266
+ clearInterval(keepAliveTimer);
267
+ }
268
+ if (this._streamMapping.get(this._standaloneSseStreamId)?.controller === streamController) {
269
+ this._streamMapping.delete(this._standaloneSseStreamId);
270
+ }
271
+ }
272
+ });
273
+ const headers = {
274
+ 'Content-Type': 'text/event-stream',
275
+ 'Cache-Control': 'no-cache, no-transform',
276
+ Connection: 'keep-alive',
277
+ 'X-Accel-Buffering': 'no'
278
+ };
279
+ // After initialization, always include the session ID if we have one
280
+ if (this.sessionId !== undefined) {
281
+ headers['mcp-session-id'] = this.sessionId;
282
+ }
283
+ // Store the stream mapping with the controller for pushing data
284
+ this._streamMapping.set(this._standaloneSseStreamId, {
285
+ controller: streamController,
286
+ encoder,
287
+ cleanup: () => {
288
+ if (keepAliveTimer !== undefined) {
289
+ clearInterval(keepAliveTimer);
290
+ }
291
+ this._streamMapping.delete(this._standaloneSseStreamId);
292
+ try {
293
+ streamController.close();
294
+ }
295
+ catch {
296
+ // Controller might already be closed
297
+ }
298
+ }
299
+ });
300
+ keepAliveTimer = this.startKeepAlive(streamController, encoder);
301
+ return new Response(readable, { headers });
302
+ }
303
+ /**
304
+ * Replays events that would have been sent after the specified event ID
305
+ * Only used when resumability is enabled
306
+ */
307
+ async replayEvents(lastEventId) {
308
+ if (!this._eventStore) {
309
+ this.onerror?.(new Error('Event store not configured'));
310
+ return this.createJsonErrorResponse(400, -32000, 'Event store not configured');
311
+ }
312
+ try {
313
+ // If getStreamIdForEventId is available, use it for conflict checking
314
+ let streamId;
315
+ if (this._eventStore.getStreamIdForEventId) {
316
+ streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
317
+ if (!streamId) {
318
+ this.onerror?.(new Error('Invalid event ID format'));
319
+ return this.createJsonErrorResponse(400, -32000, 'Invalid event ID format');
320
+ }
321
+ // Check conflict with the SAME streamId we'll use for mapping
322
+ if (this._streamMapping.get(streamId) !== undefined) {
323
+ this.onerror?.(new Error('Conflict: Stream already has an active connection'));
324
+ return this.createJsonErrorResponse(409, -32000, 'Conflict: Stream already has an active connection');
325
+ }
326
+ }
327
+ const headers = {
328
+ 'Content-Type': 'text/event-stream',
329
+ 'Cache-Control': 'no-cache, no-transform',
330
+ Connection: 'keep-alive',
331
+ 'X-Accel-Buffering': 'no'
332
+ };
333
+ if (this.sessionId !== undefined) {
334
+ headers['mcp-session-id'] = this.sessionId;
335
+ }
336
+ // Create a ReadableStream with controller for SSE
337
+ const encoder = new TextEncoder();
338
+ let streamController;
339
+ let keepAliveTimer = undefined;
340
+ let replayedStreamId = undefined;
341
+ let cancelled = false;
342
+ const readable = new ReadableStream({
343
+ start: controller => {
344
+ streamController = controller;
345
+ },
346
+ cancel: () => {
347
+ // Stream was cancelled by client. Only tear down the mapping if
348
+ // it still points at this stream — a stale cancel must not tear
349
+ // down a successor registered by a later resume.
350
+ cancelled = true;
351
+ if (keepAliveTimer !== undefined) {
352
+ clearInterval(keepAliveTimer);
353
+ }
354
+ if (replayedStreamId !== undefined && this._streamMapping.get(replayedStreamId)?.controller === streamController) {
355
+ this._streamMapping.delete(replayedStreamId);
356
+ }
357
+ }
358
+ });
359
+ // Replay events - returns the streamId for backwards compatibility
360
+ const replayedEventIds = new Set();
361
+ replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, {
362
+ send: async (eventId, message) => {
363
+ const success = this.writeSSEEvent(streamController, encoder, message, eventId);
364
+ if (!success) {
365
+ this.onerror?.(new Error('Failed replay events'));
366
+ try {
367
+ streamController.close();
368
+ }
369
+ catch {
370
+ // Controller might already be closed
371
+ }
372
+ }
373
+ else {
374
+ replayedEventIds.add(eventId);
375
+ }
376
+ }
377
+ });
378
+ // close() may have run, or the stream may have been cancelled, while
379
+ // the event store was replaying: don't hand out or register a stream
380
+ // that nothing can ever clean up again.
381
+ if (this._closed || cancelled) {
382
+ try {
383
+ streamController.close();
384
+ }
385
+ catch {
386
+ // Controller might already be closed
387
+ }
388
+ return this.createJsonErrorResponse(404, -32001, 'Session not found');
389
+ }
390
+ // A reconnect re-registers the same stream id: close the predecessor
391
+ // stream cleanly (clearing its keep-alive timer) instead of leaving it
392
+ // registered nowhere with its timer still running.
393
+ this._streamMapping.get(replayedStreamId)?.cleanup();
394
+ this._streamMapping.set(replayedStreamId, {
395
+ controller: streamController,
396
+ encoder,
397
+ replayedEventIds,
398
+ cleanup: () => {
399
+ if (keepAliveTimer !== undefined) {
400
+ clearInterval(keepAliveTimer);
401
+ }
402
+ this._streamMapping.delete(replayedStreamId);
403
+ try {
404
+ streamController.close();
405
+ }
406
+ catch {
407
+ // Controller might already be closed
408
+ }
409
+ }
410
+ });
411
+ // The resume itself proves the client holds a Last-Event-ID cursor
412
+ this._resumableStreams.add(replayedStreamId);
413
+ keepAliveTimer = this.startKeepAlive(streamController, encoder);
414
+ return new Response(readable, { headers });
415
+ }
416
+ catch (error) {
417
+ this.onerror?.(error);
418
+ return this.createJsonErrorResponse(500, -32000, 'Error replaying events');
419
+ }
420
+ }
421
+ /**
422
+ * Writes an event to an SSE stream via controller with proper formatting
423
+ */
424
+ writeSSEEvent(controller, encoder, message, eventId) {
425
+ try {
426
+ let eventData = `event: message\n`;
427
+ // Include event ID if provided - this is important for resumability
428
+ if (eventId) {
429
+ eventData += `id: ${eventId}\n`;
430
+ }
431
+ eventData += `data: ${JSON.stringify(message)}\n\n`;
432
+ controller.enqueue(encoder.encode(eventData));
433
+ return true;
434
+ }
435
+ catch (error) {
436
+ this.onerror?.(error);
437
+ return false;
438
+ }
439
+ }
440
+ /**
441
+ * Handles unsupported requests (PUT, PATCH, etc.)
442
+ */
443
+ handleUnsupportedRequest() {
444
+ this.onerror?.(new Error('Method not allowed.'));
445
+ return new Response(JSON.stringify({
446
+ jsonrpc: '2.0',
447
+ error: {
448
+ code: -32000,
449
+ message: 'Method not allowed.'
450
+ },
451
+ id: null
452
+ }), {
453
+ status: 405,
454
+ headers: {
455
+ Allow: 'GET, POST, DELETE',
456
+ 'Content-Type': 'application/json'
457
+ }
458
+ });
459
+ }
460
+ /**
461
+ * Handles POST requests containing JSON-RPC messages
462
+ */
463
+ async handlePostRequest(req, options) {
464
+ try {
465
+ // Validate the Accept header
466
+ const acceptHeader = req.headers.get('accept');
467
+ // The client MUST include an Accept header, listing both application/json and text/event-stream as supported content types.
468
+ // Accept is a comma-separated list, so a substring check is the intended semantics here (unlike Content-Type below).
469
+ // eslint-disable-next-line no-restricted-syntax
470
+ if (!acceptHeader?.includes('application/json') || !acceptHeader.includes('text/event-stream')) {
471
+ this.onerror?.(new Error('Not Acceptable: Client must accept both application/json and text/event-stream'));
472
+ return this.createJsonErrorResponse(406, -32000, 'Not Acceptable: Client must accept both application/json and text/event-stream');
473
+ }
474
+ // Parsed media type, never a substring match — see isJsonContentType.
475
+ const ct = req.headers.get('content-type');
476
+ if (!isJsonContentType(ct)) {
477
+ this.onerror?.(new Error('Unsupported Media Type: Content-Type must be application/json'));
478
+ return this.createJsonErrorResponse(415, -32000, 'Unsupported Media Type: Content-Type must be application/json');
479
+ }
480
+ // Build request info from headers and URL
481
+ const requestInfo = {
482
+ headers: Object.fromEntries(req.headers.entries()),
483
+ url: new URL(req.url)
484
+ };
485
+ let rawMessage;
486
+ if (options?.parsedBody !== undefined) {
487
+ rawMessage = options.parsedBody;
488
+ }
489
+ else {
490
+ try {
491
+ const body = await readRequestBody(req, this._maxRequestBodySize);
492
+ if (body.tooLarge) {
493
+ const message = requestBodyTooLargeMessage(this._maxRequestBodySize);
494
+ this.onerror?.(new Error(message));
495
+ return this.createJsonErrorResponse(413, -32000, message);
496
+ }
497
+ rawMessage = JSON.parse(body.text);
498
+ }
499
+ catch {
500
+ this.onerror?.(new Error('Parse error: Invalid JSON'));
501
+ return this.createJsonErrorResponse(400, -32700, 'Parse error: Invalid JSON');
502
+ }
503
+ }
504
+ if (Array.isArray(rawMessage) && rawMessage.length > MAX_BATCH_SIZE) {
505
+ this.onerror?.(new Error(`Invalid Request: Batch must not exceed ${MAX_BATCH_SIZE} messages`));
506
+ return this.createJsonErrorResponse(400, -32600, `Invalid Request: Batch must not exceed ${MAX_BATCH_SIZE} messages`);
507
+ }
508
+ let messages;
509
+ // handle batch and single messages
510
+ try {
511
+ if (Array.isArray(rawMessage)) {
512
+ messages = rawMessage.map(msg => JSONRPCMessageSchema.parse(msg));
513
+ }
514
+ else {
515
+ messages = [JSONRPCMessageSchema.parse(rawMessage)];
516
+ }
517
+ }
518
+ catch {
519
+ this.onerror?.(new Error('Parse error: Invalid JSON-RPC message'));
520
+ return this.createJsonErrorResponse(400, -32700, 'Parse error: Invalid JSON-RPC message');
521
+ }
522
+ // close() may have run while awaiting the request body above: don't
523
+ // initialize a session (or fire onsessioninitialized) on a transport
524
+ // whose cleanups have already run.
525
+ if (this._closed) {
526
+ return this.createJsonErrorResponse(404, -32001, 'Session not found');
527
+ }
528
+ // Check if this is an initialization request
529
+ // https://spec.modelcontextprotocol.io/specification/2025-03-26/basic/lifecycle/
530
+ const isInitializationRequest = messages.some(isInitializeRequest);
531
+ if (isInitializationRequest) {
532
+ // If it's a server with session management and the session ID is already set we should reject the request
533
+ // to avoid re-initialization.
534
+ if (this._initialized && this.sessionId !== undefined) {
535
+ this.onerror?.(new Error('Invalid Request: Server already initialized'));
536
+ return this.createJsonErrorResponse(400, -32600, 'Invalid Request: Server already initialized');
537
+ }
538
+ if (messages.length > 1) {
539
+ this.onerror?.(new Error('Invalid Request: Only one initialization request is allowed'));
540
+ return this.createJsonErrorResponse(400, -32600, 'Invalid Request: Only one initialization request is allowed');
541
+ }
542
+ this.sessionId = this.sessionIdGenerator?.();
543
+ this._initialized = true;
544
+ // If we have a session ID and an onsessioninitialized handler, call it immediately
545
+ // This is needed in cases where the server needs to keep track of multiple sessions
546
+ if (this.sessionId && this._onsessioninitialized) {
547
+ await Promise.resolve(this._onsessioninitialized(this.sessionId));
548
+ }
549
+ }
550
+ if (!isInitializationRequest) {
551
+ // If an Mcp-Session-Id is returned by the server during initialization,
552
+ // clients using the Streamable HTTP transport MUST include it
553
+ // in the Mcp-Session-Id header on all of their subsequent HTTP requests.
554
+ const sessionError = this.validateSession(req);
555
+ if (sessionError) {
556
+ return sessionError;
557
+ }
558
+ // Mcp-Protocol-Version header is required for all requests after initialization.
559
+ const protocolError = this.validateProtocolVersion(req);
560
+ if (protocolError) {
561
+ return protocolError;
562
+ }
563
+ }
564
+ // close() may have run while awaiting the request body or the session
565
+ // initialization callback above: don't register streams into maps the
566
+ // close sweep has already cleared, or hand out a stream that nothing
567
+ // will ever write to.
568
+ if (this._closed) {
569
+ return this.createJsonErrorResponse(404, -32001, 'Session not found');
570
+ }
571
+ // check if it contains requests
572
+ const hasRequests = messages.some(isJSONRPCRequest);
573
+ if (!hasRequests) {
574
+ // if it only contains notifications or responses, return 202
575
+ for (const message of messages) {
576
+ this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo });
577
+ }
578
+ return new Response(null, { status: 202 });
579
+ }
580
+ // The default behavior is to use SSE streaming
581
+ // but in some cases server will return JSON responses
582
+ const streamId = crypto.randomUUID();
583
+ // Extract protocol version for priming event decision.
584
+ // For initialize requests, get from request params.
585
+ // For other requests, get from header (already validated).
586
+ const initRequest = messages.find(m => isInitializeRequest(m));
587
+ const clientProtocolVersion = initRequest
588
+ ? initRequest.params.protocolVersion
589
+ : (req.headers.get('mcp-protocol-version') ?? DEFAULT_NEGOTIATED_PROTOCOL_VERSION);
590
+ if (this._enableJsonResponse) {
591
+ // For JSON response mode, return a Promise that resolves when all responses are ready
592
+ return new Promise(resolve => {
593
+ this._streamMapping.set(streamId, {
594
+ resolveJson: resolve,
595
+ cleanup: () => {
596
+ this._streamMapping.delete(streamId);
597
+ }
598
+ });
599
+ for (const message of messages) {
600
+ if (isJSONRPCRequest(message)) {
601
+ this._requestToStreamMapping.set(message.id, streamId);
602
+ }
603
+ }
604
+ for (const message of messages) {
605
+ this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo });
606
+ }
607
+ });
608
+ }
609
+ // SSE streaming mode - use ReadableStream with controller for more reliable data pushing
610
+ const encoder = new TextEncoder();
611
+ let streamController;
612
+ let keepAliveTimer = undefined;
613
+ const readable = new ReadableStream({
614
+ start: controller => {
615
+ streamController = controller;
616
+ },
617
+ cancel: () => {
618
+ // Stream was cancelled by client. Only tear down the mapping if
619
+ // it still points at this stream — a stale cancel arriving after
620
+ // a resume re-registered the id must not tear down the successor.
621
+ if (keepAliveTimer !== undefined) {
622
+ clearInterval(keepAliveTimer);
623
+ }
624
+ if (this._streamMapping.get(streamId)?.controller === streamController) {
625
+ this._streamMapping.delete(streamId);
626
+ }
627
+ }
628
+ });
629
+ const headers = {
630
+ 'Content-Type': 'text/event-stream',
631
+ 'Cache-Control': 'no-cache, no-transform',
632
+ Connection: 'keep-alive',
633
+ 'X-Accel-Buffering': 'no'
634
+ };
635
+ // After initialization, always include the session ID if we have one
636
+ if (this.sessionId !== undefined) {
637
+ headers['mcp-session-id'] = this.sessionId;
638
+ }
639
+ // Store the response for this request to send messages back through this connection
640
+ // We need to track by request ID to maintain the connection
641
+ for (const message of messages) {
642
+ if (isJSONRPCRequest(message)) {
643
+ this._streamMapping.set(streamId, {
644
+ controller: streamController,
645
+ encoder,
646
+ cleanup: () => {
647
+ if (keepAliveTimer !== undefined) {
648
+ clearInterval(keepAliveTimer);
649
+ }
650
+ this._streamMapping.delete(streamId);
651
+ try {
652
+ streamController.close();
653
+ }
654
+ catch {
655
+ // Controller might already be closed
656
+ }
657
+ }
658
+ });
659
+ this._requestToStreamMapping.set(message.id, streamId);
660
+ }
661
+ }
662
+ try {
663
+ // Write priming event if event store is configured (after mapping is set up)
664
+ await this.writePrimingEvent(streamController, encoder, streamId, clientProtocolVersion);
665
+ // handle each message
666
+ for (const message of messages) {
667
+ // Build closeSSEStream callback for requests when eventStore is configured
668
+ // AND client supports resumability (protocol version >= 2025-11-25).
669
+ // Old clients can't resume if the stream is closed early because they
670
+ // didn't receive a priming event with an event ID.
671
+ let closeSSEStream;
672
+ let closeStandaloneSSEStream;
673
+ if (isJSONRPCRequest(message) && this._eventStore && clientProtocolVersion >= '2025-11-25') {
674
+ closeSSEStream = () => {
675
+ this.closeSSEStream(message.id);
676
+ };
677
+ closeStandaloneSSEStream = () => {
678
+ this.closeStandaloneSSEStream();
679
+ };
680
+ }
681
+ this.onmessage?.(message, { authInfo: options?.authInfo, requestInfo, closeSSEStream, closeStandaloneSSEStream });
682
+ }
683
+ }
684
+ catch (error) {
685
+ // Failing before the Response is handed out means nothing can ever
686
+ // cancel this stream: release it and its request correlations here.
687
+ this._streamMapping.get(streamId)?.cleanup();
688
+ this._resumableStreams.delete(streamId);
689
+ for (const message of messages) {
690
+ if (isJSONRPCRequest(message)) {
691
+ this._requestToStreamMapping.delete(message.id);
692
+ }
693
+ }
694
+ throw error;
695
+ }
696
+ // The server SHOULD NOT close the SSE stream before sending all JSON-RPC responses
697
+ // This will be handled by the send() method when responses are ready
698
+ // Arm keep-alive only after the fallible awaits above: an error path
699
+ // returns 400 and discards the Response, so nothing could ever cancel
700
+ // the stream and clear an already-armed timer. Skip if the responses
701
+ // already completed and cleaned the stream up.
702
+ if (this._streamMapping.get(streamId)?.controller === streamController) {
703
+ keepAliveTimer = this.startKeepAlive(streamController, encoder);
704
+ }
705
+ return new Response(readable, { status: 200, headers });
706
+ }
707
+ catch (error) {
708
+ // return JSON-RPC formatted error
709
+ this.onerror?.(error);
710
+ return this.createJsonErrorResponse(400, -32700, 'Parse error', { data: String(error) });
711
+ }
712
+ }
713
+ /**
714
+ * Handles DELETE requests to terminate sessions
715
+ */
716
+ async handleDeleteRequest(req) {
717
+ const sessionError = this.validateSession(req);
718
+ if (sessionError) {
719
+ return sessionError;
720
+ }
721
+ const protocolError = this.validateProtocolVersion(req);
722
+ if (protocolError) {
723
+ return protocolError;
724
+ }
725
+ try {
726
+ await Promise.resolve(this._onsessionclosed?.(this.sessionId));
727
+ return new Response(null, { status: 200 });
728
+ }
729
+ finally {
730
+ await this.close();
731
+ }
732
+ }
733
+ /**
734
+ * Validates session ID for non-initialization requests.
735
+ * Returns Response error if invalid, undefined otherwise
736
+ */
737
+ validateSession(req) {
738
+ if (this.sessionIdGenerator === undefined) {
739
+ // If the sessionIdGenerator ID is not set, the session management is disabled
740
+ // and we don't need to validate the session ID
741
+ return undefined;
742
+ }
743
+ if (!this._initialized) {
744
+ // If the server has not been initialized yet, reject all requests
745
+ this.onerror?.(new Error('Bad Request: Server not initialized'));
746
+ return this.createJsonErrorResponse(400, -32000, 'Bad Request: Server not initialized');
747
+ }
748
+ const sessionId = req.headers.get('mcp-session-id');
749
+ if (!sessionId) {
750
+ // Non-initialization requests without a session ID should return 400 Bad Request
751
+ this.onerror?.(new Error('Bad Request: Mcp-Session-Id header is required'));
752
+ return this.createJsonErrorResponse(400, -32000, 'Bad Request: Mcp-Session-Id header is required');
753
+ }
754
+ if (sessionId !== this.sessionId) {
755
+ // Reject requests with invalid session ID with 404 Not Found
756
+ this.onerror?.(new Error('Session not found'));
757
+ return this.createJsonErrorResponse(404, -32001, 'Session not found');
758
+ }
759
+ return undefined;
760
+ }
761
+ /**
762
+ * Validates the MCP-Protocol-Version header on incoming requests.
763
+ *
764
+ * For initialization: Version negotiation handles unknown versions gracefully
765
+ * (server responds with its supported version).
766
+ *
767
+ * For subsequent requests with MCP-Protocol-Version header:
768
+ * - Accept if in supported list
769
+ * - 400 if unsupported
770
+ *
771
+ * For HTTP requests without the MCP-Protocol-Version header:
772
+ * - Accept and default to the version negotiated at initialization
773
+ */
774
+ validateProtocolVersion(req) {
775
+ const protocolVersion = req.headers.get('mcp-protocol-version');
776
+ if (protocolVersion !== null && !SUPPORTED_PROTOCOL_VERSIONS.includes(protocolVersion)) {
777
+ this.onerror?.(new Error(`Bad Request: Unsupported protocol version: ${protocolVersion}` +
778
+ ` (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(', ')})`));
779
+ return this.createJsonErrorResponse(400, -32000, `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${SUPPORTED_PROTOCOL_VERSIONS.join(', ')})`);
780
+ }
781
+ return undefined;
782
+ }
783
+ async close() {
784
+ if (this._closed) {
785
+ return;
786
+ }
787
+ // Stop any deferred keep-alive arm (e.g. a replay await resolving after
788
+ // close) from creating a timer nothing can clear.
789
+ this._closed = true;
790
+ // Close all SSE connections (each cleanup clears its own keep-alive timer)
791
+ this._streamMapping.forEach(({ cleanup }) => {
792
+ cleanup();
793
+ });
794
+ this._streamMapping.clear();
795
+ // Clear any pending responses
796
+ this._requestResponseMap.clear();
797
+ this._resumableStreams.clear();
798
+ this.onclose?.();
799
+ }
800
+ /**
801
+ * Close an SSE stream for a specific request, triggering client reconnection.
802
+ * Use this to implement polling behavior during long-running operations -
803
+ * client will reconnect after the retry interval specified in the priming event.
804
+ */
805
+ closeSSEStream(requestId) {
806
+ const streamId = this._requestToStreamMapping.get(requestId);
807
+ if (!streamId)
808
+ return;
809
+ const stream = this._streamMapping.get(streamId);
810
+ if (stream) {
811
+ stream.cleanup();
812
+ }
813
+ }
814
+ /**
815
+ * Close the standalone GET SSE stream, triggering client reconnection.
816
+ * Use this to implement polling behavior for server-initiated notifications.
817
+ */
818
+ closeStandaloneSSEStream() {
819
+ const stream = this._streamMapping.get(this._standaloneSseStreamId);
820
+ if (stream) {
821
+ stream.cleanup();
822
+ }
823
+ }
824
+ async send(message, options) {
825
+ let requestId = options?.relatedRequestId;
826
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
827
+ // If the message is a response, use the request ID from the message
828
+ requestId = message.id;
829
+ }
830
+ // Check if this message should be sent on the standalone SSE stream (no request ID)
831
+ // Ignore notifications from tools (which have relatedRequestId set)
832
+ // Those will be sent via dedicated response SSE streams
833
+ if (requestId === undefined) {
834
+ // For standalone SSE streams, we can only send requests and notifications
835
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
836
+ throw new Error('Cannot send a response on a standalone SSE stream unless resuming a previous client request');
837
+ }
838
+ // Generate and store event ID if event store is provided
839
+ // Store even if stream is disconnected so events can be replayed on reconnect
840
+ let eventId;
841
+ if (this._eventStore) {
842
+ // Stores the event and gets the generated event ID
843
+ eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message);
844
+ }
845
+ const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId);
846
+ if (standaloneSse === undefined) {
847
+ // Stream is disconnected - event is stored for replay, nothing more to do
848
+ return;
849
+ }
850
+ // Send the message to the standalone SSE stream, unless this stream
851
+ // was registered by a replay that already delivered this event (the
852
+ // store made it visible before this call resumed).
853
+ if (standaloneSse.controller &&
854
+ standaloneSse.encoder &&
855
+ (eventId === undefined || !standaloneSse.replayedEventIds?.has(eventId))) {
856
+ this.writeSSEEvent(standaloneSse.controller, standaloneSse.encoder, message, eventId);
857
+ }
858
+ return;
859
+ }
860
+ // Get the response for this request
861
+ const streamId = this._requestToStreamMapping.get(requestId);
862
+ if (!streamId) {
863
+ throw new Error(`No connection established for request ID: ${String(requestId)}`);
864
+ }
865
+ let stream = this._streamMapping.get(streamId);
866
+ if (!this._enableJsonResponse) {
867
+ // Store the event even if the stream is disconnected (e.g. after
868
+ // closeSSEStream switched the client to polling), so it can be
869
+ // replayed on reconnect — mirroring the standalone stream path.
870
+ let eventId;
871
+ if (this._eventStore) {
872
+ eventId = await this._eventStore.storeEvent(streamId, message);
873
+ // Re-fetch after the await: a resume completing meanwhile replaces
874
+ // this stream's registration with a successor, and the message
875
+ // must go to the live stream, not the evicted one.
876
+ stream = this._streamMapping.get(streamId);
877
+ }
878
+ // Skip the write if the stream was registered by a replay that
879
+ // already delivered this event (the store made it visible before
880
+ // this call resumed).
881
+ if (stream?.controller && stream?.encoder && (eventId === undefined || !stream.replayedEventIds?.has(eventId))) {
882
+ const written = this.writeSSEEvent(stream.controller, stream.encoder, message, eventId);
883
+ // The client now holds a Last-Event-ID cursor for this stream
884
+ if (written && eventId !== undefined) {
885
+ this._resumableStreams.add(streamId);
886
+ }
887
+ }
888
+ }
889
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
890
+ this._requestResponseMap.set(requestId, message);
891
+ const relatedIds = Array.from(this._requestToStreamMapping.entries())
892
+ .filter(([_, sid]) => sid === streamId)
893
+ .map(([id]) => id);
894
+ // Check if we have responses for all requests using this connection
895
+ const allResponsesReady = relatedIds.every(id => this._requestResponseMap.has(id));
896
+ if (allResponsesReady) {
897
+ if (!stream) {
898
+ // close() ran while the event store write above was awaiting:
899
+ // release the entries this call re-created after the sweep,
900
+ // then treat the late completion as a no-op.
901
+ if (this._closed) {
902
+ for (const id of relatedIds) {
903
+ this._requestResponseMap.delete(id);
904
+ this._requestToStreamMapping.delete(id);
905
+ }
906
+ return;
907
+ }
908
+ if (!this._enableJsonResponse && this._eventStore && this._resumableStreams.has(streamId)) {
909
+ // The stream went away (client disconnect, or
910
+ // closeSSEStream switched the client to polling), but the
911
+ // response was stored above and will be replayed on
912
+ // resume — release the correlations rather than throwing.
913
+ for (const id of relatedIds) {
914
+ this._requestResponseMap.delete(id);
915
+ this._requestToStreamMapping.delete(id);
916
+ }
917
+ this._resumableStreams.delete(streamId);
918
+ return;
919
+ }
920
+ // Without resumability (or in JSON response mode, where the
921
+ // pending HTTP response can never be settled by a replay),
922
+ // a missing stream means the response cannot be delivered.
923
+ // Release the correlations so the entries don't outlive the
924
+ // undeliverable response.
925
+ for (const id of relatedIds) {
926
+ this._requestResponseMap.delete(id);
927
+ this._requestToStreamMapping.delete(id);
928
+ }
929
+ throw new Error(`No connection established for request ID: ${String(requestId)}`);
930
+ }
931
+ if (this._enableJsonResponse && stream.resolveJson) {
932
+ // All responses ready, send as JSON
933
+ const headers = {
934
+ 'Content-Type': 'application/json'
935
+ };
936
+ if (this.sessionId !== undefined) {
937
+ headers['mcp-session-id'] = this.sessionId;
938
+ }
939
+ const responses = relatedIds.map(id => this._requestResponseMap.get(id));
940
+ if (responses.length === 1) {
941
+ stream.resolveJson(new Response(JSON.stringify(responses[0]), { status: 200, headers }));
942
+ }
943
+ else {
944
+ stream.resolveJson(new Response(JSON.stringify(responses), { status: 200, headers }));
945
+ }
946
+ }
947
+ else {
948
+ // End the SSE stream
949
+ stream.cleanup();
950
+ }
951
+ // Clean up
952
+ for (const id of relatedIds) {
953
+ this._requestResponseMap.delete(id);
954
+ this._requestToStreamMapping.delete(id);
955
+ }
956
+ this._resumableStreams.delete(streamId);
957
+ }
958
+ }
959
+ }
960
+ }
961
+ //# sourceMappingURL=webStandardStreamableHttp.js.map