bantou 0.1.1 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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/9a6f6e29-92f1-40d0-84d5-974a9154d48f.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 +5858 -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 +226 -23
  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,1137 @@
1
+ import { safeParse } from '../server/zod-compat.js';
2
+ import { CancelledNotificationSchema, CreateTaskResultSchema, ErrorCode, GetTaskRequestSchema, GetTaskResultSchema, GetTaskPayloadRequestSchema, ListTasksRequestSchema, ListTasksResultSchema, CancelTaskRequestSchema, CancelTaskResultSchema, isJSONRPCErrorResponse, isJSONRPCRequest, isJSONRPCResultResponse, isJSONRPCNotification, McpError, PingRequestSchema, ProgressNotificationSchema, RELATED_TASK_META_KEY, TaskStatusNotificationSchema, isTaskAugmentedRequestParams } from '../types.js';
3
+ import { isTerminal } from '../experimental/tasks/interfaces.js';
4
+ import { getMethodLiteral, parseWithCompat } from '../server/zod-json-schema-compat.js';
5
+ /**
6
+ * The default request timeout, in miliseconds.
7
+ */
8
+ export const DEFAULT_REQUEST_TIMEOUT_MSEC = 60000;
9
+ /**
10
+ * Implements MCP protocol framing on top of a pluggable transport, including
11
+ * features like request/response linking, notifications, and progress.
12
+ */
13
+ export class Protocol {
14
+ constructor(_options) {
15
+ this._options = _options;
16
+ this._requestMessageId = 0;
17
+ this._requestHandlers = new Map();
18
+ this._requestHandlerAbortControllers = new Map();
19
+ this._notificationHandlers = new Map();
20
+ this._responseHandlers = new Map();
21
+ this._progressHandlers = new Map();
22
+ this._timeoutInfo = new Map();
23
+ this._pendingDebouncedNotifications = new Set();
24
+ // Maps task IDs to progress tokens to keep handlers alive after CreateTaskResult
25
+ this._taskProgressTokens = new Map();
26
+ this._requestResolvers = new Map();
27
+ this.setNotificationHandler(CancelledNotificationSchema, notification => {
28
+ this._oncancel(notification);
29
+ });
30
+ this.setNotificationHandler(ProgressNotificationSchema, notification => {
31
+ this._onprogress(notification);
32
+ });
33
+ this.setRequestHandler(PingRequestSchema,
34
+ // Automatic pong by default.
35
+ _request => ({}));
36
+ // Install task handlers if TaskStore is provided
37
+ this._taskStore = _options?.taskStore;
38
+ this._taskMessageQueue = _options?.taskMessageQueue;
39
+ if (this._taskStore) {
40
+ this.setRequestHandler(GetTaskRequestSchema, async (request, extra) => {
41
+ const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
42
+ if (!task) {
43
+ throw new McpError(ErrorCode.InvalidParams, 'Failed to retrieve task: Task not found');
44
+ }
45
+ // Per spec: tasks/get responses SHALL NOT include related-task metadata
46
+ // as the taskId parameter is the source of truth
47
+ // @ts-expect-error SendResultT cannot contain GetTaskResult, but we include it in our derived types everywhere else
48
+ return {
49
+ ...task
50
+ };
51
+ });
52
+ this.setRequestHandler(GetTaskPayloadRequestSchema, async (request, extra) => {
53
+ const handleTaskResult = async () => {
54
+ const taskId = request.params.taskId;
55
+ // Look the task up for this session first; queued messages are only delivered for a task it can see.
56
+ if (!(await this._taskStore.getTask(taskId, extra.sessionId))) {
57
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
58
+ }
59
+ // Deliver queued messages
60
+ if (this._taskMessageQueue) {
61
+ let queuedMessage;
62
+ while ((queuedMessage = await this._taskMessageQueue.dequeue(taskId, extra.sessionId))) {
63
+ // Handle response and error messages by routing them to the appropriate resolver
64
+ if (queuedMessage.type === 'response' || queuedMessage.type === 'error') {
65
+ const message = queuedMessage.message;
66
+ const requestId = message.id;
67
+ // Lookup resolver in _requestResolvers map
68
+ const resolver = this._requestResolvers.get(requestId);
69
+ if (resolver) {
70
+ // Remove resolver from map after invocation
71
+ this._requestResolvers.delete(requestId);
72
+ // Invoke resolver with response or error
73
+ if (queuedMessage.type === 'response') {
74
+ resolver(message);
75
+ }
76
+ else {
77
+ // Convert JSONRPCError to McpError
78
+ const errorMessage = message;
79
+ const error = new McpError(errorMessage.error.code, errorMessage.error.message, errorMessage.error.data);
80
+ resolver(error);
81
+ }
82
+ }
83
+ else {
84
+ // Handle missing resolver gracefully with error logging
85
+ const messageType = queuedMessage.type === 'response' ? 'Response' : 'Error';
86
+ this._onerror(new Error(`${messageType} handler missing for request ${requestId}`));
87
+ }
88
+ // Continue to next message
89
+ continue;
90
+ }
91
+ // Send the message on the response stream by passing the relatedRequestId
92
+ // This tells the transport to write the message to the tasks/result response stream
93
+ await this._transport?.send(queuedMessage.message, { relatedRequestId: extra.requestId });
94
+ }
95
+ }
96
+ // Now check task status
97
+ const task = await this._taskStore.getTask(taskId, extra.sessionId);
98
+ if (!task) {
99
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${taskId}`);
100
+ }
101
+ // Block if task is not terminal (we've already delivered all queued messages above)
102
+ if (!isTerminal(task.status)) {
103
+ // Wait for status change or new messages
104
+ await this._waitForTaskUpdate(taskId, extra.signal, extra.sessionId);
105
+ // After waking up, recursively call to deliver any new messages or result
106
+ return await handleTaskResult();
107
+ }
108
+ // If task is terminal, return the result
109
+ if (isTerminal(task.status)) {
110
+ const result = await this._taskStore.getTaskResult(taskId, extra.sessionId);
111
+ this._clearTaskQueue(taskId, extra.sessionId);
112
+ return {
113
+ ...result,
114
+ _meta: {
115
+ ...result._meta,
116
+ [RELATED_TASK_META_KEY]: {
117
+ taskId: taskId
118
+ }
119
+ }
120
+ };
121
+ }
122
+ return await handleTaskResult();
123
+ };
124
+ return await handleTaskResult();
125
+ });
126
+ this.setRequestHandler(ListTasksRequestSchema, async (request, extra) => {
127
+ try {
128
+ const { tasks, nextCursor } = await this._taskStore.listTasks(request.params?.cursor, extra.sessionId);
129
+ // @ts-expect-error SendResultT cannot contain ListTasksResult, but we include it in our derived types everywhere else
130
+ return {
131
+ tasks,
132
+ nextCursor,
133
+ _meta: {}
134
+ };
135
+ }
136
+ catch (error) {
137
+ throw new McpError(ErrorCode.InvalidParams, `Failed to list tasks: ${error instanceof Error ? error.message : String(error)}`);
138
+ }
139
+ });
140
+ this.setRequestHandler(CancelTaskRequestSchema, async (request, extra) => {
141
+ try {
142
+ // Get the current task to check if it's in a terminal state, in case the implementation is not atomic
143
+ const task = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
144
+ if (!task) {
145
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${request.params.taskId}`);
146
+ }
147
+ // Reject cancellation of terminal tasks
148
+ if (isTerminal(task.status)) {
149
+ throw new McpError(ErrorCode.InvalidParams, `Cannot cancel task in terminal status: ${task.status}`);
150
+ }
151
+ await this._taskStore.updateTaskStatus(request.params.taskId, 'cancelled', 'Client cancelled task execution.', extra.sessionId);
152
+ this._clearTaskQueue(request.params.taskId, extra.sessionId);
153
+ const cancelledTask = await this._taskStore.getTask(request.params.taskId, extra.sessionId);
154
+ if (!cancelledTask) {
155
+ // Task was deleted during cancellation (e.g., cleanup happened)
156
+ throw new McpError(ErrorCode.InvalidParams, `Task not found after cancellation: ${request.params.taskId}`);
157
+ }
158
+ return {
159
+ _meta: {},
160
+ ...cancelledTask
161
+ };
162
+ }
163
+ catch (error) {
164
+ // Re-throw McpError as-is
165
+ if (error instanceof McpError) {
166
+ throw error;
167
+ }
168
+ throw new McpError(ErrorCode.InvalidRequest, `Failed to cancel task: ${error instanceof Error ? error.message : String(error)}`);
169
+ }
170
+ });
171
+ }
172
+ }
173
+ async _oncancel(notification) {
174
+ if (!notification.params.requestId) {
175
+ return;
176
+ }
177
+ // Handle request cancellation
178
+ const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
179
+ controller?.abort(notification.params.reason);
180
+ }
181
+ _setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
182
+ this._timeoutInfo.set(messageId, {
183
+ timeoutId: setTimeout(onTimeout, timeout),
184
+ startTime: Date.now(),
185
+ timeout,
186
+ maxTotalTimeout,
187
+ resetTimeoutOnProgress,
188
+ onTimeout
189
+ });
190
+ }
191
+ _resetTimeout(messageId) {
192
+ const info = this._timeoutInfo.get(messageId);
193
+ if (!info)
194
+ return false;
195
+ const totalElapsed = Date.now() - info.startTime;
196
+ if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) {
197
+ this._timeoutInfo.delete(messageId);
198
+ throw McpError.fromError(ErrorCode.RequestTimeout, 'Maximum total timeout exceeded', {
199
+ maxTotalTimeout: info.maxTotalTimeout,
200
+ totalElapsed
201
+ });
202
+ }
203
+ clearTimeout(info.timeoutId);
204
+ info.timeoutId = setTimeout(info.onTimeout, info.timeout);
205
+ return true;
206
+ }
207
+ _cleanupTimeout(messageId) {
208
+ const info = this._timeoutInfo.get(messageId);
209
+ if (info) {
210
+ clearTimeout(info.timeoutId);
211
+ this._timeoutInfo.delete(messageId);
212
+ }
213
+ }
214
+ /**
215
+ * Attaches to the given transport, starts it, and starts listening for messages.
216
+ *
217
+ * The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
218
+ */
219
+ async connect(transport) {
220
+ if (this._transport) {
221
+ throw new Error('Already connected to a transport. Call close() before connecting to a new transport, or use a separate Protocol instance per connection.');
222
+ }
223
+ this._transport = transport;
224
+ const _onclose = this.transport?.onclose;
225
+ this._transport.onclose = () => {
226
+ _onclose?.();
227
+ this._onclose();
228
+ };
229
+ const _onerror = this.transport?.onerror;
230
+ this._transport.onerror = (error) => {
231
+ _onerror?.(error);
232
+ this._onerror(error);
233
+ };
234
+ const _onmessage = this._transport?.onmessage;
235
+ this._transport.onmessage = (message, extra) => {
236
+ _onmessage?.(message, extra);
237
+ if (isJSONRPCResultResponse(message) || isJSONRPCErrorResponse(message)) {
238
+ this._onresponse(message);
239
+ }
240
+ else if (isJSONRPCRequest(message)) {
241
+ this._onrequest(message, extra);
242
+ }
243
+ else if (isJSONRPCNotification(message)) {
244
+ this._onnotification(message);
245
+ }
246
+ else {
247
+ this._onerror(new Error(`Unknown message type: ${JSON.stringify(message)}`));
248
+ }
249
+ };
250
+ await this._transport.start();
251
+ }
252
+ _onclose() {
253
+ const responseHandlers = this._responseHandlers;
254
+ this._responseHandlers = new Map();
255
+ this._progressHandlers.clear();
256
+ this._taskProgressTokens.clear();
257
+ this._pendingDebouncedNotifications.clear();
258
+ for (const info of this._timeoutInfo.values()) {
259
+ clearTimeout(info.timeoutId);
260
+ }
261
+ this._timeoutInfo.clear();
262
+ // Abort all in-flight request handlers so they stop sending messages
263
+ for (const controller of this._requestHandlerAbortControllers.values()) {
264
+ controller.abort();
265
+ }
266
+ this._requestHandlerAbortControllers.clear();
267
+ const error = McpError.fromError(ErrorCode.ConnectionClosed, 'Connection closed');
268
+ this._transport = undefined;
269
+ this.onclose?.();
270
+ for (const handler of responseHandlers.values()) {
271
+ handler(error);
272
+ }
273
+ }
274
+ _onerror(error) {
275
+ this.onerror?.(error);
276
+ }
277
+ _onnotification(notification) {
278
+ const handler = this._notificationHandlers.get(notification.method) ?? this.fallbackNotificationHandler;
279
+ // Ignore notifications not being subscribed to.
280
+ if (handler === undefined) {
281
+ return;
282
+ }
283
+ // Starting with Promise.resolve() puts any synchronous errors into the monad as well.
284
+ Promise.resolve()
285
+ .then(() => handler(notification))
286
+ .catch(error => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
287
+ }
288
+ _onrequest(request, extra) {
289
+ const handler = this._requestHandlers.get(request.method) ?? this.fallbackRequestHandler;
290
+ // Capture the current transport at request time to ensure responses go to the correct client
291
+ const capturedTransport = this._transport;
292
+ // Extract taskId from request metadata if present (needed early for method not found case)
293
+ const relatedTaskId = request.params?._meta?.[RELATED_TASK_META_KEY]?.taskId;
294
+ // With a session, the related task is looked up for that session first; replies are queued for it only if it is found.
295
+ const sessionId = capturedTransport?.sessionId;
296
+ const store = this._taskStore;
297
+ let relatedTaskFound = true;
298
+ let relatedTaskLookup;
299
+ if (relatedTaskId && store && this._taskMessageQueue && sessionId !== undefined) {
300
+ relatedTaskFound = false;
301
+ relatedTaskLookup = (async () => {
302
+ if (!(await store.getTask(relatedTaskId, sessionId))) {
303
+ throw new McpError(ErrorCode.InvalidParams, `Task not found: ${relatedTaskId}`);
304
+ }
305
+ relatedTaskFound = true;
306
+ })();
307
+ }
308
+ if (handler === undefined) {
309
+ const errorResponse = {
310
+ jsonrpc: '2.0',
311
+ id: request.id,
312
+ error: {
313
+ code: ErrorCode.MethodNotFound,
314
+ message: 'Method not found'
315
+ }
316
+ };
317
+ // Queue or send the error response based on whether this is a task-related request
318
+ if (relatedTaskId && relatedTaskLookup) {
319
+ const queuedError = { type: 'error', message: errorResponse, timestamp: Date.now() };
320
+ relatedTaskLookup
321
+ .then(() => this._enqueueTaskMessage(relatedTaskId, queuedError, sessionId), () => capturedTransport?.send(errorResponse))
322
+ .catch(error => this._onerror(new Error(`Failed to send an error response: ${error}`)));
323
+ }
324
+ else if (relatedTaskId && this._taskMessageQueue) {
325
+ this._enqueueTaskMessage(relatedTaskId, {
326
+ type: 'error',
327
+ message: errorResponse,
328
+ timestamp: Date.now()
329
+ }, capturedTransport?.sessionId).catch(error => this._onerror(new Error(`Failed to enqueue error response: ${error}`)));
330
+ }
331
+ else {
332
+ capturedTransport
333
+ ?.send(errorResponse)
334
+ .catch(error => this._onerror(new Error(`Failed to send an error response: ${error}`)));
335
+ }
336
+ return;
337
+ }
338
+ const abortController = new AbortController();
339
+ this._requestHandlerAbortControllers.set(request.id, abortController);
340
+ const taskCreationParams = isTaskAugmentedRequestParams(request.params) ? request.params.task : undefined;
341
+ const taskStore = this._taskStore ? this.requestTaskStore(request, capturedTransport?.sessionId) : undefined;
342
+ const fullExtra = {
343
+ signal: abortController.signal,
344
+ sessionId: capturedTransport?.sessionId,
345
+ _meta: request.params?._meta,
346
+ sendNotification: async (notification) => {
347
+ if (abortController.signal.aborted)
348
+ return;
349
+ // Include related-task metadata if this request is part of a task
350
+ const notificationOptions = { relatedRequestId: request.id };
351
+ if (relatedTaskId) {
352
+ notificationOptions.relatedTask = { taskId: relatedTaskId };
353
+ }
354
+ await this.notification(notification, notificationOptions);
355
+ },
356
+ sendRequest: async (r, resultSchema, options) => {
357
+ if (abortController.signal.aborted) {
358
+ throw new McpError(ErrorCode.ConnectionClosed, 'Request was cancelled');
359
+ }
360
+ // Include related-task metadata if this request is part of a task
361
+ const requestOptions = { ...options, relatedRequestId: request.id };
362
+ if (relatedTaskId && !requestOptions.relatedTask) {
363
+ requestOptions.relatedTask = { taskId: relatedTaskId };
364
+ }
365
+ // Set task status to input_required when sending a request within a task context
366
+ // Use the taskId from options (explicit) or fall back to relatedTaskId (inherited)
367
+ const effectiveTaskId = requestOptions.relatedTask?.taskId ?? relatedTaskId;
368
+ if (effectiveTaskId && taskStore) {
369
+ await taskStore.updateTaskStatus(effectiveTaskId, 'input_required');
370
+ }
371
+ return await this.request(r, resultSchema, requestOptions);
372
+ },
373
+ authInfo: extra?.authInfo,
374
+ requestId: request.id,
375
+ requestInfo: extra?.requestInfo,
376
+ taskId: relatedTaskId,
377
+ taskStore: taskStore,
378
+ taskRequestedTtl: taskCreationParams?.ttl,
379
+ closeSSEStream: extra?.closeSSEStream,
380
+ closeStandaloneSSEStream: extra?.closeStandaloneSSEStream
381
+ };
382
+ // Starting with Promise.resolve() puts any synchronous errors into the monad as well.
383
+ (relatedTaskLookup ?? Promise.resolve())
384
+ .then(() => {
385
+ // A request cancelled while its related task was looked up does not start its handler; nothing is replied.
386
+ if (relatedTaskLookup && abortController.signal.aborted) {
387
+ throw new McpError(ErrorCode.ConnectionClosed, 'Request was cancelled');
388
+ }
389
+ // If this request asked for task creation, check capability first
390
+ if (taskCreationParams) {
391
+ // Check if the request method supports task creation
392
+ this.assertTaskHandlerCapability(request.method);
393
+ }
394
+ })
395
+ .then(() => handler(request, fullExtra))
396
+ .then(async (result) => {
397
+ if (abortController.signal.aborted) {
398
+ // Request was cancelled
399
+ return;
400
+ }
401
+ const response = {
402
+ result,
403
+ jsonrpc: '2.0',
404
+ id: request.id
405
+ };
406
+ // Queue or send the response based on whether this is a task-related request
407
+ if (relatedTaskId && this._taskMessageQueue) {
408
+ await this._enqueueTaskMessage(relatedTaskId, {
409
+ type: 'response',
410
+ message: response,
411
+ timestamp: Date.now()
412
+ }, capturedTransport?.sessionId);
413
+ }
414
+ else {
415
+ await capturedTransport?.send(response);
416
+ }
417
+ }, async (error) => {
418
+ if (abortController.signal.aborted) {
419
+ // Request was cancelled
420
+ return;
421
+ }
422
+ const errorResponse = {
423
+ jsonrpc: '2.0',
424
+ id: request.id,
425
+ error: {
426
+ code: Number.isSafeInteger(error['code']) ? error['code'] : ErrorCode.InternalError,
427
+ message: error.message ?? 'Internal error',
428
+ ...(error['data'] !== undefined && { data: error['data'] })
429
+ }
430
+ };
431
+ // Queue or send the error response based on whether this is a task-related request
432
+ if (relatedTaskId && this._taskMessageQueue && relatedTaskFound) {
433
+ await this._enqueueTaskMessage(relatedTaskId, {
434
+ type: 'error',
435
+ message: errorResponse,
436
+ timestamp: Date.now()
437
+ }, capturedTransport?.sessionId);
438
+ }
439
+ else {
440
+ await capturedTransport?.send(errorResponse);
441
+ }
442
+ })
443
+ .catch(error => this._onerror(new Error(`Failed to send response: ${error}`)))
444
+ .finally(() => {
445
+ // Only delete if the stored controller is still ours; after close()+connect(),
446
+ // a new connection may have reused the same request ID with a different controller.
447
+ if (this._requestHandlerAbortControllers.get(request.id) === abortController) {
448
+ this._requestHandlerAbortControllers.delete(request.id);
449
+ }
450
+ });
451
+ }
452
+ _onprogress(notification) {
453
+ const { progressToken, ...params } = notification.params;
454
+ const messageId = Number(progressToken);
455
+ const handler = this._progressHandlers.get(messageId);
456
+ if (!handler) {
457
+ this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(notification)}`));
458
+ return;
459
+ }
460
+ const responseHandler = this._responseHandlers.get(messageId);
461
+ const timeoutInfo = this._timeoutInfo.get(messageId);
462
+ if (timeoutInfo && responseHandler && timeoutInfo.resetTimeoutOnProgress) {
463
+ try {
464
+ this._resetTimeout(messageId);
465
+ }
466
+ catch (error) {
467
+ // Clean up if maxTotalTimeout was exceeded
468
+ this._responseHandlers.delete(messageId);
469
+ this._progressHandlers.delete(messageId);
470
+ this._cleanupTimeout(messageId);
471
+ responseHandler(error);
472
+ return;
473
+ }
474
+ }
475
+ handler(params);
476
+ }
477
+ _onresponse(response) {
478
+ const messageId = Number(response.id);
479
+ // Check if this is a response to a queued request
480
+ const resolver = this._requestResolvers.get(messageId);
481
+ if (resolver) {
482
+ this._requestResolvers.delete(messageId);
483
+ if (isJSONRPCResultResponse(response)) {
484
+ resolver(response);
485
+ }
486
+ else {
487
+ const error = new McpError(response.error.code, response.error.message, response.error.data);
488
+ resolver(error);
489
+ }
490
+ return;
491
+ }
492
+ const handler = this._responseHandlers.get(messageId);
493
+ if (handler === undefined) {
494
+ this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`));
495
+ return;
496
+ }
497
+ this._responseHandlers.delete(messageId);
498
+ this._cleanupTimeout(messageId);
499
+ // Keep progress handler alive for CreateTaskResult responses
500
+ let isTaskResponse = false;
501
+ if (isJSONRPCResultResponse(response) && response.result && typeof response.result === 'object') {
502
+ const result = response.result;
503
+ if (result.task && typeof result.task === 'object') {
504
+ const task = result.task;
505
+ if (typeof task.taskId === 'string') {
506
+ isTaskResponse = true;
507
+ this._taskProgressTokens.set(task.taskId, messageId);
508
+ }
509
+ }
510
+ }
511
+ if (!isTaskResponse) {
512
+ this._progressHandlers.delete(messageId);
513
+ }
514
+ if (isJSONRPCResultResponse(response)) {
515
+ handler(response);
516
+ }
517
+ else {
518
+ const error = McpError.fromError(response.error.code, response.error.message, response.error.data);
519
+ handler(error);
520
+ }
521
+ }
522
+ get transport() {
523
+ return this._transport;
524
+ }
525
+ /**
526
+ * Closes the connection.
527
+ */
528
+ async close() {
529
+ await this._transport?.close();
530
+ }
531
+ /**
532
+ * Sends a request and returns an AsyncGenerator that yields response messages.
533
+ * The generator is guaranteed to end with either a 'result' or 'error' message.
534
+ *
535
+ * @example
536
+ * ```typescript
537
+ * const stream = protocol.requestStream(request, resultSchema, options);
538
+ * for await (const message of stream) {
539
+ * switch (message.type) {
540
+ * case 'taskCreated':
541
+ * console.log('Task created:', message.task.taskId);
542
+ * break;
543
+ * case 'taskStatus':
544
+ * console.log('Task status:', message.task.status);
545
+ * break;
546
+ * case 'result':
547
+ * console.log('Final result:', message.result);
548
+ * break;
549
+ * case 'error':
550
+ * console.error('Error:', message.error);
551
+ * break;
552
+ * }
553
+ * }
554
+ * ```
555
+ *
556
+ * @experimental Use `client.experimental.tasks.requestStream()` to access this method.
557
+ */
558
+ async *requestStream(request, resultSchema, options) {
559
+ const { task } = options ?? {};
560
+ // For non-task requests, just yield the result
561
+ if (!task) {
562
+ try {
563
+ const result = await this.request(request, resultSchema, options);
564
+ yield { type: 'result', result };
565
+ }
566
+ catch (error) {
567
+ yield {
568
+ type: 'error',
569
+ error: error instanceof McpError ? error : new McpError(ErrorCode.InternalError, String(error))
570
+ };
571
+ }
572
+ return;
573
+ }
574
+ // For task-augmented requests, we need to poll for status
575
+ // First, make the request to create the task
576
+ let taskId;
577
+ try {
578
+ // Send the request and get the CreateTaskResult
579
+ const createResult = await this.request(request, CreateTaskResultSchema, options);
580
+ // Extract taskId from the result
581
+ if (createResult.task) {
582
+ taskId = createResult.task.taskId;
583
+ yield { type: 'taskCreated', task: createResult.task };
584
+ }
585
+ else {
586
+ throw new McpError(ErrorCode.InternalError, 'Task creation did not return a task');
587
+ }
588
+ // Poll for task completion
589
+ while (true) {
590
+ // Get current task status
591
+ const task = await this.getTask({ taskId }, options);
592
+ yield { type: 'taskStatus', task };
593
+ // Check if task is terminal
594
+ if (isTerminal(task.status)) {
595
+ if (task.status === 'completed') {
596
+ // Get the final result
597
+ const result = await this.getTaskResult({ taskId }, resultSchema, options);
598
+ yield { type: 'result', result };
599
+ }
600
+ else if (task.status === 'failed') {
601
+ yield {
602
+ type: 'error',
603
+ error: new McpError(ErrorCode.InternalError, `Task ${taskId} failed`)
604
+ };
605
+ }
606
+ else if (task.status === 'cancelled') {
607
+ yield {
608
+ type: 'error',
609
+ error: new McpError(ErrorCode.InternalError, `Task ${taskId} was cancelled`)
610
+ };
611
+ }
612
+ return;
613
+ }
614
+ // When input_required, call tasks/result to deliver queued messages
615
+ // (elicitation, sampling) via SSE and block until terminal
616
+ if (task.status === 'input_required') {
617
+ const result = await this.getTaskResult({ taskId }, resultSchema, options);
618
+ yield { type: 'result', result };
619
+ return;
620
+ }
621
+ // Wait before polling again
622
+ const pollInterval = task.pollInterval ?? this._options?.defaultTaskPollInterval ?? 1000;
623
+ await new Promise(resolve => setTimeout(resolve, pollInterval));
624
+ // Check if cancelled
625
+ options?.signal?.throwIfAborted();
626
+ }
627
+ }
628
+ catch (error) {
629
+ yield {
630
+ type: 'error',
631
+ error: error instanceof McpError ? error : new McpError(ErrorCode.InternalError, String(error))
632
+ };
633
+ }
634
+ }
635
+ /**
636
+ * Sends a request and waits for a response.
637
+ *
638
+ * Do not use this method to emit notifications! Use notification() instead.
639
+ */
640
+ request(request, resultSchema, options) {
641
+ const { relatedRequestId, resumptionToken, onresumptiontoken, task, relatedTask } = options ?? {};
642
+ // Send the request
643
+ return new Promise((resolve, reject) => {
644
+ const earlyReject = (error) => {
645
+ reject(error);
646
+ };
647
+ if (!this._transport) {
648
+ earlyReject(new Error('Not connected'));
649
+ return;
650
+ }
651
+ if (this._options?.enforceStrictCapabilities === true) {
652
+ try {
653
+ this.assertCapabilityForMethod(request.method);
654
+ // If task creation is requested, also check task capabilities
655
+ if (task) {
656
+ this.assertTaskCapability(request.method);
657
+ }
658
+ }
659
+ catch (e) {
660
+ earlyReject(e);
661
+ return;
662
+ }
663
+ }
664
+ options?.signal?.throwIfAborted();
665
+ const messageId = this._requestMessageId++;
666
+ const jsonrpcRequest = {
667
+ ...request,
668
+ jsonrpc: '2.0',
669
+ id: messageId
670
+ };
671
+ if (options?.onprogress) {
672
+ this._progressHandlers.set(messageId, options.onprogress);
673
+ jsonrpcRequest.params = {
674
+ ...request.params,
675
+ _meta: {
676
+ ...(request.params?._meta || {}),
677
+ progressToken: messageId
678
+ }
679
+ };
680
+ }
681
+ // Augment with task creation parameters if provided
682
+ if (task) {
683
+ jsonrpcRequest.params = {
684
+ ...jsonrpcRequest.params,
685
+ task: task
686
+ };
687
+ }
688
+ // Augment with related task metadata if relatedTask is provided
689
+ if (relatedTask) {
690
+ jsonrpcRequest.params = {
691
+ ...jsonrpcRequest.params,
692
+ _meta: {
693
+ ...(jsonrpcRequest.params?._meta || {}),
694
+ [RELATED_TASK_META_KEY]: relatedTask
695
+ }
696
+ };
697
+ }
698
+ const cancel = (reason) => {
699
+ this._responseHandlers.delete(messageId);
700
+ this._progressHandlers.delete(messageId);
701
+ this._cleanupTimeout(messageId);
702
+ this._transport
703
+ ?.send({
704
+ jsonrpc: '2.0',
705
+ method: 'notifications/cancelled',
706
+ params: {
707
+ requestId: messageId,
708
+ reason: String(reason)
709
+ }
710
+ }, { relatedRequestId, resumptionToken, onresumptiontoken })
711
+ .catch(error => this._onerror(new Error(`Failed to send cancellation: ${error}`)));
712
+ // Wrap the reason in an McpError if it isn't already
713
+ const error = reason instanceof McpError ? reason : new McpError(ErrorCode.RequestTimeout, String(reason));
714
+ reject(error);
715
+ };
716
+ this._responseHandlers.set(messageId, response => {
717
+ if (options?.signal?.aborted) {
718
+ return;
719
+ }
720
+ if (response instanceof Error) {
721
+ return reject(response);
722
+ }
723
+ try {
724
+ const parseResult = safeParse(resultSchema, response.result);
725
+ if (!parseResult.success) {
726
+ // Type guard: if success is false, error is guaranteed to exist
727
+ reject(parseResult.error);
728
+ }
729
+ else {
730
+ resolve(parseResult.data);
731
+ }
732
+ }
733
+ catch (error) {
734
+ reject(error);
735
+ }
736
+ });
737
+ options?.signal?.addEventListener('abort', () => {
738
+ cancel(options?.signal?.reason);
739
+ });
740
+ const timeout = options?.timeout ?? DEFAULT_REQUEST_TIMEOUT_MSEC;
741
+ const timeoutHandler = () => cancel(McpError.fromError(ErrorCode.RequestTimeout, 'Request timed out', { timeout }));
742
+ this._setupTimeout(messageId, timeout, options?.maxTotalTimeout, timeoutHandler, options?.resetTimeoutOnProgress ?? false);
743
+ // Queue request if related to a task
744
+ const relatedTaskId = relatedTask?.taskId;
745
+ if (relatedTaskId) {
746
+ // Store the response resolver for this request so responses can be routed back
747
+ const responseResolver = (response) => {
748
+ const handler = this._responseHandlers.get(messageId);
749
+ if (handler) {
750
+ handler(response);
751
+ }
752
+ else {
753
+ // Log error when resolver is missing, but don't fail
754
+ this._onerror(new Error(`Response handler missing for side-channeled request ${messageId}`));
755
+ }
756
+ };
757
+ this._requestResolvers.set(messageId, responseResolver);
758
+ this._enqueueTaskMessage(relatedTaskId, {
759
+ type: 'request',
760
+ message: jsonrpcRequest,
761
+ timestamp: Date.now()
762
+ }).catch(error => {
763
+ this._cleanupTimeout(messageId);
764
+ reject(error);
765
+ });
766
+ // Don't send through transport - queued messages are delivered via tasks/result only
767
+ // This prevents duplicate delivery for bidirectional transports
768
+ }
769
+ else {
770
+ // No related task - send through transport normally
771
+ this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch(error => {
772
+ this._cleanupTimeout(messageId);
773
+ reject(error);
774
+ });
775
+ }
776
+ });
777
+ }
778
+ /**
779
+ * Gets the current status of a task.
780
+ *
781
+ * @experimental Use `client.experimental.tasks.getTask()` to access this method.
782
+ */
783
+ async getTask(params, options) {
784
+ // @ts-expect-error SendRequestT cannot directly contain GetTaskRequest, but we ensure all type instantiations contain it anyways
785
+ return this.request({ method: 'tasks/get', params }, GetTaskResultSchema, options);
786
+ }
787
+ /**
788
+ * Retrieves the result of a completed task.
789
+ *
790
+ * @experimental Use `client.experimental.tasks.getTaskResult()` to access this method.
791
+ */
792
+ async getTaskResult(params, resultSchema, options) {
793
+ // @ts-expect-error SendRequestT cannot directly contain GetTaskPayloadRequest, but we ensure all type instantiations contain it anyways
794
+ return this.request({ method: 'tasks/result', params }, resultSchema, options);
795
+ }
796
+ /**
797
+ * Lists tasks, optionally starting from a pagination cursor.
798
+ *
799
+ * @experimental Use `client.experimental.tasks.listTasks()` to access this method.
800
+ */
801
+ async listTasks(params, options) {
802
+ // @ts-expect-error SendRequestT cannot directly contain ListTasksRequest, but we ensure all type instantiations contain it anyways
803
+ return this.request({ method: 'tasks/list', params }, ListTasksResultSchema, options);
804
+ }
805
+ /**
806
+ * Cancels a specific task.
807
+ *
808
+ * @experimental Use `client.experimental.tasks.cancelTask()` to access this method.
809
+ */
810
+ async cancelTask(params, options) {
811
+ // @ts-expect-error SendRequestT cannot directly contain CancelTaskRequest, but we ensure all type instantiations contain it anyways
812
+ return this.request({ method: 'tasks/cancel', params }, CancelTaskResultSchema, options);
813
+ }
814
+ /**
815
+ * Emits a notification, which is a one-way message that does not expect a response.
816
+ */
817
+ async notification(notification, options) {
818
+ if (!this._transport) {
819
+ throw new Error('Not connected');
820
+ }
821
+ this.assertNotificationCapability(notification.method);
822
+ // Queue notification if related to a task
823
+ const relatedTaskId = options?.relatedTask?.taskId;
824
+ if (relatedTaskId) {
825
+ // Build the JSONRPC notification with metadata
826
+ const jsonrpcNotification = {
827
+ ...notification,
828
+ jsonrpc: '2.0',
829
+ params: {
830
+ ...notification.params,
831
+ _meta: {
832
+ ...(notification.params?._meta || {}),
833
+ [RELATED_TASK_META_KEY]: options.relatedTask
834
+ }
835
+ }
836
+ };
837
+ await this._enqueueTaskMessage(relatedTaskId, {
838
+ type: 'notification',
839
+ message: jsonrpcNotification,
840
+ timestamp: Date.now()
841
+ });
842
+ // Don't send through transport - queued messages are delivered via tasks/result only
843
+ // This prevents duplicate delivery for bidirectional transports
844
+ return;
845
+ }
846
+ const debouncedMethods = this._options?.debouncedNotificationMethods ?? [];
847
+ // A notification can only be debounced if it's in the list AND it's "simple"
848
+ // (i.e., has no parameters and no related request ID or related task that could be lost).
849
+ const canDebounce = debouncedMethods.includes(notification.method) && !notification.params && !options?.relatedRequestId && !options?.relatedTask;
850
+ if (canDebounce) {
851
+ // If a notification of this type is already scheduled, do nothing.
852
+ if (this._pendingDebouncedNotifications.has(notification.method)) {
853
+ return;
854
+ }
855
+ // Mark this notification type as pending.
856
+ this._pendingDebouncedNotifications.add(notification.method);
857
+ // Schedule the actual send to happen in the next microtask.
858
+ // This allows all synchronous calls in the current event loop tick to be coalesced.
859
+ Promise.resolve().then(() => {
860
+ // Un-mark the notification so the next one can be scheduled.
861
+ this._pendingDebouncedNotifications.delete(notification.method);
862
+ // SAFETY CHECK: If the connection was closed while this was pending, abort.
863
+ if (!this._transport) {
864
+ return;
865
+ }
866
+ let jsonrpcNotification = {
867
+ ...notification,
868
+ jsonrpc: '2.0'
869
+ };
870
+ // Augment with related task metadata if relatedTask is provided
871
+ if (options?.relatedTask) {
872
+ jsonrpcNotification = {
873
+ ...jsonrpcNotification,
874
+ params: {
875
+ ...jsonrpcNotification.params,
876
+ _meta: {
877
+ ...(jsonrpcNotification.params?._meta || {}),
878
+ [RELATED_TASK_META_KEY]: options.relatedTask
879
+ }
880
+ }
881
+ };
882
+ }
883
+ // Send the notification, but don't await it here to avoid blocking.
884
+ // Handle potential errors with a .catch().
885
+ this._transport?.send(jsonrpcNotification, options).catch(error => this._onerror(error));
886
+ });
887
+ // Return immediately.
888
+ return;
889
+ }
890
+ let jsonrpcNotification = {
891
+ ...notification,
892
+ jsonrpc: '2.0'
893
+ };
894
+ // Augment with related task metadata if relatedTask is provided
895
+ if (options?.relatedTask) {
896
+ jsonrpcNotification = {
897
+ ...jsonrpcNotification,
898
+ params: {
899
+ ...jsonrpcNotification.params,
900
+ _meta: {
901
+ ...(jsonrpcNotification.params?._meta || {}),
902
+ [RELATED_TASK_META_KEY]: options.relatedTask
903
+ }
904
+ }
905
+ };
906
+ }
907
+ await this._transport.send(jsonrpcNotification, options);
908
+ }
909
+ /**
910
+ * Registers a handler to invoke when this protocol object receives a request with the given method.
911
+ *
912
+ * Note that this will replace any previous request handler for the same method.
913
+ */
914
+ setRequestHandler(requestSchema, handler) {
915
+ const method = getMethodLiteral(requestSchema);
916
+ this.assertRequestHandlerCapability(method);
917
+ this._requestHandlers.set(method, (request, extra) => {
918
+ const parsed = parseWithCompat(requestSchema, request);
919
+ return Promise.resolve(handler(parsed, extra));
920
+ });
921
+ }
922
+ /**
923
+ * Removes the request handler for the given method.
924
+ */
925
+ removeRequestHandler(method) {
926
+ this._requestHandlers.delete(method);
927
+ }
928
+ /**
929
+ * Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.
930
+ */
931
+ assertCanSetRequestHandler(method) {
932
+ if (this._requestHandlers.has(method)) {
933
+ throw new Error(`A request handler for ${method} already exists, which would be overridden`);
934
+ }
935
+ }
936
+ /**
937
+ * Registers a handler to invoke when this protocol object receives a notification with the given method.
938
+ *
939
+ * Note that this will replace any previous notification handler for the same method.
940
+ */
941
+ setNotificationHandler(notificationSchema, handler) {
942
+ const method = getMethodLiteral(notificationSchema);
943
+ this._notificationHandlers.set(method, notification => {
944
+ const parsed = parseWithCompat(notificationSchema, notification);
945
+ return Promise.resolve(handler(parsed));
946
+ });
947
+ }
948
+ /**
949
+ * Removes the notification handler for the given method.
950
+ */
951
+ removeNotificationHandler(method) {
952
+ this._notificationHandlers.delete(method);
953
+ }
954
+ /**
955
+ * Cleans up the progress handler associated with a task.
956
+ * This should be called when a task reaches a terminal status.
957
+ */
958
+ _cleanupTaskProgressHandler(taskId) {
959
+ const progressToken = this._taskProgressTokens.get(taskId);
960
+ if (progressToken !== undefined) {
961
+ this._progressHandlers.delete(progressToken);
962
+ this._taskProgressTokens.delete(taskId);
963
+ }
964
+ }
965
+ /**
966
+ * Enqueues a task-related message for side-channel delivery via tasks/result.
967
+ * @param taskId The task ID to associate the message with
968
+ * @param message The message to enqueue
969
+ * @param sessionId Optional session ID for binding the operation to a specific session
970
+ * @throws Error if taskStore is not configured or if enqueue fails (e.g., queue overflow)
971
+ *
972
+ * Note: If enqueue fails, it's the TaskMessageQueue implementation's responsibility to handle
973
+ * the error appropriately (e.g., by failing the task, logging, etc.). The Protocol layer
974
+ * simply propagates the error.
975
+ */
976
+ async _enqueueTaskMessage(taskId, message, sessionId) {
977
+ // Task message queues are only used when taskStore is configured
978
+ if (!this._taskStore || !this._taskMessageQueue) {
979
+ throw new Error('Cannot enqueue task message: taskStore and taskMessageQueue are not configured');
980
+ }
981
+ const maxQueueSize = this._options?.maxTaskQueueSize;
982
+ // Messages queued by local code carry the session of the current connection, like the ones queued for a request.
983
+ await this._taskMessageQueue.enqueue(taskId, message, sessionId ?? this._transport?.sessionId, maxQueueSize);
984
+ }
985
+ /**
986
+ * Clears the message queue for a task and rejects any pending request resolvers.
987
+ * @param taskId The task ID whose queue should be cleared
988
+ * @param sessionId Optional session ID for binding the operation to a specific session
989
+ */
990
+ async _clearTaskQueue(taskId, sessionId) {
991
+ if (this._taskMessageQueue) {
992
+ // Reject any pending request resolvers
993
+ const messages = await this._taskMessageQueue.dequeueAll(taskId, sessionId);
994
+ for (const message of messages) {
995
+ if (message.type === 'request' && isJSONRPCRequest(message.message)) {
996
+ // Extract request ID from the message
997
+ const requestId = message.message.id;
998
+ const resolver = this._requestResolvers.get(requestId);
999
+ if (resolver) {
1000
+ resolver(new McpError(ErrorCode.InternalError, 'Task cancelled or completed'));
1001
+ this._requestResolvers.delete(requestId);
1002
+ }
1003
+ else {
1004
+ // Log error when resolver is missing during cleanup for better observability
1005
+ this._onerror(new Error(`Resolver missing for request ${requestId} during task ${taskId} cleanup`));
1006
+ }
1007
+ }
1008
+ }
1009
+ }
1010
+ }
1011
+ /**
1012
+ * Waits for a task update (new messages or status change) with abort signal support.
1013
+ * Uses polling to check for updates at the task's configured poll interval.
1014
+ * @param taskId The task ID to wait for
1015
+ * @param signal Abort signal to cancel the wait
1016
+ * @param sessionId Session of the request that waits, passed to the task store
1017
+ * @returns Promise that resolves when an update occurs or rejects if aborted
1018
+ */
1019
+ async _waitForTaskUpdate(taskId, signal, sessionId) {
1020
+ // Get the task's poll interval, falling back to default
1021
+ let interval = this._options?.defaultTaskPollInterval ?? 1000;
1022
+ try {
1023
+ const task = await this._taskStore?.getTask(taskId, sessionId);
1024
+ if (task?.pollInterval) {
1025
+ interval = task.pollInterval;
1026
+ }
1027
+ }
1028
+ catch {
1029
+ // Use default interval if task lookup fails
1030
+ }
1031
+ return new Promise((resolve, reject) => {
1032
+ if (signal.aborted) {
1033
+ reject(new McpError(ErrorCode.InvalidRequest, 'Request cancelled'));
1034
+ return;
1035
+ }
1036
+ // Wait for the poll interval, then resolve so caller can check for updates
1037
+ const timeoutId = setTimeout(resolve, interval);
1038
+ // Clean up timeout and reject if aborted
1039
+ signal.addEventListener('abort', () => {
1040
+ clearTimeout(timeoutId);
1041
+ reject(new McpError(ErrorCode.InvalidRequest, 'Request cancelled'));
1042
+ }, { once: true });
1043
+ });
1044
+ }
1045
+ requestTaskStore(request, sessionId) {
1046
+ const taskStore = this._taskStore;
1047
+ if (!taskStore) {
1048
+ throw new Error('No task store configured');
1049
+ }
1050
+ return {
1051
+ createTask: async (taskParams) => {
1052
+ if (!request) {
1053
+ throw new Error('No request provided');
1054
+ }
1055
+ return await taskStore.createTask(taskParams, request.id, {
1056
+ method: request.method,
1057
+ params: request.params
1058
+ }, sessionId);
1059
+ },
1060
+ getTask: async (taskId) => {
1061
+ const task = await taskStore.getTask(taskId, sessionId);
1062
+ if (!task) {
1063
+ throw new McpError(ErrorCode.InvalidParams, 'Failed to retrieve task: Task not found');
1064
+ }
1065
+ return task;
1066
+ },
1067
+ storeTaskResult: async (taskId, status, result) => {
1068
+ await taskStore.storeTaskResult(taskId, status, result, sessionId);
1069
+ // Get updated task state and send notification
1070
+ const task = await taskStore.getTask(taskId, sessionId);
1071
+ if (task) {
1072
+ const notification = TaskStatusNotificationSchema.parse({
1073
+ method: 'notifications/tasks/status',
1074
+ params: task
1075
+ });
1076
+ await this.notification(notification);
1077
+ if (isTerminal(task.status)) {
1078
+ this._cleanupTaskProgressHandler(taskId);
1079
+ // Don't clear queue here - it will be cleared after delivery via tasks/result
1080
+ }
1081
+ }
1082
+ },
1083
+ getTaskResult: taskId => {
1084
+ return taskStore.getTaskResult(taskId, sessionId);
1085
+ },
1086
+ updateTaskStatus: async (taskId, status, statusMessage) => {
1087
+ // Check if task exists
1088
+ const task = await taskStore.getTask(taskId, sessionId);
1089
+ if (!task) {
1090
+ throw new McpError(ErrorCode.InvalidParams, `Task "${taskId}" not found - it may have been cleaned up`);
1091
+ }
1092
+ // Don't allow transitions from terminal states
1093
+ if (isTerminal(task.status)) {
1094
+ throw new McpError(ErrorCode.InvalidParams, `Cannot update task "${taskId}" from terminal status "${task.status}" to "${status}". Terminal states (completed, failed, cancelled) cannot transition to other states.`);
1095
+ }
1096
+ await taskStore.updateTaskStatus(taskId, status, statusMessage, sessionId);
1097
+ // Get updated task state and send notification
1098
+ const updatedTask = await taskStore.getTask(taskId, sessionId);
1099
+ if (updatedTask) {
1100
+ const notification = TaskStatusNotificationSchema.parse({
1101
+ method: 'notifications/tasks/status',
1102
+ params: updatedTask
1103
+ });
1104
+ await this.notification(notification);
1105
+ if (isTerminal(updatedTask.status)) {
1106
+ this._cleanupTaskProgressHandler(taskId);
1107
+ // Don't clear queue here - it will be cleared after delivery via tasks/result
1108
+ }
1109
+ }
1110
+ },
1111
+ listTasks: cursor => {
1112
+ return taskStore.listTasks(cursor, sessionId);
1113
+ }
1114
+ };
1115
+ }
1116
+ }
1117
+ function isPlainObject(value) {
1118
+ return value !== null && typeof value === 'object' && !Array.isArray(value);
1119
+ }
1120
+ export function mergeCapabilities(base, additional) {
1121
+ const result = { ...base };
1122
+ for (const key in additional) {
1123
+ const k = key;
1124
+ const addValue = additional[k];
1125
+ if (addValue === undefined)
1126
+ continue;
1127
+ const baseValue = result[k];
1128
+ if (isPlainObject(baseValue) && isPlainObject(addValue)) {
1129
+ result[k] = { ...baseValue, ...addValue };
1130
+ }
1131
+ else {
1132
+ result[k] = addValue;
1133
+ }
1134
+ }
1135
+ return result;
1136
+ }
1137
+ //# sourceMappingURL=protocol.js.map