outask 0.0.0-stage → 1.6.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 (831) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +47 -2
  3. package/bin/outask +7 -0
  4. package/bin/tasks +7 -0
  5. package/cli.mjs +151 -0
  6. package/mcp/package-lock.json +175 -0
  7. package/mcp/package.json +15 -0
  8. package/mcp/server.mjs +132 -0
  9. package/node_modules/@modelcontextprotocol/core/LICENSE +216 -0
  10. package/node_modules/@modelcontextprotocol/core/README.md +40 -0
  11. package/node_modules/@modelcontextprotocol/core/dist/auth-Anm-lwWi.d.mts +8507 -0
  12. package/node_modules/@modelcontextprotocol/core/dist/auth-Anm-lwWi.d.mts.map +1 -0
  13. package/node_modules/@modelcontextprotocol/core/dist/auth-BNDyLTqp.mjs +1681 -0
  14. package/node_modules/@modelcontextprotocol/core/dist/auth-BNDyLTqp.mjs.map +1 -0
  15. package/node_modules/@modelcontextprotocol/core/dist/auth-D1CeV_Jr.cjs +2902 -0
  16. package/node_modules/@modelcontextprotocol/core/dist/auth-D1CeV_Jr.cjs.map +1 -0
  17. package/node_modules/@modelcontextprotocol/core/dist/auth-V9XJSCfa.d.cts +8507 -0
  18. package/node_modules/@modelcontextprotocol/core/dist/auth-V9XJSCfa.d.cts.map +1 -0
  19. package/node_modules/@modelcontextprotocol/core/dist/index.cjs +175 -0
  20. package/node_modules/@modelcontextprotocol/core/dist/index.d.cts +2 -0
  21. package/node_modules/@modelcontextprotocol/core/dist/index.d.mts +2 -0
  22. package/node_modules/@modelcontextprotocol/core/dist/index.mjs +3 -0
  23. package/node_modules/@modelcontextprotocol/core/dist/internal.cjs +201 -0
  24. package/node_modules/@modelcontextprotocol/core/dist/internal.d.cts +99 -0
  25. package/node_modules/@modelcontextprotocol/core/dist/internal.d.cts.map +1 -0
  26. package/node_modules/@modelcontextprotocol/core/dist/internal.d.mts +99 -0
  27. package/node_modules/@modelcontextprotocol/core/dist/internal.d.mts.map +1 -0
  28. package/node_modules/@modelcontextprotocol/core/dist/internal.mjs +3 -0
  29. package/node_modules/@modelcontextprotocol/core/package.json +85 -0
  30. package/node_modules/@modelcontextprotocol/server/LICENSE +216 -0
  31. package/node_modules/@modelcontextprotocol/server/README.md +30 -0
  32. package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-CEoC__sr.mjs +7514 -0
  33. package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-CEoC__sr.mjs.map +1 -0
  34. package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-CgI-5L6O.d.mts +1071 -0
  35. package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-CgI-5L6O.d.mts.map +1 -0
  36. package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-FOQRM7up.d.cts +1071 -0
  37. package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-FOQRM7up.d.cts.map +1 -0
  38. package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-ZaoO9afR.cjs +7531 -0
  39. package/node_modules/@modelcontextprotocol/server/dist/ajvProvider-ZaoO9afR.cjs.map +1 -0
  40. package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-BwbPzsdI.cjs +986 -0
  41. package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-BwbPzsdI.cjs.map +1 -0
  42. package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-C03CSigr.d.mts +74 -0
  43. package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-C03CSigr.d.mts.map +1 -0
  44. package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-doTkZbTr.d.cts +74 -0
  45. package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-doTkZbTr.d.cts.map +1 -0
  46. package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-p3WaZPqB.mjs +981 -0
  47. package/node_modules/@modelcontextprotocol/server/dist/cfWorkerProvider-p3WaZPqB.mjs.map +1 -0
  48. package/node_modules/@modelcontextprotocol/server/dist/chunk-Bnu9O96Y.cjs +60 -0
  49. package/node_modules/@modelcontextprotocol/server/dist/chunk-Br0eD_fh.mjs +42 -0
  50. package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-D4NN8WsG.d.mts +4168 -0
  51. package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-D4NN8WsG.d.mts.map +1 -0
  52. package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-DZmmlN8e.d.cts +4170 -0
  53. package/node_modules/@modelcontextprotocol/server/dist/createMcpHandler-DZmmlN8e.d.cts.map +1 -0
  54. package/node_modules/@modelcontextprotocol/server/dist/dialects-D8eXzoGv.cjs +46 -0
  55. package/node_modules/@modelcontextprotocol/server/dist/dialects-D8eXzoGv.cjs.map +1 -0
  56. package/node_modules/@modelcontextprotocol/server/dist/dialects-DoSzNhcb.mjs +34 -0
  57. package/node_modules/@modelcontextprotocol/server/dist/dialects-DoSzNhcb.mjs.map +1 -0
  58. package/node_modules/@modelcontextprotocol/server/dist/index.cjs +1978 -0
  59. package/node_modules/@modelcontextprotocol/server/dist/index.cjs.map +1 -0
  60. package/node_modules/@modelcontextprotocol/server/dist/index.d.cts +810 -0
  61. package/node_modules/@modelcontextprotocol/server/dist/index.d.cts.map +1 -0
  62. package/node_modules/@modelcontextprotocol/server/dist/index.d.mts +810 -0
  63. package/node_modules/@modelcontextprotocol/server/dist/index.d.mts.map +1 -0
  64. package/node_modules/@modelcontextprotocol/server/dist/index.mjs +1790 -0
  65. package/node_modules/@modelcontextprotocol/server/dist/index.mjs.map +1 -0
  66. package/node_modules/@modelcontextprotocol/server/dist/mcp-BumlNux0.cjs +2477 -0
  67. package/node_modules/@modelcontextprotocol/server/dist/mcp-BumlNux0.cjs.map +1 -0
  68. package/node_modules/@modelcontextprotocol/server/dist/mcp-DIH4cS6P.mjs +2326 -0
  69. package/node_modules/@modelcontextprotocol/server/dist/mcp-DIH4cS6P.mjs.map +1 -0
  70. package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.cjs +23 -0
  71. package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.cjs.map +1 -0
  72. package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.d.cts +11 -0
  73. package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.d.cts.map +1 -0
  74. package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.d.mts +11 -0
  75. package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.d.mts.map +1 -0
  76. package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.mjs +22 -0
  77. package/node_modules/@modelcontextprotocol/server/dist/shimsBrowser.mjs.map +1 -0
  78. package/node_modules/@modelcontextprotocol/server/dist/shimsNode.cjs +12 -0
  79. package/node_modules/@modelcontextprotocol/server/dist/shimsNode.d.cts +3 -0
  80. package/node_modules/@modelcontextprotocol/server/dist/shimsNode.d.mts +3 -0
  81. package/node_modules/@modelcontextprotocol/server/dist/shimsNode.mjs +4 -0
  82. package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.cjs +30 -0
  83. package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.cjs.map +1 -0
  84. package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.d.cts +10 -0
  85. package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.d.cts.map +1 -0
  86. package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.d.mts +10 -0
  87. package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.d.mts.map +1 -0
  88. package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.mjs +29 -0
  89. package/node_modules/@modelcontextprotocol/server/dist/shimsWorkerd.mjs.map +1 -0
  90. package/node_modules/@modelcontextprotocol/server/dist/src-BhnGYybN.cjs +8200 -0
  91. package/node_modules/@modelcontextprotocol/server/dist/src-BhnGYybN.cjs.map +1 -0
  92. package/node_modules/@modelcontextprotocol/server/dist/src-Cqbh3MYc.mjs +7702 -0
  93. package/node_modules/@modelcontextprotocol/server/dist/src-Cqbh3MYc.mjs.map +1 -0
  94. package/node_modules/@modelcontextprotocol/server/dist/stdio.cjs +591 -0
  95. package/node_modules/@modelcontextprotocol/server/dist/stdio.cjs.map +1 -0
  96. package/node_modules/@modelcontextprotocol/server/dist/stdio.d.cts +115 -0
  97. package/node_modules/@modelcontextprotocol/server/dist/stdio.d.cts.map +1 -0
  98. package/node_modules/@modelcontextprotocol/server/dist/stdio.d.mts +115 -0
  99. package/node_modules/@modelcontextprotocol/server/dist/stdio.d.mts.map +1 -0
  100. package/node_modules/@modelcontextprotocol/server/dist/stdio.mjs +589 -0
  101. package/node_modules/@modelcontextprotocol/server/dist/stdio.mjs.map +1 -0
  102. package/node_modules/@modelcontextprotocol/server/dist/types-DUs7mGBv.d.mts +1099 -0
  103. package/node_modules/@modelcontextprotocol/server/dist/types-DUs7mGBv.d.mts.map +1 -0
  104. package/node_modules/@modelcontextprotocol/server/dist/types-DsbMXNFL.d.cts +1099 -0
  105. package/node_modules/@modelcontextprotocol/server/dist/types-DsbMXNFL.d.cts.map +1 -0
  106. package/node_modules/@modelcontextprotocol/server/dist/validators/ajv.cjs +5 -0
  107. package/node_modules/@modelcontextprotocol/server/dist/validators/ajv.d.cts +2 -0
  108. package/node_modules/@modelcontextprotocol/server/dist/validators/ajv.d.mts +2 -0
  109. package/node_modules/@modelcontextprotocol/server/dist/validators/ajv.mjs +3 -0
  110. package/node_modules/@modelcontextprotocol/server/dist/validators/cfWorker.cjs +3 -0
  111. package/node_modules/@modelcontextprotocol/server/dist/validators/cfWorker.d.cts +2 -0
  112. package/node_modules/@modelcontextprotocol/server/dist/validators/cfWorker.d.mts +2 -0
  113. package/node_modules/@modelcontextprotocol/server/dist/validators/cfWorker.mjs +3 -0
  114. package/node_modules/@modelcontextprotocol/server/package.json +160 -0
  115. package/node_modules/jsonc-parser/CHANGELOG.md +76 -0
  116. package/node_modules/jsonc-parser/LICENSE.md +21 -0
  117. package/node_modules/jsonc-parser/README.md +364 -0
  118. package/node_modules/jsonc-parser/SECURITY.md +41 -0
  119. package/node_modules/jsonc-parser/lib/esm/impl/edit.js +185 -0
  120. package/node_modules/jsonc-parser/lib/esm/impl/format.js +261 -0
  121. package/node_modules/jsonc-parser/lib/esm/impl/parser.js +659 -0
  122. package/node_modules/jsonc-parser/lib/esm/impl/scanner.js +443 -0
  123. package/node_modules/jsonc-parser/lib/esm/impl/string-intern.js +29 -0
  124. package/node_modules/jsonc-parser/lib/esm/main.d.ts +351 -0
  125. package/node_modules/jsonc-parser/lib/esm/main.js +178 -0
  126. package/node_modules/jsonc-parser/lib/umd/impl/edit.js +201 -0
  127. package/node_modules/jsonc-parser/lib/umd/impl/format.js +275 -0
  128. package/node_modules/jsonc-parser/lib/umd/impl/parser.js +682 -0
  129. package/node_modules/jsonc-parser/lib/umd/impl/scanner.js +456 -0
  130. package/node_modules/jsonc-parser/lib/umd/impl/string-intern.js +42 -0
  131. package/node_modules/jsonc-parser/lib/umd/main.d.ts +351 -0
  132. package/node_modules/jsonc-parser/lib/umd/main.js +194 -0
  133. package/node_modules/jsonc-parser/package.json +37 -0
  134. package/node_modules/zod/LICENSE +21 -0
  135. package/node_modules/zod/README.md +218 -0
  136. package/node_modules/zod/compile.cjs +96 -0
  137. package/node_modules/zod/compile.d.cts +1 -0
  138. package/node_modules/zod/compile.d.ts +1 -0
  139. package/node_modules/zod/compile.js +52 -0
  140. package/node_modules/zod/index.cjs +52 -0
  141. package/node_modules/zod/index.d.cts +3 -0
  142. package/node_modules/zod/index.d.ts +3 -0
  143. package/node_modules/zod/index.js +7 -0
  144. package/node_modules/zod/locales/index.cjs +36 -0
  145. package/node_modules/zod/locales/index.d.cts +1 -0
  146. package/node_modules/zod/locales/index.d.ts +1 -0
  147. package/node_modules/zod/locales/index.js +1 -0
  148. package/node_modules/zod/locales/package.json +7 -0
  149. package/node_modules/zod/mini/index.cjs +51 -0
  150. package/node_modules/zod/mini/index.d.cts +3 -0
  151. package/node_modules/zod/mini/index.d.ts +3 -0
  152. package/node_modules/zod/mini/index.js +3 -0
  153. package/node_modules/zod/mini/package.json +7 -0
  154. package/node_modules/zod/package.json +147 -0
  155. package/node_modules/zod/src/compile.ts +56 -0
  156. package/node_modules/zod/src/index.ts +7 -0
  157. package/node_modules/zod/src/locales/index.ts +1 -0
  158. package/node_modules/zod/src/mini/index.ts +3 -0
  159. package/node_modules/zod/src/v3/ZodError.ts +340 -0
  160. package/node_modules/zod/src/v3/benchmarks/datetime.ts +58 -0
  161. package/node_modules/zod/src/v3/benchmarks/discriminatedUnion.ts +80 -0
  162. package/node_modules/zod/src/v3/benchmarks/index.ts +59 -0
  163. package/node_modules/zod/src/v3/benchmarks/ipv4.ts +57 -0
  164. package/node_modules/zod/src/v3/benchmarks/object.ts +69 -0
  165. package/node_modules/zod/src/v3/benchmarks/primitives.ts +162 -0
  166. package/node_modules/zod/src/v3/benchmarks/realworld.ts +63 -0
  167. package/node_modules/zod/src/v3/benchmarks/string.ts +55 -0
  168. package/node_modules/zod/src/v3/benchmarks/union.ts +80 -0
  169. package/node_modules/zod/src/v3/errors.ts +13 -0
  170. package/node_modules/zod/src/v3/external.ts +6 -0
  171. package/node_modules/zod/src/v3/helpers/enumUtil.ts +17 -0
  172. package/node_modules/zod/src/v3/helpers/errorUtil.ts +8 -0
  173. package/node_modules/zod/src/v3/helpers/parseUtil.ts +176 -0
  174. package/node_modules/zod/src/v3/helpers/partialUtil.ts +34 -0
  175. package/node_modules/zod/src/v3/helpers/typeAliases.ts +2 -0
  176. package/node_modules/zod/src/v3/helpers/util.ts +224 -0
  177. package/node_modules/zod/src/v3/index.ts +4 -0
  178. package/node_modules/zod/src/v3/locales/en.ts +124 -0
  179. package/node_modules/zod/src/v3/standard-schema.ts +113 -0
  180. package/node_modules/zod/src/v3/types.ts +5138 -0
  181. package/node_modules/zod/src/v4/classic/checks.ts +33 -0
  182. package/node_modules/zod/src/v4/classic/coerce.ts +27 -0
  183. package/node_modules/zod/src/v4/classic/compat.ts +78 -0
  184. package/node_modules/zod/src/v4/classic/deep-partial.ts +76 -0
  185. package/node_modules/zod/src/v4/classic/errors.ts +97 -0
  186. package/node_modules/zod/src/v4/classic/external.ts +57 -0
  187. package/node_modules/zod/src/v4/classic/from-json-schema.ts +944 -0
  188. package/node_modules/zod/src/v4/classic/in-out.ts +45 -0
  189. package/node_modules/zod/src/v4/classic/index.ts +5 -0
  190. package/node_modules/zod/src/v4/classic/iso.ts +20 -0
  191. package/node_modules/zod/src/v4/classic/parse.ts +88 -0
  192. package/node_modules/zod/src/v4/classic/schemas.ts +2937 -0
  193. package/node_modules/zod/src/v4/core/api.ts +1875 -0
  194. package/node_modules/zod/src/v4/core/checks.ts +1266 -0
  195. package/node_modules/zod/src/v4/core/compile.ts +2322 -0
  196. package/node_modules/zod/src/v4/core/core.ts +230 -0
  197. package/node_modules/zod/src/v4/core/doc.ts +52 -0
  198. package/node_modules/zod/src/v4/core/errors.ts +543 -0
  199. package/node_modules/zod/src/v4/core/index.ts +19 -0
  200. package/node_modules/zod/src/v4/core/json-schema-generator.ts +131 -0
  201. package/node_modules/zod/src/v4/core/json-schema-processors.ts +934 -0
  202. package/node_modules/zod/src/v4/core/json-schema.ts +148 -0
  203. package/node_modules/zod/src/v4/core/memoizer.ts +331 -0
  204. package/node_modules/zod/src/v4/core/parse.ts +309 -0
  205. package/node_modules/zod/src/v4/core/regexes.ts +217 -0
  206. package/node_modules/zod/src/v4/core/registries.ts +105 -0
  207. package/node_modules/zod/src/v4/core/schemas.ts +5226 -0
  208. package/node_modules/zod/src/v4/core/standard-schema.ts +159 -0
  209. package/node_modules/zod/src/v4/core/to-json-schema.ts +857 -0
  210. package/node_modules/zod/src/v4/core/util.ts +1293 -0
  211. package/node_modules/zod/src/v4/core/versions.ts +5 -0
  212. package/node_modules/zod/src/v4/core/visit.ts +193 -0
  213. package/node_modules/zod/src/v4/core/zsf.ts +323 -0
  214. package/node_modules/zod/src/v4/index.ts +4 -0
  215. package/node_modules/zod/src/v4/locales/ar.ts +120 -0
  216. package/node_modules/zod/src/v4/locales/az.ts +116 -0
  217. package/node_modules/zod/src/v4/locales/be.ts +188 -0
  218. package/node_modules/zod/src/v4/locales/bg.ts +133 -0
  219. package/node_modules/zod/src/v4/locales/bn.ts +123 -0
  220. package/node_modules/zod/src/v4/locales/ca.ts +121 -0
  221. package/node_modules/zod/src/v4/locales/ckb.ts +140 -0
  222. package/node_modules/zod/src/v4/locales/cs.ts +123 -0
  223. package/node_modules/zod/src/v4/locales/da.ts +128 -0
  224. package/node_modules/zod/src/v4/locales/de.ts +121 -0
  225. package/node_modules/zod/src/v4/locales/el.ts +124 -0
  226. package/node_modules/zod/src/v4/locales/en.ts +136 -0
  227. package/node_modules/zod/src/v4/locales/eo.ts +123 -0
  228. package/node_modules/zod/src/v4/locales/es.ts +145 -0
  229. package/node_modules/zod/src/v4/locales/fa.ts +131 -0
  230. package/node_modules/zod/src/v4/locales/fi.ts +126 -0
  231. package/node_modules/zod/src/v4/locales/fr-CA.ts +121 -0
  232. package/node_modules/zod/src/v4/locales/fr.ts +139 -0
  233. package/node_modules/zod/src/v4/locales/gu.ts +123 -0
  234. package/node_modules/zod/src/v4/locales/he.ts +253 -0
  235. package/node_modules/zod/src/v4/locales/hi.ts +126 -0
  236. package/node_modules/zod/src/v4/locales/hr.ts +135 -0
  237. package/node_modules/zod/src/v4/locales/hu.ts +122 -0
  238. package/node_modules/zod/src/v4/locales/hy.ts +175 -0
  239. package/node_modules/zod/src/v4/locales/id.ts +120 -0
  240. package/node_modules/zod/src/v4/locales/index.ts +63 -0
  241. package/node_modules/zod/src/v4/locales/is.ts +124 -0
  242. package/node_modules/zod/src/v4/locales/it.ts +121 -0
  243. package/node_modules/zod/src/v4/locales/ja.ts +119 -0
  244. package/node_modules/zod/src/v4/locales/ka.ts +128 -0
  245. package/node_modules/zod/src/v4/locales/kh.ts +7 -0
  246. package/node_modules/zod/src/v4/locales/km.ts +124 -0
  247. package/node_modules/zod/src/v4/locales/kn.ts +126 -0
  248. package/node_modules/zod/src/v4/locales/ko.ts +126 -0
  249. package/node_modules/zod/src/v4/locales/lt.ts +243 -0
  250. package/node_modules/zod/src/v4/locales/mk.ts +123 -0
  251. package/node_modules/zod/src/v4/locales/ms.ts +120 -0
  252. package/node_modules/zod/src/v4/locales/ne.ts +128 -0
  253. package/node_modules/zod/src/v4/locales/nl.ts +126 -0
  254. package/node_modules/zod/src/v4/locales/nn.ts +121 -0
  255. package/node_modules/zod/src/v4/locales/no.ts +121 -0
  256. package/node_modules/zod/src/v4/locales/ota.ts +122 -0
  257. package/node_modules/zod/src/v4/locales/pl.ts +123 -0
  258. package/node_modules/zod/src/v4/locales/ps.ts +131 -0
  259. package/node_modules/zod/src/v4/locales/pt-BR.ts +161 -0
  260. package/node_modules/zod/src/v4/locales/pt.ts +159 -0
  261. package/node_modules/zod/src/v4/locales/ro.ts +132 -0
  262. package/node_modules/zod/src/v4/locales/ru.ts +188 -0
  263. package/node_modules/zod/src/v4/locales/sk.ts +123 -0
  264. package/node_modules/zod/src/v4/locales/sl.ts +123 -0
  265. package/node_modules/zod/src/v4/locales/sv.ts +124 -0
  266. package/node_modules/zod/src/v4/locales/ta.ts +123 -0
  267. package/node_modules/zod/src/v4/locales/tg.ts +135 -0
  268. package/node_modules/zod/src/v4/locales/th.ts +124 -0
  269. package/node_modules/zod/src/v4/locales/tk.ts +113 -0
  270. package/node_modules/zod/src/v4/locales/tr.ts +116 -0
  271. package/node_modules/zod/src/v4/locales/ua.ts +7 -0
  272. package/node_modules/zod/src/v4/locales/uk.ts +122 -0
  273. package/node_modules/zod/src/v4/locales/ur.ts +124 -0
  274. package/node_modules/zod/src/v4/locales/uz.ts +120 -0
  275. package/node_modules/zod/src/v4/locales/vi.ts +122 -0
  276. package/node_modules/zod/src/v4/locales/yo.ts +129 -0
  277. package/node_modules/zod/src/v4/locales/zh-CN.ts +121 -0
  278. package/node_modules/zod/src/v4/locales/zh-TW.ts +120 -0
  279. package/node_modules/zod/src/v4/mini/checks.ts +33 -0
  280. package/node_modules/zod/src/v4/mini/coerce.ts +27 -0
  281. package/node_modules/zod/src/v4/mini/deep-partial.ts +73 -0
  282. package/node_modules/zod/src/v4/mini/external.ts +52 -0
  283. package/node_modules/zod/src/v4/mini/in-out.ts +45 -0
  284. package/node_modules/zod/src/v4/mini/index.ts +3 -0
  285. package/node_modules/zod/src/v4/mini/iso.ts +66 -0
  286. package/node_modules/zod/src/v4/mini/parse.ts +16 -0
  287. package/node_modules/zod/src/v4/mini/schemas.ts +2051 -0
  288. package/node_modules/zod/src/v4-mini/index.ts +3 -0
  289. package/node_modules/zod/v3/ZodError.cjs +167 -0
  290. package/node_modules/zod/v3/ZodError.d.cts +164 -0
  291. package/node_modules/zod/v3/ZodError.d.ts +164 -0
  292. package/node_modules/zod/v3/ZodError.js +143 -0
  293. package/node_modules/zod/v3/errors.cjs +36 -0
  294. package/node_modules/zod/v3/errors.d.cts +5 -0
  295. package/node_modules/zod/v3/errors.d.ts +5 -0
  296. package/node_modules/zod/v3/errors.js +9 -0
  297. package/node_modules/zod/v3/external.cjs +41 -0
  298. package/node_modules/zod/v3/external.d.cts +6 -0
  299. package/node_modules/zod/v3/external.d.ts +6 -0
  300. package/node_modules/zod/v3/external.js +6 -0
  301. package/node_modules/zod/v3/helpers/enumUtil.cjs +21 -0
  302. package/node_modules/zod/v3/helpers/enumUtil.d.cts +8 -0
  303. package/node_modules/zod/v3/helpers/enumUtil.d.ts +8 -0
  304. package/node_modules/zod/v3/helpers/enumUtil.js +1 -0
  305. package/node_modules/zod/v3/helpers/errorUtil.cjs +28 -0
  306. package/node_modules/zod/v3/helpers/errorUtil.d.cts +9 -0
  307. package/node_modules/zod/v3/helpers/errorUtil.d.ts +9 -0
  308. package/node_modules/zod/v3/helpers/errorUtil.js +6 -0
  309. package/node_modules/zod/v3/helpers/parseUtil.cjs +143 -0
  310. package/node_modules/zod/v3/helpers/parseUtil.d.cts +78 -0
  311. package/node_modules/zod/v3/helpers/parseUtil.d.ts +78 -0
  312. package/node_modules/zod/v3/helpers/parseUtil.js +109 -0
  313. package/node_modules/zod/v3/helpers/partialUtil.cjs +21 -0
  314. package/node_modules/zod/v3/helpers/partialUtil.d.cts +8 -0
  315. package/node_modules/zod/v3/helpers/partialUtil.d.ts +8 -0
  316. package/node_modules/zod/v3/helpers/partialUtil.js +1 -0
  317. package/node_modules/zod/v3/helpers/typeAliases.cjs +21 -0
  318. package/node_modules/zod/v3/helpers/typeAliases.d.cts +2 -0
  319. package/node_modules/zod/v3/helpers/typeAliases.d.ts +2 -0
  320. package/node_modules/zod/v3/helpers/typeAliases.js +1 -0
  321. package/node_modules/zod/v3/helpers/util.cjs +156 -0
  322. package/node_modules/zod/v3/helpers/util.d.cts +85 -0
  323. package/node_modules/zod/v3/helpers/util.d.ts +85 -0
  324. package/node_modules/zod/v3/helpers/util.js +133 -0
  325. package/node_modules/zod/v3/index.cjs +52 -0
  326. package/node_modules/zod/v3/index.d.cts +4 -0
  327. package/node_modules/zod/v3/index.d.ts +4 -0
  328. package/node_modules/zod/v3/index.js +4 -0
  329. package/node_modules/zod/v3/locales/en.cjs +112 -0
  330. package/node_modules/zod/v3/locales/en.d.cts +3 -0
  331. package/node_modules/zod/v3/locales/en.d.ts +3 -0
  332. package/node_modules/zod/v3/locales/en.js +109 -0
  333. package/node_modules/zod/v3/package.json +7 -0
  334. package/node_modules/zod/v3/standard-schema.cjs +21 -0
  335. package/node_modules/zod/v3/standard-schema.d.cts +102 -0
  336. package/node_modules/zod/v3/standard-schema.d.ts +102 -0
  337. package/node_modules/zod/v3/standard-schema.js +1 -0
  338. package/node_modules/zod/v3/types.cjs +3798 -0
  339. package/node_modules/zod/v3/types.d.cts +1034 -0
  340. package/node_modules/zod/v3/types.d.ts +1034 -0
  341. package/node_modules/zod/v3/types.js +3697 -0
  342. package/node_modules/zod/v4/classic/checks.cjs +53 -0
  343. package/node_modules/zod/v4/classic/checks.d.cts +1 -0
  344. package/node_modules/zod/v4/classic/checks.d.ts +1 -0
  345. package/node_modules/zod/v4/classic/checks.js +1 -0
  346. package/node_modules/zod/v4/classic/coerce.cjs +66 -0
  347. package/node_modules/zod/v4/classic/coerce.d.cts +17 -0
  348. package/node_modules/zod/v4/classic/coerce.d.ts +17 -0
  349. package/node_modules/zod/v4/classic/coerce.js +17 -0
  350. package/node_modules/zod/v4/classic/compat.cjs +80 -0
  351. package/node_modules/zod/v4/classic/compat.d.cts +48 -0
  352. package/node_modules/zod/v4/classic/compat.d.ts +48 -0
  353. package/node_modules/zod/v4/classic/compat.js +31 -0
  354. package/node_modules/zod/v4/classic/deep-partial.cjs +58 -0
  355. package/node_modules/zod/v4/classic/deep-partial.d.cts +14 -0
  356. package/node_modules/zod/v4/classic/deep-partial.d.ts +14 -0
  357. package/node_modules/zod/v4/classic/deep-partial.js +13 -0
  358. package/node_modules/zod/v4/classic/errors.cjs +102 -0
  359. package/node_modules/zod/v4/classic/errors.d.cts +29 -0
  360. package/node_modules/zod/v4/classic/errors.d.ts +29 -0
  361. package/node_modules/zod/v4/classic/errors.js +57 -0
  362. package/node_modules/zod/v4/classic/external.cjs +97 -0
  363. package/node_modules/zod/v4/classic/external.d.cts +19 -0
  364. package/node_modules/zod/v4/classic/external.d.ts +19 -0
  365. package/node_modules/zod/v4/classic/external.js +17 -0
  366. package/node_modules/zod/v4/classic/from-json-schema.cjs +926 -0
  367. package/node_modules/zod/v4/classic/from-json-schema.d.cts +12 -0
  368. package/node_modules/zod/v4/classic/from-json-schema.d.ts +12 -0
  369. package/node_modules/zod/v4/classic/from-json-schema.js +881 -0
  370. package/node_modules/zod/v4/classic/in-out.cjs +82 -0
  371. package/node_modules/zod/v4/classic/in-out.d.cts +8 -0
  372. package/node_modules/zod/v4/classic/in-out.d.ts +8 -0
  373. package/node_modules/zod/v4/classic/in-out.js +36 -0
  374. package/node_modules/zod/v4/classic/index.cjs +52 -0
  375. package/node_modules/zod/v4/classic/index.d.cts +3 -0
  376. package/node_modules/zod/v4/classic/index.d.ts +3 -0
  377. package/node_modules/zod/v4/classic/index.js +4 -0
  378. package/node_modules/zod/v4/classic/iso.cjs +68 -0
  379. package/node_modules/zod/v4/classic/iso.d.cts +7 -0
  380. package/node_modules/zod/v4/classic/iso.d.ts +7 -0
  381. package/node_modules/zod/v4/classic/iso.js +15 -0
  382. package/node_modules/zod/v4/classic/package.json +7 -0
  383. package/node_modules/zod/v4/classic/parse.cjs +63 -0
  384. package/node_modules/zod/v4/classic/parse.d.cts +44 -0
  385. package/node_modules/zod/v4/classic/parse.d.ts +44 -0
  386. package/node_modules/zod/v4/classic/parse.js +16 -0
  387. package/node_modules/zod/v4/classic/schemas.cjs +1676 -0
  388. package/node_modules/zod/v4/classic/schemas.d.cts +816 -0
  389. package/node_modules/zod/v4/classic/schemas.d.ts +816 -0
  390. package/node_modules/zod/v4/classic/schemas.js +1535 -0
  391. package/node_modules/zod/v4/core/api.cjs +1269 -0
  392. package/node_modules/zod/v4/core/api.d.cts +335 -0
  393. package/node_modules/zod/v4/core/api.d.ts +335 -0
  394. package/node_modules/zod/v4/core/api.js +1107 -0
  395. package/node_modules/zod/v4/core/checks.cjs +561 -0
  396. package/node_modules/zod/v4/core/checks.d.cts +294 -0
  397. package/node_modules/zod/v4/core/checks.d.ts +294 -0
  398. package/node_modules/zod/v4/core/checks.js +516 -0
  399. package/node_modules/zod/v4/core/compile.cjs +1916 -0
  400. package/node_modules/zod/v4/core/compile.d.cts +65 -0
  401. package/node_modules/zod/v4/core/compile.d.ts +65 -0
  402. package/node_modules/zod/v4/core/compile.js +1866 -0
  403. package/node_modules/zod/v4/core/core.cjs +167 -0
  404. package/node_modules/zod/v4/core/core.d.cts +82 -0
  405. package/node_modules/zod/v4/core/core.d.ts +82 -0
  406. package/node_modules/zod/v4/core/core.js +141 -0
  407. package/node_modules/zod/v4/core/doc.cjs +61 -0
  408. package/node_modules/zod/v4/core/doc.d.cts +16 -0
  409. package/node_modules/zod/v4/core/doc.d.ts +16 -0
  410. package/node_modules/zod/v4/core/doc.js +38 -0
  411. package/node_modules/zod/v4/core/errors.cjs +317 -0
  412. package/node_modules/zod/v4/core/errors.d.cts +225 -0
  413. package/node_modules/zod/v4/core/errors.d.ts +225 -0
  414. package/node_modules/zod/v4/core/errors.js +267 -0
  415. package/node_modules/zod/v4/core/index.cjs +70 -0
  416. package/node_modules/zod/v4/core/index.d.cts +19 -0
  417. package/node_modules/zod/v4/core/index.d.ts +19 -0
  418. package/node_modules/zod/v4/core/index.js +19 -0
  419. package/node_modules/zod/v4/core/json-schema-generator.cjs +122 -0
  420. package/node_modules/zod/v4/core/json-schema-generator.d.cts +65 -0
  421. package/node_modules/zod/v4/core/json-schema-generator.d.ts +65 -0
  422. package/node_modules/zod/v4/core/json-schema-generator.js +99 -0
  423. package/node_modules/zod/v4/core/json-schema-processors.cjs +929 -0
  424. package/node_modules/zod/v4/core/json-schema-processors.d.cts +65 -0
  425. package/node_modules/zod/v4/core/json-schema-processors.d.ts +65 -0
  426. package/node_modules/zod/v4/core/json-schema-processors.js +843 -0
  427. package/node_modules/zod/v4/core/json-schema.cjs +21 -0
  428. package/node_modules/zod/v4/core/json-schema.d.cts +89 -0
  429. package/node_modules/zod/v4/core/json-schema.d.ts +89 -0
  430. package/node_modules/zod/v4/core/json-schema.js +1 -0
  431. package/node_modules/zod/v4/core/memoizer.cjs +360 -0
  432. package/node_modules/zod/v4/core/memoizer.d.cts +15 -0
  433. package/node_modules/zod/v4/core/memoizer.d.ts +15 -0
  434. package/node_modules/zod/v4/core/memoizer.js +311 -0
  435. package/node_modules/zod/v4/core/package.json +7 -0
  436. package/node_modules/zod/v4/core/parse.cjs +233 -0
  437. package/node_modules/zod/v4/core/parse.d.cts +52 -0
  438. package/node_modules/zod/v4/core/parse.d.ts +52 -0
  439. package/node_modules/zod/v4/core/parse.js +175 -0
  440. package/node_modules/zod/v4/core/regexes.cjs +209 -0
  441. package/node_modules/zod/v4/core/regexes.d.cts +90 -0
  442. package/node_modules/zod/v4/core/regexes.d.ts +90 -0
  443. package/node_modules/zod/v4/core/regexes.js +156 -0
  444. package/node_modules/zod/v4/core/registries.cjs +75 -0
  445. package/node_modules/zod/v4/core/registries.d.cts +35 -0
  446. package/node_modules/zod/v4/core/registries.d.ts +35 -0
  447. package/node_modules/zod/v4/core/registries.js +51 -0
  448. package/node_modules/zod/v4/core/schemas.cjs +2699 -0
  449. package/node_modules/zod/v4/core/schemas.d.cts +1275 -0
  450. package/node_modules/zod/v4/core/schemas.d.ts +1275 -0
  451. package/node_modules/zod/v4/core/schemas.js +2636 -0
  452. package/node_modules/zod/v4/core/standard-schema.cjs +21 -0
  453. package/node_modules/zod/v4/core/standard-schema.d.cts +126 -0
  454. package/node_modules/zod/v4/core/standard-schema.d.ts +126 -0
  455. package/node_modules/zod/v4/core/standard-schema.js +1 -0
  456. package/node_modules/zod/v4/core/to-json-schema.cjs +681 -0
  457. package/node_modules/zod/v4/core/to-json-schema.d.cts +154 -0
  458. package/node_modules/zod/v4/core/to-json-schema.d.ts +154 -0
  459. package/node_modules/zod/v4/core/to-json-schema.js +651 -0
  460. package/node_modules/zod/v4/core/util.cjs +964 -0
  461. package/node_modules/zod/v4/core/util.d.cts +280 -0
  462. package/node_modules/zod/v4/core/util.d.ts +280 -0
  463. package/node_modules/zod/v4/core/util.js +873 -0
  464. package/node_modules/zod/v4/core/versions.cjs +27 -0
  465. package/node_modules/zod/v4/core/versions.d.cts +5 -0
  466. package/node_modules/zod/v4/core/versions.d.ts +5 -0
  467. package/node_modules/zod/v4/core/versions.js +5 -0
  468. package/node_modules/zod/v4/core/visit.cjs +214 -0
  469. package/node_modules/zod/v4/core/visit.d.cts +30 -0
  470. package/node_modules/zod/v4/core/visit.d.ts +30 -0
  471. package/node_modules/zod/v4/core/visit.js +169 -0
  472. package/node_modules/zod/v4/index.cjs +51 -0
  473. package/node_modules/zod/v4/index.d.cts +3 -0
  474. package/node_modules/zod/v4/index.d.ts +3 -0
  475. package/node_modules/zod/v4/index.js +4 -0
  476. package/node_modules/zod/v4/locales/ar.cjs +138 -0
  477. package/node_modules/zod/v4/locales/ar.d.cts +5 -0
  478. package/node_modules/zod/v4/locales/ar.d.ts +4 -0
  479. package/node_modules/zod/v4/locales/ar.js +111 -0
  480. package/node_modules/zod/v4/locales/az.cjs +137 -0
  481. package/node_modules/zod/v4/locales/az.d.cts +5 -0
  482. package/node_modules/zod/v4/locales/az.d.ts +4 -0
  483. package/node_modules/zod/v4/locales/az.js +110 -0
  484. package/node_modules/zod/v4/locales/be.cjs +195 -0
  485. package/node_modules/zod/v4/locales/be.d.cts +5 -0
  486. package/node_modules/zod/v4/locales/be.d.ts +4 -0
  487. package/node_modules/zod/v4/locales/be.js +168 -0
  488. package/node_modules/zod/v4/locales/bg.cjs +152 -0
  489. package/node_modules/zod/v4/locales/bg.d.cts +5 -0
  490. package/node_modules/zod/v4/locales/bg.d.ts +4 -0
  491. package/node_modules/zod/v4/locales/bg.js +125 -0
  492. package/node_modules/zod/v4/locales/bn.cjs +140 -0
  493. package/node_modules/zod/v4/locales/bn.d.cts +5 -0
  494. package/node_modules/zod/v4/locales/bn.d.ts +4 -0
  495. package/node_modules/zod/v4/locales/bn.js +113 -0
  496. package/node_modules/zod/v4/locales/ca.cjs +139 -0
  497. package/node_modules/zod/v4/locales/ca.d.cts +5 -0
  498. package/node_modules/zod/v4/locales/ca.d.ts +4 -0
  499. package/node_modules/zod/v4/locales/ca.js +112 -0
  500. package/node_modules/zod/v4/locales/ckb.cjs +160 -0
  501. package/node_modules/zod/v4/locales/ckb.d.cts +5 -0
  502. package/node_modules/zod/v4/locales/ckb.d.ts +4 -0
  503. package/node_modules/zod/v4/locales/ckb.js +133 -0
  504. package/node_modules/zod/v4/locales/cs.cjs +143 -0
  505. package/node_modules/zod/v4/locales/cs.d.cts +5 -0
  506. package/node_modules/zod/v4/locales/cs.d.ts +4 -0
  507. package/node_modules/zod/v4/locales/cs.js +116 -0
  508. package/node_modules/zod/v4/locales/da.cjs +147 -0
  509. package/node_modules/zod/v4/locales/da.d.cts +5 -0
  510. package/node_modules/zod/v4/locales/da.d.ts +4 -0
  511. package/node_modules/zod/v4/locales/da.js +120 -0
  512. package/node_modules/zod/v4/locales/de.cjs +140 -0
  513. package/node_modules/zod/v4/locales/de.d.cts +5 -0
  514. package/node_modules/zod/v4/locales/de.d.ts +4 -0
  515. package/node_modules/zod/v4/locales/de.js +113 -0
  516. package/node_modules/zod/v4/locales/el.cjs +139 -0
  517. package/node_modules/zod/v4/locales/el.d.cts +5 -0
  518. package/node_modules/zod/v4/locales/el.d.ts +4 -0
  519. package/node_modules/zod/v4/locales/el.js +112 -0
  520. package/node_modules/zod/v4/locales/en.cjs +152 -0
  521. package/node_modules/zod/v4/locales/en.d.cts +5 -0
  522. package/node_modules/zod/v4/locales/en.d.ts +4 -0
  523. package/node_modules/zod/v4/locales/en.js +125 -0
  524. package/node_modules/zod/v4/locales/eo.cjs +141 -0
  525. package/node_modules/zod/v4/locales/eo.d.cts +5 -0
  526. package/node_modules/zod/v4/locales/eo.d.ts +4 -0
  527. package/node_modules/zod/v4/locales/eo.js +114 -0
  528. package/node_modules/zod/v4/locales/es.cjs +163 -0
  529. package/node_modules/zod/v4/locales/es.d.cts +5 -0
  530. package/node_modules/zod/v4/locales/es.d.ts +4 -0
  531. package/node_modules/zod/v4/locales/es.js +136 -0
  532. package/node_modules/zod/v4/locales/fa.cjs +146 -0
  533. package/node_modules/zod/v4/locales/fa.d.cts +5 -0
  534. package/node_modules/zod/v4/locales/fa.d.ts +4 -0
  535. package/node_modules/zod/v4/locales/fa.js +119 -0
  536. package/node_modules/zod/v4/locales/fi.cjs +144 -0
  537. package/node_modules/zod/v4/locales/fi.d.cts +5 -0
  538. package/node_modules/zod/v4/locales/fi.d.ts +4 -0
  539. package/node_modules/zod/v4/locales/fi.js +117 -0
  540. package/node_modules/zod/v4/locales/fr-CA.cjs +139 -0
  541. package/node_modules/zod/v4/locales/fr-CA.d.cts +5 -0
  542. package/node_modules/zod/v4/locales/fr-CA.d.ts +4 -0
  543. package/node_modules/zod/v4/locales/fr-CA.js +112 -0
  544. package/node_modules/zod/v4/locales/fr.cjs +156 -0
  545. package/node_modules/zod/v4/locales/fr.d.cts +5 -0
  546. package/node_modules/zod/v4/locales/fr.d.ts +4 -0
  547. package/node_modules/zod/v4/locales/fr.js +129 -0
  548. package/node_modules/zod/v4/locales/gu.cjs +140 -0
  549. package/node_modules/zod/v4/locales/gu.d.cts +5 -0
  550. package/node_modules/zod/v4/locales/gu.d.ts +4 -0
  551. package/node_modules/zod/v4/locales/gu.js +113 -0
  552. package/node_modules/zod/v4/locales/he.cjs +248 -0
  553. package/node_modules/zod/v4/locales/he.d.cts +5 -0
  554. package/node_modules/zod/v4/locales/he.d.ts +4 -0
  555. package/node_modules/zod/v4/locales/he.js +221 -0
  556. package/node_modules/zod/v4/locales/hi.cjs +138 -0
  557. package/node_modules/zod/v4/locales/hi.d.cts +5 -0
  558. package/node_modules/zod/v4/locales/hi.d.ts +4 -0
  559. package/node_modules/zod/v4/locales/hi.js +111 -0
  560. package/node_modules/zod/v4/locales/hr.cjs +153 -0
  561. package/node_modules/zod/v4/locales/hr.d.cts +5 -0
  562. package/node_modules/zod/v4/locales/hr.d.ts +4 -0
  563. package/node_modules/zod/v4/locales/hr.js +126 -0
  564. package/node_modules/zod/v4/locales/hu.cjs +140 -0
  565. package/node_modules/zod/v4/locales/hu.d.cts +5 -0
  566. package/node_modules/zod/v4/locales/hu.d.ts +4 -0
  567. package/node_modules/zod/v4/locales/hu.js +113 -0
  568. package/node_modules/zod/v4/locales/hy.cjs +185 -0
  569. package/node_modules/zod/v4/locales/hy.d.cts +5 -0
  570. package/node_modules/zod/v4/locales/hy.d.ts +4 -0
  571. package/node_modules/zod/v4/locales/hy.js +158 -0
  572. package/node_modules/zod/v4/locales/id.cjs +138 -0
  573. package/node_modules/zod/v4/locales/id.d.cts +5 -0
  574. package/node_modules/zod/v4/locales/id.d.ts +4 -0
  575. package/node_modules/zod/v4/locales/id.js +111 -0
  576. package/node_modules/zod/v4/locales/index.cjs +152 -0
  577. package/node_modules/zod/v4/locales/index.d.cts +63 -0
  578. package/node_modules/zod/v4/locales/index.d.ts +63 -0
  579. package/node_modules/zod/v4/locales/index.js +63 -0
  580. package/node_modules/zod/v4/locales/is.cjs +141 -0
  581. package/node_modules/zod/v4/locales/is.d.cts +5 -0
  582. package/node_modules/zod/v4/locales/is.d.ts +4 -0
  583. package/node_modules/zod/v4/locales/is.js +114 -0
  584. package/node_modules/zod/v4/locales/it.cjs +140 -0
  585. package/node_modules/zod/v4/locales/it.d.cts +5 -0
  586. package/node_modules/zod/v4/locales/it.d.ts +4 -0
  587. package/node_modules/zod/v4/locales/it.js +113 -0
  588. package/node_modules/zod/v4/locales/ja.cjs +139 -0
  589. package/node_modules/zod/v4/locales/ja.d.cts +5 -0
  590. package/node_modules/zod/v4/locales/ja.d.ts +4 -0
  591. package/node_modules/zod/v4/locales/ja.js +112 -0
  592. package/node_modules/zod/v4/locales/ka.cjs +144 -0
  593. package/node_modules/zod/v4/locales/ka.d.cts +5 -0
  594. package/node_modules/zod/v4/locales/ka.d.ts +4 -0
  595. package/node_modules/zod/v4/locales/ka.js +117 -0
  596. package/node_modules/zod/v4/locales/kh.cjs +12 -0
  597. package/node_modules/zod/v4/locales/kh.d.cts +5 -0
  598. package/node_modules/zod/v4/locales/kh.d.ts +5 -0
  599. package/node_modules/zod/v4/locales/kh.js +5 -0
  600. package/node_modules/zod/v4/locales/km.cjs +142 -0
  601. package/node_modules/zod/v4/locales/km.d.cts +5 -0
  602. package/node_modules/zod/v4/locales/km.d.ts +4 -0
  603. package/node_modules/zod/v4/locales/km.js +115 -0
  604. package/node_modules/zod/v4/locales/kn.cjs +143 -0
  605. package/node_modules/zod/v4/locales/kn.d.cts +5 -0
  606. package/node_modules/zod/v4/locales/kn.d.ts +4 -0
  607. package/node_modules/zod/v4/locales/kn.js +116 -0
  608. package/node_modules/zod/v4/locales/ko.cjs +143 -0
  609. package/node_modules/zod/v4/locales/ko.d.cts +5 -0
  610. package/node_modules/zod/v4/locales/ko.d.ts +4 -0
  611. package/node_modules/zod/v4/locales/ko.js +116 -0
  612. package/node_modules/zod/v4/locales/lt.cjs +234 -0
  613. package/node_modules/zod/v4/locales/lt.d.cts +5 -0
  614. package/node_modules/zod/v4/locales/lt.d.ts +4 -0
  615. package/node_modules/zod/v4/locales/lt.js +207 -0
  616. package/node_modules/zod/v4/locales/mk.cjs +141 -0
  617. package/node_modules/zod/v4/locales/mk.d.cts +5 -0
  618. package/node_modules/zod/v4/locales/mk.d.ts +4 -0
  619. package/node_modules/zod/v4/locales/mk.js +114 -0
  620. package/node_modules/zod/v4/locales/ms.cjs +139 -0
  621. package/node_modules/zod/v4/locales/ms.d.cts +5 -0
  622. package/node_modules/zod/v4/locales/ms.d.ts +4 -0
  623. package/node_modules/zod/v4/locales/ms.js +112 -0
  624. package/node_modules/zod/v4/locales/ne.cjs +138 -0
  625. package/node_modules/zod/v4/locales/ne.d.cts +5 -0
  626. package/node_modules/zod/v4/locales/ne.d.ts +4 -0
  627. package/node_modules/zod/v4/locales/ne.js +111 -0
  628. package/node_modules/zod/v4/locales/nl.cjs +142 -0
  629. package/node_modules/zod/v4/locales/nl.d.cts +5 -0
  630. package/node_modules/zod/v4/locales/nl.d.ts +4 -0
  631. package/node_modules/zod/v4/locales/nl.js +115 -0
  632. package/node_modules/zod/v4/locales/nn.cjs +140 -0
  633. package/node_modules/zod/v4/locales/nn.d.cts +5 -0
  634. package/node_modules/zod/v4/locales/nn.d.ts +4 -0
  635. package/node_modules/zod/v4/locales/nn.js +113 -0
  636. package/node_modules/zod/v4/locales/no.cjs +140 -0
  637. package/node_modules/zod/v4/locales/no.d.cts +5 -0
  638. package/node_modules/zod/v4/locales/no.d.ts +4 -0
  639. package/node_modules/zod/v4/locales/no.js +113 -0
  640. package/node_modules/zod/v4/locales/ota.cjs +141 -0
  641. package/node_modules/zod/v4/locales/ota.d.cts +5 -0
  642. package/node_modules/zod/v4/locales/ota.d.ts +4 -0
  643. package/node_modules/zod/v4/locales/ota.js +114 -0
  644. package/node_modules/zod/v4/locales/package.json +7 -0
  645. package/node_modules/zod/v4/locales/pl.cjs +141 -0
  646. package/node_modules/zod/v4/locales/pl.d.cts +5 -0
  647. package/node_modules/zod/v4/locales/pl.d.ts +4 -0
  648. package/node_modules/zod/v4/locales/pl.js +114 -0
  649. package/node_modules/zod/v4/locales/ps.cjs +146 -0
  650. package/node_modules/zod/v4/locales/ps.d.cts +5 -0
  651. package/node_modules/zod/v4/locales/ps.d.ts +4 -0
  652. package/node_modules/zod/v4/locales/ps.js +119 -0
  653. package/node_modules/zod/v4/locales/pt-BR.cjs +170 -0
  654. package/node_modules/zod/v4/locales/pt-BR.d.cts +5 -0
  655. package/node_modules/zod/v4/locales/pt-BR.d.ts +4 -0
  656. package/node_modules/zod/v4/locales/pt-BR.js +143 -0
  657. package/node_modules/zod/v4/locales/pt.cjs +169 -0
  658. package/node_modules/zod/v4/locales/pt.d.cts +5 -0
  659. package/node_modules/zod/v4/locales/pt.d.ts +4 -0
  660. package/node_modules/zod/v4/locales/pt.js +142 -0
  661. package/node_modules/zod/v4/locales/ro.cjs +149 -0
  662. package/node_modules/zod/v4/locales/ro.d.cts +5 -0
  663. package/node_modules/zod/v4/locales/ro.d.ts +4 -0
  664. package/node_modules/zod/v4/locales/ro.js +122 -0
  665. package/node_modules/zod/v4/locales/ru.cjs +195 -0
  666. package/node_modules/zod/v4/locales/ru.d.cts +5 -0
  667. package/node_modules/zod/v4/locales/ru.d.ts +4 -0
  668. package/node_modules/zod/v4/locales/ru.js +168 -0
  669. package/node_modules/zod/v4/locales/sk.cjs +143 -0
  670. package/node_modules/zod/v4/locales/sk.d.cts +5 -0
  671. package/node_modules/zod/v4/locales/sk.d.ts +4 -0
  672. package/node_modules/zod/v4/locales/sk.js +116 -0
  673. package/node_modules/zod/v4/locales/sl.cjs +141 -0
  674. package/node_modules/zod/v4/locales/sl.d.cts +5 -0
  675. package/node_modules/zod/v4/locales/sl.d.ts +4 -0
  676. package/node_modules/zod/v4/locales/sl.js +114 -0
  677. package/node_modules/zod/v4/locales/sv.cjs +142 -0
  678. package/node_modules/zod/v4/locales/sv.d.cts +5 -0
  679. package/node_modules/zod/v4/locales/sv.d.ts +4 -0
  680. package/node_modules/zod/v4/locales/sv.js +115 -0
  681. package/node_modules/zod/v4/locales/ta.cjs +142 -0
  682. package/node_modules/zod/v4/locales/ta.d.cts +5 -0
  683. package/node_modules/zod/v4/locales/ta.d.ts +4 -0
  684. package/node_modules/zod/v4/locales/ta.js +115 -0
  685. package/node_modules/zod/v4/locales/tg.cjs +144 -0
  686. package/node_modules/zod/v4/locales/tg.d.cts +5 -0
  687. package/node_modules/zod/v4/locales/tg.d.ts +4 -0
  688. package/node_modules/zod/v4/locales/tg.js +117 -0
  689. package/node_modules/zod/v4/locales/th.cjs +142 -0
  690. package/node_modules/zod/v4/locales/th.d.cts +5 -0
  691. package/node_modules/zod/v4/locales/th.d.ts +4 -0
  692. package/node_modules/zod/v4/locales/th.js +115 -0
  693. package/node_modules/zod/v4/locales/tk.cjs +134 -0
  694. package/node_modules/zod/v4/locales/tk.d.cts +5 -0
  695. package/node_modules/zod/v4/locales/tk.d.ts +4 -0
  696. package/node_modules/zod/v4/locales/tk.js +107 -0
  697. package/node_modules/zod/v4/locales/tr.cjs +137 -0
  698. package/node_modules/zod/v4/locales/tr.d.cts +5 -0
  699. package/node_modules/zod/v4/locales/tr.d.ts +4 -0
  700. package/node_modules/zod/v4/locales/tr.js +110 -0
  701. package/node_modules/zod/v4/locales/ua.cjs +12 -0
  702. package/node_modules/zod/v4/locales/ua.d.cts +5 -0
  703. package/node_modules/zod/v4/locales/ua.d.ts +5 -0
  704. package/node_modules/zod/v4/locales/ua.js +5 -0
  705. package/node_modules/zod/v4/locales/uk.cjs +140 -0
  706. package/node_modules/zod/v4/locales/uk.d.cts +5 -0
  707. package/node_modules/zod/v4/locales/uk.d.ts +4 -0
  708. package/node_modules/zod/v4/locales/uk.js +113 -0
  709. package/node_modules/zod/v4/locales/ur.cjs +142 -0
  710. package/node_modules/zod/v4/locales/ur.d.cts +5 -0
  711. package/node_modules/zod/v4/locales/ur.d.ts +4 -0
  712. package/node_modules/zod/v4/locales/ur.js +115 -0
  713. package/node_modules/zod/v4/locales/uz.cjs +140 -0
  714. package/node_modules/zod/v4/locales/uz.d.cts +5 -0
  715. package/node_modules/zod/v4/locales/uz.d.ts +4 -0
  716. package/node_modules/zod/v4/locales/uz.js +113 -0
  717. package/node_modules/zod/v4/locales/vi.cjs +140 -0
  718. package/node_modules/zod/v4/locales/vi.d.cts +5 -0
  719. package/node_modules/zod/v4/locales/vi.d.ts +4 -0
  720. package/node_modules/zod/v4/locales/vi.js +113 -0
  721. package/node_modules/zod/v4/locales/yo.cjs +139 -0
  722. package/node_modules/zod/v4/locales/yo.d.cts +5 -0
  723. package/node_modules/zod/v4/locales/yo.d.ts +4 -0
  724. package/node_modules/zod/v4/locales/yo.js +112 -0
  725. package/node_modules/zod/v4/locales/zh-CN.cjs +141 -0
  726. package/node_modules/zod/v4/locales/zh-CN.d.cts +5 -0
  727. package/node_modules/zod/v4/locales/zh-CN.d.ts +4 -0
  728. package/node_modules/zod/v4/locales/zh-CN.js +114 -0
  729. package/node_modules/zod/v4/locales/zh-TW.cjs +139 -0
  730. package/node_modules/zod/v4/locales/zh-TW.d.cts +5 -0
  731. package/node_modules/zod/v4/locales/zh-TW.d.ts +4 -0
  732. package/node_modules/zod/v4/locales/zh-TW.js +112 -0
  733. package/node_modules/zod/v4/mini/checks.cjs +54 -0
  734. package/node_modules/zod/v4/mini/checks.d.cts +1 -0
  735. package/node_modules/zod/v4/mini/checks.d.ts +1 -0
  736. package/node_modules/zod/v4/mini/checks.js +1 -0
  737. package/node_modules/zod/v4/mini/coerce.cjs +71 -0
  738. package/node_modules/zod/v4/mini/coerce.d.cts +7 -0
  739. package/node_modules/zod/v4/mini/coerce.d.ts +7 -0
  740. package/node_modules/zod/v4/mini/coerce.js +22 -0
  741. package/node_modules/zod/v4/mini/deep-partial.cjs +58 -0
  742. package/node_modules/zod/v4/mini/deep-partial.d.cts +14 -0
  743. package/node_modules/zod/v4/mini/deep-partial.d.ts +14 -0
  744. package/node_modules/zod/v4/mini/deep-partial.js +13 -0
  745. package/node_modules/zod/v4/mini/external.cjs +95 -0
  746. package/node_modules/zod/v4/mini/external.d.cts +16 -0
  747. package/node_modules/zod/v4/mini/external.d.ts +16 -0
  748. package/node_modules/zod/v4/mini/external.js +16 -0
  749. package/node_modules/zod/v4/mini/in-out.cjs +82 -0
  750. package/node_modules/zod/v4/mini/in-out.d.cts +8 -0
  751. package/node_modules/zod/v4/mini/in-out.d.ts +8 -0
  752. package/node_modules/zod/v4/mini/in-out.js +36 -0
  753. package/node_modules/zod/v4/mini/index.cjs +51 -0
  754. package/node_modules/zod/v4/mini/index.d.cts +3 -0
  755. package/node_modules/zod/v4/mini/index.d.ts +3 -0
  756. package/node_modules/zod/v4/mini/index.js +3 -0
  757. package/node_modules/zod/v4/mini/iso.cjs +83 -0
  758. package/node_modules/zod/v4/mini/iso.d.cts +22 -0
  759. package/node_modules/zod/v4/mini/iso.d.ts +22 -0
  760. package/node_modules/zod/v4/mini/iso.js +34 -0
  761. package/node_modules/zod/v4/mini/package.json +7 -0
  762. package/node_modules/zod/v4/mini/parse.cjs +37 -0
  763. package/node_modules/zod/v4/mini/parse.d.cts +1 -0
  764. package/node_modules/zod/v4/mini/parse.d.ts +1 -0
  765. package/node_modules/zod/v4/mini/parse.js +1 -0
  766. package/node_modules/zod/v4/mini/schemas.cjs +1147 -0
  767. package/node_modules/zod/v4/mini/schemas.d.cts +480 -0
  768. package/node_modules/zod/v4/mini/schemas.d.ts +480 -0
  769. package/node_modules/zod/v4/mini/schemas.js +1002 -0
  770. package/node_modules/zod/v4/package.json +7 -0
  771. package/node_modules/zod/v4-mini/index.cjs +51 -0
  772. package/node_modules/zod/v4-mini/index.d.cts +3 -0
  773. package/node_modules/zod/v4-mini/index.d.ts +3 -0
  774. package/node_modules/zod/v4-mini/index.js +3 -0
  775. package/node_modules/zod/v4-mini/package.json +7 -0
  776. package/package.json +32 -4
  777. package/runtime.cjs +14 -0
  778. package/scripts/arguments.mjs +77 -0
  779. package/scripts/continuation.mjs +31 -0
  780. package/scripts/create-task.mjs +27 -0
  781. package/scripts/delete-task.mjs +3 -0
  782. package/scripts/entry.mjs +6 -0
  783. package/scripts/get-task.mjs +40 -0
  784. package/scripts/get-tasks.mjs +84 -0
  785. package/scripts/hook.mjs +89 -0
  786. package/scripts/inspect-blockers.mjs +76 -0
  787. package/scripts/install-launcher.mjs +28 -0
  788. package/scripts/install-migration.mjs +82 -0
  789. package/scripts/install-path.mjs +105 -0
  790. package/scripts/install-release.mjs +252 -0
  791. package/scripts/lifecycle.mjs +35 -0
  792. package/scripts/list-tasks.mjs +117 -0
  793. package/scripts/output.mjs +67 -0
  794. package/scripts/schema.mjs +41 -0
  795. package/scripts/search-tasks.mjs +96 -0
  796. package/scripts/task-write-input.mjs +80 -0
  797. package/scripts/transition-task.mjs +3 -0
  798. package/scripts/update-release.mjs +82 -0
  799. package/scripts/update-task.mjs +29 -0
  800. package/scripts/validate-task-stores.mjs +34 -0
  801. package/src/blockers.mjs +134 -0
  802. package/src/cache.mjs +50 -0
  803. package/src/config.mjs +30 -0
  804. package/src/create.mjs +144 -0
  805. package/src/cursor.mjs +30 -0
  806. package/src/destinations.mjs +74 -0
  807. package/src/errors.mjs +16 -0
  808. package/src/field-rules.mjs +105 -0
  809. package/src/fields.mjs +32 -0
  810. package/src/input.mjs +144 -0
  811. package/src/limits.mjs +5 -0
  812. package/src/locations.mjs +19 -0
  813. package/src/pagination.mjs +30 -0
  814. package/src/project-lock.mjs +74 -0
  815. package/src/projects.mjs +33 -0
  816. package/src/response.mjs +75 -0
  817. package/src/schema.mjs +76 -0
  818. package/src/search-index-worker.mjs +10 -0
  819. package/src/search-index.mjs +639 -0
  820. package/src/search.mjs +228 -0
  821. package/src/service.mjs +260 -0
  822. package/src/source.mjs +48 -0
  823. package/src/sqlite.mjs +17 -0
  824. package/src/storage-format.mjs +15 -0
  825. package/src/stores.mjs +307 -0
  826. package/src/tasks.mjs +290 -0
  827. package/src/timestamps.mjs +22 -0
  828. package/src/transition.mjs +180 -0
  829. package/src/update.mjs +56 -0
  830. package/src/validation.mjs +143 -0
  831. package/src/version.mjs +5 -0
@@ -0,0 +1,1978 @@
1
+ const require_chunk = require('./chunk-Bnu9O96Y.cjs');
2
+ const require_mcp = require('./mcp-BumlNux0.cjs');
3
+ const require_src = require('./src-BhnGYybN.cjs');
4
+ let _modelcontextprotocol_server__shims = require("@modelcontextprotocol/server/_shims");
5
+ let _modelcontextprotocol_core_internal = require("@modelcontextprotocol/core/internal");
6
+
7
+ //#region src/server/perRequestTransport.ts
8
+ /**
9
+ * The per-request micro-transport: a real, connected `Transport` whose whole
10
+ * lifetime is one HTTP exchange. See the module documentation for the
11
+ * response shapes it produces.
12
+ */
13
+ var PerRequestHTTPServerTransport = class {
14
+ onclose;
15
+ onerror;
16
+ onmessage;
17
+ _classification;
18
+ _responseMode;
19
+ _started = false;
20
+ _used = false;
21
+ _closed = false;
22
+ _terminalDelivered = false;
23
+ /**
24
+ * `true` only while the inbound message is being delivered synchronously
25
+ * to the connected protocol layer. The pre-handler gates (the era
26
+ * registry gate, the edge→instance handoff check, the missing-handler
27
+ * rejection) answer inside this window; request handlers always run
28
+ * after it (the protocol layer defers them to a microtask). An error
29
+ * sent inside the window is therefore ladder-originated, and an error
30
+ * sent after it is handler-produced.
31
+ */
32
+ _dispatchWindowOpen = false;
33
+ _requestId;
34
+ _deferredResponse;
35
+ _sse;
36
+ _abortCleanup;
37
+ _keepAliveMs;
38
+ constructor(options) {
39
+ this._classification = options.classification;
40
+ this._responseMode = options.responseMode ?? "auto";
41
+ this._keepAliveMs = options.keepAliveMs ?? require_mcp.DEFAULT_SSE_KEEP_ALIVE_MS;
42
+ }
43
+ async start() {
44
+ if (this._started) throw new Error("PerRequestHTTPServerTransport is already started");
45
+ this._started = true;
46
+ }
47
+ /**
48
+ * Serves the single exchange: delivers the classified message to the
49
+ * connected server instance and resolves with the HTTP response.
50
+ *
51
+ * Throws when called a second time (the transport is strictly
52
+ * single-use), or before a server has been connected to the transport.
53
+ * The returned promise rejects with a connection-closed error when the
54
+ * transport is closed before a response was produced (for example because
55
+ * the client disconnected).
56
+ */
57
+ async handleMessage(message, extra) {
58
+ if (this._used) throw new Error("PerRequestHTTPServerTransport serves exactly one exchange; construct a new transport per request");
59
+ if (!this._started || this.onmessage === void 0) throw new Error("PerRequestHTTPServerTransport is not connected: connect a server to this transport before handling a message");
60
+ if (this._closed) throw new Error("PerRequestHTTPServerTransport is closed");
61
+ this._used = true;
62
+ const signal = extra?.request?.signal;
63
+ if (signal?.aborted) {
64
+ await this.close();
65
+ throw new require_src.SdkError(require_src.SdkErrorCode.ConnectionClosed, "The request was aborted before it could be handled");
66
+ }
67
+ const messageExtra = {
68
+ classification: this._classification,
69
+ ...extra?.request !== void 0 && { request: extra.request },
70
+ ...extra?.authInfo !== void 0 && { authInfo: extra.authInfo }
71
+ };
72
+ if (require_src.isJSONRPCRequest(message)) {
73
+ this._requestId = message.id;
74
+ let resolve;
75
+ let reject;
76
+ const promise = new Promise((promiseResolve, promiseReject) => {
77
+ resolve = promiseResolve;
78
+ reject = promiseReject;
79
+ });
80
+ this._deferredResponse = {
81
+ promise,
82
+ resolve,
83
+ reject,
84
+ settled: false
85
+ };
86
+ if (signal !== void 0) {
87
+ const onAbort = () => void this.close();
88
+ signal.addEventListener("abort", onAbort, { once: true });
89
+ this._abortCleanup = () => signal.removeEventListener("abort", onAbort);
90
+ }
91
+ this._dispatchWindowOpen = true;
92
+ try {
93
+ this.onmessage(message, messageExtra);
94
+ } finally {
95
+ this._dispatchWindowOpen = false;
96
+ }
97
+ if (this._responseMode === "sse" && !this._closed && !this._deferredResponse.settled) this.upgradeToSse();
98
+ return promise;
99
+ }
100
+ this.onmessage(message, messageExtra);
101
+ return new Response(null, { status: 202 });
102
+ }
103
+ async send(message, options) {
104
+ if (this._closed) return;
105
+ const isResponse = require_src.isJSONRPCResultResponse(message) || require_src.isJSONRPCErrorResponse(message);
106
+ const relatedId = isResponse ? message.id : options?.relatedRequestId;
107
+ if (this._requestId === void 0 || relatedId === void 0 || relatedId !== this._requestId) {
108
+ if (isResponse) this.onerror?.(/* @__PURE__ */ new Error(`Received a response for an unknown request id: ${String(message.id)}`));
109
+ return;
110
+ }
111
+ if (isResponse) {
112
+ if (this._terminalDelivered) return;
113
+ this._terminalDelivered = true;
114
+ const errorCode = require_src.isJSONRPCErrorResponse(message) ? message.error.code : void 0;
115
+ const ladderStatus = errorCode !== void 0 && (this._dispatchWindowOpen || errorCode === require_src.ProtocolErrorCode.MissingRequiredClientCapability) ? require_src.LADDER_ERROR_HTTP_STATUS[errorCode] : void 0;
116
+ if (ladderStatus !== void 0 && this._sse === void 0) {
117
+ this.settleResponse(Response.json(message, {
118
+ status: ladderStatus,
119
+ headers: { "Content-Type": "application/json" }
120
+ }));
121
+ queueMicrotask(() => void this.close());
122
+ return;
123
+ }
124
+ if (this._sse !== void 0 || this._responseMode === "sse") {
125
+ if (this._sse === void 0) this.upgradeToSse();
126
+ this.writeMessageFrame(message);
127
+ this.finalizeStream();
128
+ return;
129
+ }
130
+ this.settleResponse(Response.json(message, {
131
+ status: 200,
132
+ headers: { "Content-Type": "application/json" }
133
+ }));
134
+ queueMicrotask(() => void this.close());
135
+ return;
136
+ }
137
+ if (this._responseMode === "json") return;
138
+ if (this._sse === void 0) this.upgradeToSse();
139
+ this.writeMessageFrame(message);
140
+ }
141
+ /**
142
+ * Writes an SSE comment frame (a keep-alive heartbeat). Dropped when the
143
+ * exchange is not currently streaming.
144
+ */
145
+ writeCommentFrame(comment) {
146
+ if (this._closed || this._sse === void 0 || this._sse.closed) return;
147
+ const frame = comment.split("\n").map((line) => `: ${line}`).join("\n");
148
+ this.writeFrame(`${frame}\n\n`);
149
+ }
150
+ async close() {
151
+ if (this._closed) return;
152
+ this._closed = true;
153
+ this._abortCleanup?.();
154
+ this._abortCleanup = void 0;
155
+ if (this._sse?.keepAliveTimer !== void 0) clearInterval(this._sse.keepAliveTimer);
156
+ if (this._sse !== void 0 && !this._sse.closed) {
157
+ this._sse.closed = true;
158
+ try {
159
+ this._sse.controller.close();
160
+ } catch {}
161
+ }
162
+ if (this._deferredResponse !== void 0 && !this._deferredResponse.settled) {
163
+ this._deferredResponse.settled = true;
164
+ this._deferredResponse.reject(new require_src.SdkError(require_src.SdkErrorCode.ConnectionClosed, "Connection closed before a response was produced"));
165
+ }
166
+ this.onclose?.();
167
+ }
168
+ settleResponse(response) {
169
+ if (this._deferredResponse === void 0 || this._deferredResponse.settled) return;
170
+ this._deferredResponse.settled = true;
171
+ this._deferredResponse.resolve(response);
172
+ }
173
+ upgradeToSse() {
174
+ let controller;
175
+ const readable = new ReadableStream({
176
+ start: (streamController) => {
177
+ controller = streamController;
178
+ },
179
+ cancel: () => {
180
+ this.close();
181
+ }
182
+ });
183
+ this._sse = {
184
+ controller,
185
+ encoder: new TextEncoder(),
186
+ closed: false
187
+ };
188
+ this._sse.keepAliveTimer = require_mcp.armSseKeepAlive(this._keepAliveMs, () => this.writeCommentFrame("keepalive"));
189
+ this.settleResponse(new Response(readable, {
190
+ status: 200,
191
+ headers: {
192
+ "Content-Type": "text/event-stream",
193
+ "Cache-Control": "no-cache, no-transform",
194
+ Connection: "keep-alive",
195
+ "X-Accel-Buffering": "no"
196
+ }
197
+ }));
198
+ }
199
+ finalizeStream() {
200
+ if (this._sse?.keepAliveTimer !== void 0) clearInterval(this._sse.keepAliveTimer);
201
+ if (this._sse !== void 0 && !this._sse.closed) {
202
+ this._sse.closed = true;
203
+ try {
204
+ this._sse.controller.close();
205
+ } catch {}
206
+ }
207
+ queueMicrotask(() => void this.close());
208
+ }
209
+ writeMessageFrame(message) {
210
+ this.writeFrame(`event: message\ndata: ${JSON.stringify(message)}\n\n`);
211
+ }
212
+ writeFrame(frame) {
213
+ if (this._sse === void 0 || this._sse.closed) return;
214
+ try {
215
+ this._sse.controller.enqueue(this._sse.encoder.encode(frame));
216
+ } catch (error) {
217
+ this.onerror?.(/* @__PURE__ */ new Error(`Failed to write to the response stream: ${error}`));
218
+ }
219
+ }
220
+ };
221
+
222
+ //#endregion
223
+ //#region src/server/invoke.ts
224
+ /**
225
+ * Serves one classified inbound message on the given server instance and
226
+ * returns the HTTP response for the exchange.
227
+ *
228
+ * The instance is connected to a fresh single-exchange transport, the message
229
+ * is injected through the normal transport message path, and whatever the
230
+ * dispatch layer produces (the handler result, a protocol-level rejection, or
231
+ * streamed related messages followed by the result) is captured as the
232
+ * returned `Response`. For request exchanges, teardown rides the transport's
233
+ * close chain once the terminal response has been delivered; notification
234
+ * exchanges resolve with the 202 response immediately and do NOT run the
235
+ * close chain — the transport stays connected until the caller closes it or
236
+ * drops the per-request instance, which is the caller's choice either way.
237
+ */
238
+ async function invoke(server, message, ctx) {
239
+ const transport = new PerRequestHTTPServerTransport({
240
+ classification: ctx.classification,
241
+ ...ctx.responseMode !== void 0 && { responseMode: ctx.responseMode },
242
+ ...ctx.keepAliveMs !== void 0 && { keepAliveMs: ctx.keepAliveMs }
243
+ });
244
+ await server.connect(transport);
245
+ return transport.handleMessage(message, {
246
+ ...ctx.request !== void 0 && { request: ctx.request },
247
+ ...ctx.authInfo !== void 0 && { authInfo: ctx.authInfo }
248
+ });
249
+ }
250
+
251
+ //#endregion
252
+ //#region src/server/requestBody.ts
253
+ /** Default upper bound, in bytes, on a request body read by the HTTP entry points (4 MiB). */
254
+ const DEFAULT_MAX_REQUEST_BODY_SIZE = 4 * 1024 * 1024;
255
+ /** Upper bound on the number of messages accepted in one JSON-RPC batch array. */
256
+ const MAX_BATCH_SIZE = 100;
257
+ /** The message answered with 413 for a request body over `maxBytes`. */
258
+ function requestBodyTooLargeMessage(maxBytes) {
259
+ return `Payload Too Large: Request body must not exceed ${maxBytes} bytes`;
260
+ }
261
+ /**
262
+ * Resolves a `maxRequestBodySize` option to the bound to apply: the default when
263
+ * omitted, otherwise the value itself, which must be a positive finite number of
264
+ * bytes (a `RangeError` is thrown at configuration time for anything else).
265
+ */
266
+ function resolveMaxRequestBodySize(value) {
267
+ if (value === void 0) return DEFAULT_MAX_REQUEST_BODY_SIZE;
268
+ if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) throw new RangeError(`maxRequestBodySize must be a positive number of bytes, got ${String(value)}`);
269
+ return value;
270
+ }
271
+ /**
272
+ * Reads a request body as text, up to `maxBytes` (default
273
+ * {@linkcode DEFAULT_MAX_REQUEST_BODY_SIZE}). A declared `Content-Length` over the
274
+ * limit is refused without reading anything; otherwise the read stops as soon as
275
+ * more than the limit has arrived. Stream failures propagate.
276
+ */
277
+ async function readRequestBody(request, maxBytes = DEFAULT_MAX_REQUEST_BODY_SIZE) {
278
+ if (Number(request.headers.get("content-length")) > maxBytes) return { tooLarge: true };
279
+ if (request.body === null) return {
280
+ tooLarge: false,
281
+ text: ""
282
+ };
283
+ const reader = request.body.getReader();
284
+ const decoder = new TextDecoder();
285
+ let received = 0;
286
+ let text = "";
287
+ try {
288
+ for (;;) {
289
+ const { done, value } = await reader.read();
290
+ if (done) break;
291
+ received += value.byteLength;
292
+ if (received > maxBytes) return { tooLarge: true };
293
+ text += decoder.decode(value, { stream: true });
294
+ }
295
+ } finally {
296
+ reader.releaseLock();
297
+ }
298
+ return {
299
+ tooLarge: false,
300
+ text: text + decoder.decode()
301
+ };
302
+ }
303
+
304
+ //#endregion
305
+ //#region src/server/streamableHttp.ts
306
+ /**
307
+ * Server transport for Web Standards Streamable HTTP: this implements the MCP Streamable HTTP transport specification
308
+ * using Web Standard APIs (`Request`, `Response`, `ReadableStream`).
309
+ *
310
+ * This transport works on any runtime that supports Web Standards: Node.js 18+, Cloudflare Workers, Deno, Bun, etc.
311
+ *
312
+ * In stateful mode:
313
+ * - Session ID is generated and included in response headers
314
+ * - Session ID is always included in initialization responses
315
+ * - Requests with invalid session IDs are rejected with `404 Not Found`
316
+ * - Non-initialization requests without a session ID are rejected with `400 Bad Request`
317
+ * - State is maintained in-memory (connections, message history)
318
+ *
319
+ * In stateless mode:
320
+ * - No Session ID is included in any responses
321
+ * - No session validation is performed
322
+ *
323
+ * @example Stateful setup
324
+ * ```ts source="./streamableHttp.examples.ts#WebStandardStreamableHTTPServerTransport_stateful"
325
+ * const server = new McpServer({ name: 'my-server', version: '1.0.0' });
326
+ *
327
+ * const transport = new WebStandardStreamableHTTPServerTransport({
328
+ * sessionIdGenerator: () => crypto.randomUUID()
329
+ * });
330
+ *
331
+ * await server.connect(transport);
332
+ * ```
333
+ *
334
+ * @example Stateless setup
335
+ * ```ts source="./streamableHttp.examples.ts#WebStandardStreamableHTTPServerTransport_stateless"
336
+ * const transport = new WebStandardStreamableHTTPServerTransport({
337
+ * sessionIdGenerator: undefined
338
+ * });
339
+ * ```
340
+ *
341
+ * @example Hono.js
342
+ * ```ts source="./streamableHttp.examples.ts#WebStandardStreamableHTTPServerTransport_hono"
343
+ * app.all('/mcp', async c => {
344
+ * // Stateless example: create a server and a transport per request.
345
+ * const server = new McpServer({ name: 'my-server', version: '1.0.0' });
346
+ * const transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: undefined });
347
+ * await server.connect(transport);
348
+ * return transport.handleRequest(c.req.raw);
349
+ * });
350
+ * ```
351
+ *
352
+ * @example Cloudflare Workers
353
+ * ```ts source="./streamableHttp.examples.ts#WebStandardStreamableHTTPServerTransport_workers"
354
+ * const worker = {
355
+ * async fetch(request: Request): Promise<Response> {
356
+ * // Stateless example: create a server and a transport per request.
357
+ * const server = new McpServer({ name: 'my-server', version: '1.0.0' });
358
+ * const transport = new WebStandardStreamableHTTPServerTransport({ sessionIdGenerator: undefined });
359
+ * await server.connect(transport);
360
+ * return transport.handleRequest(request);
361
+ * }
362
+ * };
363
+ * ```
364
+ */
365
+ var WebStandardStreamableHTTPServerTransport = class {
366
+ sessionIdGenerator;
367
+ _started = false;
368
+ _hasHandledRequest = false;
369
+ _closed = false;
370
+ _streamMapping = /* @__PURE__ */ new Map();
371
+ _requestToStreamMapping = /* @__PURE__ */ new Map();
372
+ _requestResponseMap = /* @__PURE__ */ new Map();
373
+ _initialized = false;
374
+ _enableJsonResponse = false;
375
+ _standaloneSseStreamId = "_GET_stream";
376
+ _eventStore;
377
+ _onsessioninitialized;
378
+ _onsessionclosed;
379
+ _allowedHosts;
380
+ _allowedOrigins;
381
+ _enableDnsRebindingProtection;
382
+ _retryInterval;
383
+ _supportedProtocolVersions;
384
+ _keepAliveMs;
385
+ _maxRequestBodySize;
386
+ _scopeChallengeResolver;
387
+ sessionId;
388
+ onclose;
389
+ onerror;
390
+ onmessage;
391
+ constructor(options = {}) {
392
+ this.sessionIdGenerator = options.sessionIdGenerator;
393
+ this._enableJsonResponse = options.enableJsonResponse ?? false;
394
+ this._eventStore = options.eventStore;
395
+ this._onsessioninitialized = options.onsessioninitialized;
396
+ this._onsessionclosed = options.onsessionclosed;
397
+ this._allowedHosts = options.allowedHosts;
398
+ this._allowedOrigins = options.allowedOrigins;
399
+ this._enableDnsRebindingProtection = options.enableDnsRebindingProtection ?? false;
400
+ this._retryInterval = options.retryInterval;
401
+ this._supportedProtocolVersions = options.supportedProtocolVersions ?? _modelcontextprotocol_core_internal.SUPPORTED_PROTOCOL_VERSIONS;
402
+ this._keepAliveMs = options.keepAliveMs ?? require_mcp.DEFAULT_SSE_KEEP_ALIVE_MS;
403
+ this._maxRequestBodySize = resolveMaxRequestBodySize(options.maxRequestBodySize);
404
+ }
405
+ startKeepAlive(controller, encoder) {
406
+ if (this._closed) return void 0;
407
+ const timer = require_mcp.armSseKeepAlive(this._keepAliveMs, () => {
408
+ try {
409
+ controller.enqueue(encoder.encode(": keepalive\n\n"));
410
+ } catch {
411
+ if (timer !== void 0) clearInterval(timer);
412
+ }
413
+ });
414
+ return timer;
415
+ }
416
+ /** Sets the scope challenge resolver for parsed JSON-RPC requests. */
417
+ setScopeChallengeResolver(resolver) {
418
+ this._scopeChallengeResolver = resolver;
419
+ }
420
+ /**
421
+ * Starts the transport. This is required by the {@linkcode Transport} interface but is a no-op
422
+ * for the Streamable HTTP transport as connections are managed per-request.
423
+ */
424
+ async start() {
425
+ if (this._started) throw new Error("Transport already started");
426
+ this._started = true;
427
+ }
428
+ /**
429
+ * Sets the supported protocol versions for header validation.
430
+ * Called by the server during {@linkcode server/server.Server.connect | connect()} to pass its supported versions.
431
+ */
432
+ setSupportedProtocolVersions(versions) {
433
+ this._supportedProtocolVersions = versions;
434
+ }
435
+ /**
436
+ * Helper to create a JSON error response
437
+ */
438
+ createJsonErrorResponse(status, code, message, options) {
439
+ const error = {
440
+ code,
441
+ message
442
+ };
443
+ if (options?.data !== void 0) error.data = options.data;
444
+ return Response.json({
445
+ jsonrpc: "2.0",
446
+ error,
447
+ id: null
448
+ }, {
449
+ status,
450
+ headers: {
451
+ "Content-Type": "application/json",
452
+ ...options?.headers
453
+ }
454
+ });
455
+ }
456
+ async _checkScopeChallenge(messages, authInfo) {
457
+ if (!this._scopeChallengeResolver) return;
458
+ const challenge = await require_mcp.findScopeChallenge(messages.filter((message) => require_src.isJSONRPCRequest(message)), authInfo, this._scopeChallengeResolver);
459
+ return challenge === void 0 ? void 0 : require_mcp.createScopeChallengeResponse(challenge, require_mcp.scopeChallengeResourceMetadataUrl(authInfo));
460
+ }
461
+ /**
462
+ * Validates request headers for DNS rebinding protection.
463
+ * @returns Error response if validation fails, `undefined` if validation passes.
464
+ */
465
+ validateRequestHeaders(req) {
466
+ if (!this._enableDnsRebindingProtection) return;
467
+ if (this._allowedHosts && this._allowedHosts.length > 0) {
468
+ const hostHeader = req.headers.get("host");
469
+ if (!hostHeader || !this._allowedHosts.includes(hostHeader)) {
470
+ const error = `Invalid Host header: ${hostHeader}`;
471
+ this.onerror?.(new Error(error));
472
+ return this.createJsonErrorResponse(403, -32e3, error);
473
+ }
474
+ }
475
+ if (this._allowedOrigins && this._allowedOrigins.length > 0) {
476
+ const originHeader = req.headers.get("origin");
477
+ if (originHeader && !this._allowedOrigins.includes(originHeader)) {
478
+ const error = `Invalid Origin header: ${originHeader}`;
479
+ this.onerror?.(new Error(error));
480
+ return this.createJsonErrorResponse(403, -32e3, error);
481
+ }
482
+ }
483
+ }
484
+ /**
485
+ * Handles an incoming HTTP request, whether `GET`, `POST`, or `DELETE`
486
+ * Returns a `Response` object (Web Standard)
487
+ */
488
+ async handleRequest(req, options) {
489
+ if (this._closed) return this.createJsonErrorResponse(404, -32001, "Session not found");
490
+ if (!this.sessionIdGenerator && this._hasHandledRequest) throw new Error("Stateless transport cannot be reused across requests. Create a new transport per request.");
491
+ this._hasHandledRequest = true;
492
+ const validationError = this.validateRequestHeaders(req);
493
+ if (validationError) return validationError;
494
+ switch (req.method) {
495
+ case "POST": return this.handlePostRequest(req, options);
496
+ case "GET": return this.handleGetRequest(req);
497
+ case "DELETE": return this.handleDeleteRequest(req);
498
+ default: return this.handleUnsupportedRequest();
499
+ }
500
+ }
501
+ /**
502
+ * Returns true if the client's protocol version supports empty SSE data in
503
+ * priming events (the fix shipped with protocol version `2025-11-25`).
504
+ *
505
+ * The version is checked for membership in this transport instance's
506
+ * supported protocol versions rather than with an open-ended
507
+ * `>= '2025-11-25'` comparison: the value may come from an `initialize`
508
+ * request body, which (unlike the `MCP-Protocol-Version` header) is not
509
+ * validated against `supportedProtocolVersions` before reaching this
510
+ * check. An unknown future version string must not silently enable
511
+ * behavior reserved for versions this transport actually supports.
512
+ */
513
+ supportsEmptySSEData(protocolVersion) {
514
+ return this._supportedProtocolVersions.includes(protocolVersion) && protocolVersion >= "2025-11-25";
515
+ }
516
+ /**
517
+ * Writes a priming event to establish resumption capability.
518
+ * Only sends if `eventStore` is configured (opt-in for resumability) and
519
+ * the client's protocol version supports empty SSE data (a supported
520
+ * version that is >= `2025-11-25`).
521
+ */
522
+ async writePrimingEvent(controller, encoder, streamId, protocolVersion) {
523
+ if (!this._eventStore) return;
524
+ if (!this.supportsEmptySSEData(protocolVersion)) return;
525
+ const primingEventId = await this._eventStore.storeEvent(streamId, {});
526
+ let primingEvent = `id: ${primingEventId}\ndata: \n\n`;
527
+ if (this._retryInterval !== void 0) primingEvent = `id: ${primingEventId}\nretry: ${this._retryInterval}\ndata: \n\n`;
528
+ controller.enqueue(encoder.encode(primingEvent));
529
+ }
530
+ /**
531
+ * Handles `GET` requests for SSE stream
532
+ */
533
+ async handleGetRequest(req) {
534
+ if (!req.headers.get("accept")?.includes("text/event-stream")) {
535
+ this.onerror?.(/* @__PURE__ */ new Error("Not Acceptable: Client must accept text/event-stream"));
536
+ return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept text/event-stream");
537
+ }
538
+ const sessionError = this.validateSession(req);
539
+ if (sessionError) return sessionError;
540
+ const protocolError = this.validateProtocolVersion(req);
541
+ if (protocolError) return protocolError;
542
+ if (this._eventStore) {
543
+ const lastEventId = req.headers.get("last-event-id");
544
+ if (lastEventId) return this.replayEvents(lastEventId);
545
+ }
546
+ if (this._streamMapping.get(this._standaloneSseStreamId) !== void 0) {
547
+ this.onerror?.(/* @__PURE__ */ new Error("Conflict: Only one SSE stream is allowed per session"));
548
+ return this.createJsonErrorResponse(409, -32e3, "Conflict: Only one SSE stream is allowed per session");
549
+ }
550
+ const encoder = new TextEncoder();
551
+ let streamController;
552
+ let keepAliveTimer;
553
+ const readable = new ReadableStream({
554
+ start: (controller) => {
555
+ streamController = controller;
556
+ },
557
+ cancel: () => {
558
+ if (keepAliveTimer !== void 0) clearInterval(keepAliveTimer);
559
+ if (this._streamMapping.get(this._standaloneSseStreamId)?.controller === streamController) this._streamMapping.delete(this._standaloneSseStreamId);
560
+ }
561
+ });
562
+ const headers = {
563
+ "Content-Type": "text/event-stream",
564
+ "Cache-Control": "no-cache, no-transform",
565
+ Connection: "keep-alive",
566
+ "X-Accel-Buffering": "no"
567
+ };
568
+ if (this.sessionId !== void 0) headers["mcp-session-id"] = this.sessionId;
569
+ this._streamMapping.set(this._standaloneSseStreamId, {
570
+ controller: streamController,
571
+ encoder,
572
+ cleanup: () => {
573
+ if (keepAliveTimer !== void 0) clearInterval(keepAliveTimer);
574
+ this._streamMapping.delete(this._standaloneSseStreamId);
575
+ try {
576
+ streamController.close();
577
+ } catch {}
578
+ }
579
+ });
580
+ keepAliveTimer = this.startKeepAlive(streamController, encoder);
581
+ return new Response(readable, { headers });
582
+ }
583
+ /**
584
+ * Replays events that would have been sent after the specified event ID
585
+ * Only used when resumability is enabled
586
+ */
587
+ async replayEvents(lastEventId) {
588
+ if (!this._eventStore) {
589
+ this.onerror?.(/* @__PURE__ */ new Error("Event store not configured"));
590
+ return this.createJsonErrorResponse(400, -32e3, "Event store not configured");
591
+ }
592
+ try {
593
+ let streamId;
594
+ if (this._eventStore.getStreamIdForEventId) {
595
+ streamId = await this._eventStore.getStreamIdForEventId(lastEventId);
596
+ if (!streamId) {
597
+ this.onerror?.(/* @__PURE__ */ new Error("Invalid event ID format"));
598
+ return this.createJsonErrorResponse(400, -32e3, "Invalid event ID format");
599
+ }
600
+ if (this._streamMapping.get(streamId) !== void 0) {
601
+ this.onerror?.(/* @__PURE__ */ new Error("Conflict: Stream already has an active connection"));
602
+ return this.createJsonErrorResponse(409, -32e3, "Conflict: Stream already has an active connection");
603
+ }
604
+ }
605
+ const headers = {
606
+ "Content-Type": "text/event-stream",
607
+ "Cache-Control": "no-cache, no-transform",
608
+ Connection: "keep-alive",
609
+ "X-Accel-Buffering": "no"
610
+ };
611
+ if (this.sessionId !== void 0) headers["mcp-session-id"] = this.sessionId;
612
+ const encoder = new TextEncoder();
613
+ let streamController;
614
+ let keepAliveTimer;
615
+ let cancelled = false;
616
+ let replayedStreamId;
617
+ const readable = new ReadableStream({
618
+ start: (controller) => {
619
+ streamController = controller;
620
+ },
621
+ cancel: () => {
622
+ cancelled = true;
623
+ if (keepAliveTimer !== void 0) clearInterval(keepAliveTimer);
624
+ if (replayedStreamId !== void 0 && this._streamMapping.get(replayedStreamId)?.controller === streamController) this._streamMapping.delete(replayedStreamId);
625
+ }
626
+ });
627
+ const replayedEventIds = /* @__PURE__ */ new Set();
628
+ replayedStreamId = await this._eventStore.replayEventsAfter(lastEventId, { send: async (eventId, message) => {
629
+ replayedEventIds.add(eventId);
630
+ if (!this.writeSSEEvent(streamController, encoder, message, eventId)) try {
631
+ streamController.close();
632
+ } catch {}
633
+ } });
634
+ if (this._closed || cancelled) {
635
+ try {
636
+ streamController.close();
637
+ } catch {}
638
+ return this.createJsonErrorResponse(404, -32001, "Session not found");
639
+ }
640
+ this._streamMapping.get(replayedStreamId)?.cleanup();
641
+ this._streamMapping.set(replayedStreamId, {
642
+ controller: streamController,
643
+ encoder,
644
+ replayedEventIds,
645
+ cleanup: () => {
646
+ if (keepAliveTimer !== void 0) clearInterval(keepAliveTimer);
647
+ this._streamMapping.delete(replayedStreamId);
648
+ try {
649
+ streamController.close();
650
+ } catch {}
651
+ }
652
+ });
653
+ if (replayedStreamId !== this._standaloneSseStreamId) {
654
+ if (![...this._requestToStreamMapping.values()].includes(replayedStreamId)) {
655
+ this._streamMapping.delete(replayedStreamId);
656
+ try {
657
+ streamController.close();
658
+ } catch {}
659
+ }
660
+ }
661
+ if (this._streamMapping.get(replayedStreamId)?.controller === streamController) keepAliveTimer = this.startKeepAlive(streamController, encoder);
662
+ return new Response(readable, { headers });
663
+ } catch (error) {
664
+ this.onerror?.(error);
665
+ return this.createJsonErrorResponse(500, -32e3, "Error replaying events");
666
+ }
667
+ }
668
+ /**
669
+ * Writes an event to an SSE stream via controller with proper formatting
670
+ */
671
+ writeSSEEvent(controller, encoder, message, eventId) {
672
+ try {
673
+ let eventData = `event: message\n`;
674
+ if (eventId) eventData += `id: ${eventId}\n`;
675
+ eventData += `data: ${JSON.stringify(message)}\n\n`;
676
+ controller.enqueue(encoder.encode(eventData));
677
+ return true;
678
+ } catch (error) {
679
+ this.onerror?.(error);
680
+ return false;
681
+ }
682
+ }
683
+ /**
684
+ * Handles unsupported requests (`PUT`, `PATCH`, etc.)
685
+ */
686
+ handleUnsupportedRequest() {
687
+ this.onerror?.(/* @__PURE__ */ new Error("Method not allowed."));
688
+ return Response.json({
689
+ jsonrpc: "2.0",
690
+ error: {
691
+ code: -32e3,
692
+ message: "Method not allowed."
693
+ },
694
+ id: null
695
+ }, {
696
+ status: 405,
697
+ headers: {
698
+ Allow: "GET, POST, DELETE",
699
+ "Content-Type": "application/json"
700
+ }
701
+ });
702
+ }
703
+ /**
704
+ * Handles `POST` requests containing JSON-RPC messages
705
+ */
706
+ async handlePostRequest(req, options) {
707
+ try {
708
+ const acceptHeader = req.headers.get("accept");
709
+ if (!acceptHeader?.includes("application/json") || !acceptHeader.includes("text/event-stream")) {
710
+ this.onerror?.(/* @__PURE__ */ new Error("Not Acceptable: Client must accept both application/json and text/event-stream"));
711
+ return this.createJsonErrorResponse(406, -32e3, "Not Acceptable: Client must accept both application/json and text/event-stream");
712
+ }
713
+ if (!require_src.isJsonContentType(req.headers.get("content-type"))) {
714
+ this.onerror?.(/* @__PURE__ */ new Error("Unsupported Media Type: Content-Type must be application/json"));
715
+ return this.createJsonErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
716
+ }
717
+ const request = req;
718
+ let rawMessage;
719
+ if (options?.parsedBody === void 0) try {
720
+ const body = await readRequestBody(req, this._maxRequestBodySize);
721
+ if (body.tooLarge) {
722
+ const message = requestBodyTooLargeMessage(this._maxRequestBodySize);
723
+ this.onerror?.(new Error(message));
724
+ return this.createJsonErrorResponse(413, -32e3, message);
725
+ }
726
+ rawMessage = JSON.parse(body.text);
727
+ } catch (error) {
728
+ this.onerror?.(error);
729
+ return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON");
730
+ }
731
+ else rawMessage = options.parsedBody;
732
+ if (Array.isArray(rawMessage) && rawMessage.length > MAX_BATCH_SIZE) {
733
+ this.onerror?.(/* @__PURE__ */ new Error(`Invalid Request: Batch must not exceed ${MAX_BATCH_SIZE} messages`));
734
+ return this.createJsonErrorResponse(400, -32600, `Invalid Request: Batch must not exceed ${MAX_BATCH_SIZE} messages`);
735
+ }
736
+ let messages;
737
+ try {
738
+ messages = Array.isArray(rawMessage) ? rawMessage.map((msg) => _modelcontextprotocol_core_internal.JSONRPCMessageSchema.parse(msg)) : [_modelcontextprotocol_core_internal.JSONRPCMessageSchema.parse(rawMessage)];
739
+ } catch (error) {
740
+ this.onerror?.(error);
741
+ return this.createJsonErrorResponse(400, -32700, "Parse error: Invalid JSON-RPC message");
742
+ }
743
+ if (this._closed) return this.createJsonErrorResponse(404, -32001, "Session not found");
744
+ const isInitializationRequest = messages.some((element) => require_src.isInitializeRequest(element));
745
+ if (isInitializationRequest) {
746
+ if (this._initialized && this.sessionId !== void 0) {
747
+ this.onerror?.(/* @__PURE__ */ new Error("Invalid Request: Server already initialized"));
748
+ return this.createJsonErrorResponse(400, -32600, "Invalid Request: Server already initialized");
749
+ }
750
+ if (messages.length > 1) {
751
+ this.onerror?.(/* @__PURE__ */ new Error("Invalid Request: Only one initialization request is allowed"));
752
+ return this.createJsonErrorResponse(400, -32600, "Invalid Request: Only one initialization request is allowed");
753
+ }
754
+ this.sessionId = this.sessionIdGenerator?.();
755
+ this._initialized = true;
756
+ if (this.sessionId && this._onsessioninitialized) await Promise.resolve(this._onsessioninitialized(this.sessionId));
757
+ }
758
+ if (!isInitializationRequest) {
759
+ const sessionError = this.validateSession(req);
760
+ if (sessionError) return sessionError;
761
+ const protocolError = this.validateProtocolVersion(req);
762
+ if (protocolError) return protocolError;
763
+ }
764
+ if (this._closed) return this.createJsonErrorResponse(404, -32001, "Session not found");
765
+ let scopeChallengeResponse;
766
+ try {
767
+ scopeChallengeResponse = await this._checkScopeChallenge(messages, options?.authInfo);
768
+ } catch (error) {
769
+ this.onerror?.(error);
770
+ return this.createJsonErrorResponse(500, -32603, "Internal server error");
771
+ }
772
+ if (scopeChallengeResponse) return scopeChallengeResponse;
773
+ if (!messages.some((element) => require_src.isJSONRPCRequest(element))) {
774
+ for (const message of messages) this.onmessage?.(message, {
775
+ authInfo: options?.authInfo,
776
+ request
777
+ });
778
+ return new Response(null, { status: 202 });
779
+ }
780
+ const streamId = crypto.randomUUID();
781
+ const initRequest = messages.find((m) => require_src.isInitializeRequest(m));
782
+ const clientProtocolVersion = initRequest ? initRequest.params.protocolVersion : req.headers.get("mcp-protocol-version") ?? _modelcontextprotocol_core_internal.DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
783
+ if (this._enableJsonResponse) return new Promise((resolve) => {
784
+ this._streamMapping.set(streamId, {
785
+ resolveJson: resolve,
786
+ cleanup: () => {
787
+ this._streamMapping.delete(streamId);
788
+ }
789
+ });
790
+ for (const message of messages) if (require_src.isJSONRPCRequest(message)) this._requestToStreamMapping.set(message.id, streamId);
791
+ for (const message of messages) this.onmessage?.(message, {
792
+ authInfo: options?.authInfo,
793
+ request
794
+ });
795
+ });
796
+ const encoder = new TextEncoder();
797
+ let streamController;
798
+ let keepAliveTimer;
799
+ const readable = new ReadableStream({
800
+ start: (controller) => {
801
+ streamController = controller;
802
+ },
803
+ cancel: () => {
804
+ if (keepAliveTimer !== void 0) clearInterval(keepAliveTimer);
805
+ if (this._streamMapping.get(streamId)?.controller === streamController) this._streamMapping.delete(streamId);
806
+ }
807
+ });
808
+ const headers = {
809
+ "Content-Type": "text/event-stream",
810
+ "Cache-Control": "no-cache, no-transform",
811
+ Connection: "keep-alive",
812
+ "X-Accel-Buffering": "no"
813
+ };
814
+ if (this.sessionId !== void 0) headers["mcp-session-id"] = this.sessionId;
815
+ for (const message of messages) if (require_src.isJSONRPCRequest(message)) {
816
+ this._streamMapping.set(streamId, {
817
+ controller: streamController,
818
+ encoder,
819
+ cleanup: () => {
820
+ if (keepAliveTimer !== void 0) clearInterval(keepAliveTimer);
821
+ this._streamMapping.delete(streamId);
822
+ try {
823
+ streamController.close();
824
+ } catch {}
825
+ }
826
+ });
827
+ this._requestToStreamMapping.set(message.id, streamId);
828
+ }
829
+ await this.writePrimingEvent(streamController, encoder, streamId, clientProtocolVersion);
830
+ for (const message of messages) {
831
+ let closeSSEStream;
832
+ let closeStandaloneSSEStream;
833
+ if (require_src.isJSONRPCRequest(message) && this._eventStore && this.supportsEmptySSEData(clientProtocolVersion)) {
834
+ closeSSEStream = () => {
835
+ this.closeSSEStream(message.id);
836
+ };
837
+ closeStandaloneSSEStream = () => {
838
+ this.closeStandaloneSSEStream();
839
+ };
840
+ }
841
+ this.onmessage?.(message, {
842
+ authInfo: options?.authInfo,
843
+ request,
844
+ closeSSEStream,
845
+ closeStandaloneSSEStream
846
+ });
847
+ }
848
+ if (this._streamMapping.get(streamId)?.controller === streamController) keepAliveTimer = this.startKeepAlive(streamController, encoder);
849
+ return new Response(readable, {
850
+ status: 200,
851
+ headers
852
+ });
853
+ } catch (error) {
854
+ this.onerror?.(error);
855
+ return this.createJsonErrorResponse(400, -32700, "Parse error", { data: String(error) });
856
+ }
857
+ }
858
+ /**
859
+ * Handles `DELETE` requests to terminate sessions
860
+ */
861
+ async handleDeleteRequest(req) {
862
+ const sessionError = this.validateSession(req);
863
+ if (sessionError) return sessionError;
864
+ const protocolError = this.validateProtocolVersion(req);
865
+ if (protocolError) return protocolError;
866
+ try {
867
+ await Promise.resolve(this._onsessionclosed?.(this.sessionId));
868
+ return new Response(null, { status: 200 });
869
+ } finally {
870
+ await this.close();
871
+ }
872
+ }
873
+ /**
874
+ * Validates session ID for non-initialization requests.
875
+ * Returns `Response` error if invalid, `undefined` otherwise
876
+ */
877
+ validateSession(req) {
878
+ if (this.sessionIdGenerator === void 0) return;
879
+ if (!this._initialized) {
880
+ this.onerror?.(/* @__PURE__ */ new Error("Bad Request: Server not initialized"));
881
+ return this.createJsonErrorResponse(400, -32e3, "Bad Request: Server not initialized");
882
+ }
883
+ const sessionId = req.headers.get("mcp-session-id");
884
+ if (!sessionId) {
885
+ this.onerror?.(/* @__PURE__ */ new Error("Bad Request: Mcp-Session-Id header is required"));
886
+ return this.createJsonErrorResponse(400, -32e3, "Bad Request: Mcp-Session-Id header is required");
887
+ }
888
+ if (sessionId !== this.sessionId) {
889
+ this.onerror?.(/* @__PURE__ */ new Error("Session not found"));
890
+ return this.createJsonErrorResponse(404, -32001, "Session not found");
891
+ }
892
+ }
893
+ /**
894
+ * Validates the `MCP-Protocol-Version` header on incoming requests.
895
+ *
896
+ * For initialization: Version negotiation handles unknown versions gracefully
897
+ * (server responds with its supported version).
898
+ *
899
+ * For subsequent requests with `MCP-Protocol-Version` header:
900
+ * - Accept if in supported list
901
+ * - 400 if unsupported
902
+ *
903
+ * For HTTP requests without the `MCP-Protocol-Version` header:
904
+ * - Accept and default to the version negotiated at initialization
905
+ */
906
+ validateProtocolVersion(req) {
907
+ const protocolVersion = req.headers.get("mcp-protocol-version");
908
+ if (protocolVersion !== null && !this._supportedProtocolVersions.includes(protocolVersion)) {
909
+ const error = `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${this._supportedProtocolVersions.join(", ")})`;
910
+ this.onerror?.(new Error(error));
911
+ return this.createJsonErrorResponse(400, -32e3, error);
912
+ }
913
+ }
914
+ async close() {
915
+ if (this._closed) return;
916
+ this._closed = true;
917
+ for (const { cleanup } of this._streamMapping.values()) cleanup();
918
+ this._streamMapping.clear();
919
+ this._requestResponseMap.clear();
920
+ this.onclose?.();
921
+ }
922
+ /**
923
+ * Close an SSE stream for a specific request, triggering client reconnection.
924
+ * Use this to implement polling behavior during long-running operations -
925
+ * client will reconnect after the retry interval specified in the priming event.
926
+ */
927
+ closeSSEStream(requestId) {
928
+ const streamId = this._requestToStreamMapping.get(requestId);
929
+ if (!streamId) return;
930
+ const stream = this._streamMapping.get(streamId);
931
+ if (stream) stream.cleanup();
932
+ }
933
+ /**
934
+ * Close the standalone `GET` SSE stream, triggering client reconnection.
935
+ * Use this to implement polling behavior for server-initiated notifications.
936
+ */
937
+ closeStandaloneSSEStream() {
938
+ const stream = this._streamMapping.get(this._standaloneSseStreamId);
939
+ if (stream) stream.cleanup();
940
+ }
941
+ async send(message, options) {
942
+ let requestId = options?.relatedRequestId;
943
+ if (require_src.isJSONRPCResultResponse(message) || require_src.isJSONRPCErrorResponse(message)) requestId = message.id;
944
+ if (requestId === void 0) {
945
+ if (require_src.isJSONRPCResultResponse(message) || require_src.isJSONRPCErrorResponse(message)) throw new Error("Cannot send a response on a standalone SSE stream unless resuming a previous client request");
946
+ let eventId;
947
+ if (this._eventStore) eventId = await this._eventStore.storeEvent(this._standaloneSseStreamId, message);
948
+ const standaloneSse = this._streamMapping.get(this._standaloneSseStreamId);
949
+ if (standaloneSse === void 0) return;
950
+ if (standaloneSse.controller && standaloneSse.encoder && (eventId === void 0 || !standaloneSse.replayedEventIds?.has(eventId))) this.writeSSEEvent(standaloneSse.controller, standaloneSse.encoder, message, eventId);
951
+ return;
952
+ }
953
+ const streamId = this._requestToStreamMapping.get(requestId);
954
+ if (!streamId) throw new Error(`No connection established for request ID: ${String(requestId)}`);
955
+ let stream = this._streamMapping.get(streamId);
956
+ if (!this._enableJsonResponse) {
957
+ let eventId;
958
+ if (this._eventStore) {
959
+ eventId = await this._eventStore.storeEvent(streamId, message);
960
+ stream = this._streamMapping.get(streamId);
961
+ }
962
+ if (stream?.controller && stream?.encoder && (eventId === void 0 || !stream.replayedEventIds?.has(eventId))) this.writeSSEEvent(stream.controller, stream.encoder, message, eventId);
963
+ }
964
+ if (require_src.isJSONRPCResultResponse(message) || require_src.isJSONRPCErrorResponse(message)) {
965
+ this._requestResponseMap.set(requestId, message);
966
+ const relatedIds = [...this._requestToStreamMapping.entries()].filter(([_, sid]) => sid === streamId).map(([id]) => id);
967
+ if (relatedIds.every((id) => this._requestResponseMap.has(id))) {
968
+ if (!stream) {
969
+ if (this._enableJsonResponse) throw new Error(`No connection established for request ID: ${String(requestId)}`);
970
+ if (!this._eventStore) {
971
+ this.onerror?.(/* @__PURE__ */ new Error(`Response for request ID ${String(requestId)} is undeliverable: per-request stream is disconnected and no eventStore is configured`));
972
+ for (const id of relatedIds) {
973
+ this._requestResponseMap.delete(id);
974
+ this._requestToStreamMapping.delete(id);
975
+ }
976
+ return;
977
+ }
978
+ for (const id of relatedIds) {
979
+ this._requestResponseMap.delete(id);
980
+ this._requestToStreamMapping.delete(id);
981
+ }
982
+ return;
983
+ }
984
+ if (this._enableJsonResponse && stream.resolveJson) {
985
+ const headers = { "Content-Type": "application/json" };
986
+ if (this.sessionId !== void 0) headers["mcp-session-id"] = this.sessionId;
987
+ const responses = relatedIds.map((id) => this._requestResponseMap.get(id));
988
+ if (responses.length === 1) stream.resolveJson(Response.json(responses[0], {
989
+ status: 200,
990
+ headers
991
+ }));
992
+ else stream.resolveJson(Response.json(responses, {
993
+ status: 200,
994
+ headers
995
+ }));
996
+ stream.cleanup();
997
+ } else stream.cleanup();
998
+ for (const id of relatedIds) {
999
+ this._requestResponseMap.delete(id);
1000
+ this._requestToStreamMapping.delete(id);
1001
+ }
1002
+ }
1003
+ }
1004
+ }
1005
+ };
1006
+
1007
+ //#endregion
1008
+ //#region src/server/createMcpHandler.ts
1009
+ /**
1010
+ * The JSON-RPC id to echo on an entry-built error response: the body's `id`
1011
+ * when the body is a single JSON-RPC request whose id is a string or number,
1012
+ * `null` otherwise. Error responses must carry the id of the request they
1013
+ * correspond to whenever it could be read; `null` is reserved for the cases
1014
+ * where no single request id is determinable — unparseable bodies, body-less
1015
+ * methods, notifications, posted responses and batch arrays.
1016
+ */
1017
+ function echoableRequestId(body) {
1018
+ if (body === null || typeof body !== "object" || Array.isArray(body)) return null;
1019
+ const { method, id } = body;
1020
+ if (typeof method !== "string") return null;
1021
+ return typeof id === "string" || typeof id === "number" ? id : null;
1022
+ }
1023
+ function jsonRpcErrorResponse(httpStatus, code, message, data, id = null) {
1024
+ return Response.json({
1025
+ jsonrpc: "2.0",
1026
+ error: {
1027
+ code,
1028
+ message,
1029
+ ...data !== void 0 && { data }
1030
+ },
1031
+ id
1032
+ }, { status: httpStatus });
1033
+ }
1034
+ function rejectionResponse(rejection, id = null) {
1035
+ return jsonRpcErrorResponse(rejection.httpStatus, rejection.code, rejection.message, rejection.data, id);
1036
+ }
1037
+ function toError(value) {
1038
+ return value instanceof Error ? value : new Error(String(value));
1039
+ }
1040
+ function internalServerErrorResponse(id = null) {
1041
+ return jsonRpcErrorResponse(500, -32603, "Internal server error", void 0, id);
1042
+ }
1043
+ /** Throws when the factory returned an instance that is still connected to another exchange. */
1044
+ function assertNotServing(server) {
1045
+ if (server.transport !== void 0) throw new Error("The factory returned an instance that is still serving another request. Return a new instance for each request.");
1046
+ }
1047
+ /**
1048
+ * The entry's default legacy serving (`legacy: 'stateless'`): per-request
1049
+ * stateless serving of 2025-era traffic using the same factory as the modern
1050
+ * path. Exported as a standalone building block for hand-wired compositions
1051
+ * (for example mounting legacy stateless serving on its own route next to a
1052
+ * strict modern endpoint).
1053
+ *
1054
+ * Each POST is served by a fresh instance from the factory connected to a
1055
+ * fresh streamable HTTP transport constructed with only
1056
+ * `sessionIdGenerator: undefined` — the established stateless idiom, unchanged.
1057
+ * Because serving is per-request and stateless, GET and DELETE (2025 session
1058
+ * operations) are answered with `405` / `Method not allowed.`, exactly like the
1059
+ * canonical stateless example.
1060
+ *
1061
+ * The optional `onerror` callback receives factory and serving failures on
1062
+ * this leg (reporting only — the response stays the 500 internal-error body).
1063
+ * The entry passes its own `onerror` here when expanding the default, so
1064
+ * legacy-leg failures are never silently swallowed.
1065
+ */
1066
+ function createLegacyStatelessFallback(factory, onerror, keepAliveMs, maxRequestBodySize) {
1067
+ return async (request, options) => {
1068
+ if (request.method.toUpperCase() !== "POST") return jsonRpcErrorResponse(405, -32e3, "Method not allowed.");
1069
+ try {
1070
+ const product = await factory({
1071
+ era: "legacy",
1072
+ ...options?.authInfo !== void 0 && { authInfo: options.authInfo },
1073
+ requestInfo: request
1074
+ });
1075
+ const transport = new WebStandardStreamableHTTPServerTransport({
1076
+ sessionIdGenerator: void 0,
1077
+ ...keepAliveMs !== void 0 && { keepAliveMs },
1078
+ ...maxRequestBodySize !== void 0 && { maxRequestBodySize }
1079
+ });
1080
+ await product.connect(transport);
1081
+ const teardown = () => {
1082
+ transport.close().catch(() => {});
1083
+ product.close().catch(() => {});
1084
+ };
1085
+ request.signal?.addEventListener("abort", teardown, { once: true });
1086
+ const response = await transport.handleRequest(request, {
1087
+ ...options?.authInfo !== void 0 && { authInfo: options.authInfo },
1088
+ ...options?.parsedBody !== void 0 && { parsedBody: options.parsedBody }
1089
+ });
1090
+ if (response.body === null || require_src.mediaTypeEssence(response.headers.get("content-type")) !== "text/event-stream") {
1091
+ teardown();
1092
+ return response;
1093
+ }
1094
+ const reader = response.body.getReader();
1095
+ let toreDown = false;
1096
+ const completeExchange = () => {
1097
+ if (!toreDown) {
1098
+ toreDown = true;
1099
+ teardown();
1100
+ }
1101
+ };
1102
+ const monitoredBody = new ReadableStream({
1103
+ pull: async (controller) => {
1104
+ try {
1105
+ const { done, value } = await reader.read();
1106
+ if (done) {
1107
+ completeExchange();
1108
+ controller.close();
1109
+ return;
1110
+ }
1111
+ if (value !== void 0) controller.enqueue(value);
1112
+ } catch (error) {
1113
+ completeExchange();
1114
+ controller.error(error);
1115
+ }
1116
+ },
1117
+ cancel: (reason) => {
1118
+ completeExchange();
1119
+ return reader.cancel(reason).catch(() => {});
1120
+ }
1121
+ });
1122
+ return new Response(monitoredBody, {
1123
+ status: response.status,
1124
+ statusText: response.statusText,
1125
+ headers: response.headers
1126
+ });
1127
+ } catch (error) {
1128
+ try {
1129
+ onerror?.(toError(error));
1130
+ } catch {}
1131
+ return internalServerErrorResponse(echoableRequestId(options?.parsedBody));
1132
+ }
1133
+ };
1134
+ }
1135
+ function legacyStatelessFallback(factory, onerror, options) {
1136
+ return createLegacyStatelessFallback(factory, onerror, void 0, resolveMaxRequestBodySize(options?.maxRequestBodySize));
1137
+ }
1138
+ /**
1139
+ * Read the SEP-2243 standard request headers off the inbound request.
1140
+ *
1141
+ * Both halves of the standard-header story need them — the body-primary
1142
+ * classifier for its cross-check cells, and
1143
+ * {@linkcode validateStandardRequestHeaders} for the presence half — and a
1144
+ * header read at one site but not the other is precisely how a required header
1145
+ * goes unenforced: that divergence is what let a modern POST omitting
1146
+ * `MCP-Protocol-Version` be served. Read them here once so a header added to
1147
+ * {@linkcode InboundHttpRequest} reaches both sites together.
1148
+ */
1149
+ function standardHeadersOf(request) {
1150
+ return {
1151
+ protocolVersionHeader: request.headers.get("mcp-protocol-version") ?? void 0,
1152
+ mcpMethodHeader: request.headers.get("mcp-method") ?? void 0,
1153
+ mcpNameHeader: request.headers.get("mcp-name") ?? void 0
1154
+ };
1155
+ }
1156
+ /**
1157
+ * The entry's classification step: read the request body exactly once (unless
1158
+ * a pre-parsed body is supplied) and classify the request with
1159
+ * {@linkcode classifyInboundRequest}. This is the single code path behind both
1160
+ * {@linkcode createMcpHandler}'s routing and the exported
1161
+ * {@linkcode isLegacyRequest} predicate, so the two can never disagree.
1162
+ *
1163
+ * Pass `needsForward: false` when the caller never reads `forwardRequest` —
1164
+ * the body-preserving clone is then skipped and `forwardRequest` is the
1165
+ * (consumed) input request.
1166
+ */
1167
+ async function classifyEntryRequest(request, providedParsedBody, needsForward = true, maxRequestBodySize = DEFAULT_MAX_REQUEST_BODY_SIZE) {
1168
+ const httpMethod = request.method.toUpperCase();
1169
+ let body;
1170
+ let parsedBody = providedParsedBody;
1171
+ let forwardRequest = request;
1172
+ let unparseable = false;
1173
+ if (httpMethod === "POST") {
1174
+ if (parsedBody === void 0) {
1175
+ if (needsForward) forwardRequest = request.clone();
1176
+ let bodyText;
1177
+ try {
1178
+ const read = await readRequestBody(request, maxRequestBodySize);
1179
+ if (read.tooLarge) return { step: "body-too-large" };
1180
+ bodyText = read.text;
1181
+ } catch {
1182
+ return { step: "unreadable-body" };
1183
+ }
1184
+ try {
1185
+ body = bodyText.length === 0 ? void 0 : JSON.parse(bodyText);
1186
+ } catch {
1187
+ unparseable = true;
1188
+ }
1189
+ if (!unparseable && body !== void 0) parsedBody = body;
1190
+ } else body = parsedBody;
1191
+ if (unparseable || body === void 0) return {
1192
+ step: "no-json-body",
1193
+ forwardRequest
1194
+ };
1195
+ }
1196
+ return {
1197
+ step: "classified",
1198
+ outcome: require_src.classifyInboundRequest({
1199
+ httpMethod,
1200
+ ...standardHeadersOf(request),
1201
+ ...body !== void 0 && { body }
1202
+ }),
1203
+ body,
1204
+ parsedBody,
1205
+ forwardRequest
1206
+ };
1207
+ }
1208
+ /**
1209
+ * Whether {@linkcode createMcpHandler} would route this request to its legacy
1210
+ * (2025-era) serving rather than the modern (2026-07-28) path.
1211
+ *
1212
+ * Call it with just the request: `await isLegacyRequest(request)`. For a
1213
+ * `POST` the body is read from an internal clone, so the request you pass
1214
+ * stays fully readable for whichever handler you route it to — no second
1215
+ * argument is needed. (In a Node `(req, res)` handler, build that `Request`
1216
+ * with `toWebRequest(req)` from `@modelcontextprotocol/node`; behind a body
1217
+ * parser, which has already drained the Node stream, build it as
1218
+ * `toWebRequest(req, req.body)` so the bytes come from the parsed body —
1219
+ * either way the predicate still takes just the request.) The optional
1220
+ * `parsedBody` is a perf escape hatch for a body you already hold parsed:
1221
+ * pass it and the predicate classifies from the value directly, reading and
1222
+ * cloning nothing. It is needed, not just faster, when the request's own
1223
+ * body was already read — the internal clone is then impossible (cloning a
1224
+ * used body throws a `TypeError`), so such a single-argument call rejects
1225
+ * instead of guessing.
1226
+ *
1227
+ * This is the entry's own classification step exported as a predicate — it
1228
+ * runs exactly the code `createMcpHandler` runs to make the routing decision,
1229
+ * not a re-implementation — so a hand-wired composition that branches on it
1230
+ * can never disagree with the entry. It is classification only: hand-wired
1231
+ * compositions must validate Content-Type themselves (415 for POSTs whose
1232
+ * media type is not `application/json`, via {@linkcode isJsonContentType})
1233
+ * before dispatching either leg — routing the legacy leg into the SDK
1234
+ * transports gets their built-in check, but a custom modern leg has none. Use it to keep an existing legacy
1235
+ * deployment (for example a sessionful streamable HTTP wiring) serving 2025
1236
+ * traffic next to a strict modern endpoint, now that the entry has no
1237
+ * handler-valued `legacy` option:
1238
+ *
1239
+ * ```ts
1240
+ * import { createMcpHandler, isLegacyRequest } from '@modelcontextprotocol/server';
1241
+ *
1242
+ * const modern = createMcpHandler(factory, { legacy: 'reject' });
1243
+ *
1244
+ * export default {
1245
+ * async fetch(request: Request): Promise<Response> {
1246
+ * if (await isLegacyRequest(request)) {
1247
+ * // e.g. an existing sessionful WebStandardStreamableHTTPServerTransport wiring
1248
+ * return myExistingLegacyHandler(request);
1249
+ * }
1250
+ * return modern.fetch(request);
1251
+ * }
1252
+ * };
1253
+ * ```
1254
+ *
1255
+ * Semantics (identical to the entry's routing):
1256
+ *
1257
+ * - Returns `true` only for requests with no per-request `_meta` envelope
1258
+ * claim: claim-less POSTs (including the `initialize` handshake and 2025-era
1259
+ * notification POSTs without a modern protocol-version header), body-less
1260
+ * GET/DELETE session operations, all-legacy JSON-RPC batch arrays, posted
1261
+ * JSON-RPC responses, and POSTs whose body is empty or not valid JSON.
1262
+ * - Returns `false` for everything the modern path answers, including its
1263
+ * validation-ladder rejections: a request carrying the envelope claim (even
1264
+ * one naming a revision the endpoint does not serve — the modern path
1265
+ * answers it with the unsupported-protocol-version error), a malformed
1266
+ * envelope behind a present claim (answered `-32602`), a request whose
1267
+ * `MCP-Protocol-Version` header names a modern revision but that lacks the
1268
+ * envelope (`-32602`), header/body mismatches (`-32020`), and a POST body
1269
+ * over the size limit (413). Consumers
1270
+ * routing on the predicate must send `false` traffic to the modern handler,
1271
+ * never to a legacy handler — the modern path owns those error answers.
1272
+ * - `server/discover` probes sent by negotiating clients always carry the
1273
+ * envelope claim, so they are never legacy; a hand-built claim-less POST to
1274
+ * a method named `server/discover` has no claim and classifies legacy,
1275
+ * exactly as the entry itself routes it.
1276
+ */
1277
+ async function isLegacyRequest(request, parsedBody, options) {
1278
+ const maxRequestBodySize = resolveMaxRequestBodySize(options?.maxRequestBodySize);
1279
+ const classified = await classifyEntryRequest(parsedBody === void 0 && request.method.toUpperCase() === "POST" ? request.clone() : request, parsedBody, false, maxRequestBodySize);
1280
+ return classified.step === "no-json-body" || classified.step === "classified" && classified.outcome.kind === "legacy";
1281
+ }
1282
+ /**
1283
+ * Creates an HTTP handler that serves the 2026-07-28 protocol revision from a
1284
+ * per-request server factory and, by default, falls back to old-school
1285
+ * stateless serving for 2025-era traffic. Pass `legacy: 'reject'` for a
1286
+ * modern-only strict endpoint.
1287
+ *
1288
+ * Mounting: `handler.fetch` is the web-standard face (Cloudflare Workers,
1289
+ * Deno, Bun, Hono's `c.req.raw`); for Express/Fastify/plain `node:http`, wrap
1290
+ * the handler once with `toNodeHandler(handler)` from
1291
+ * `@modelcontextprotocol/node`. When mounting bare on a fetch-native runtime,
1292
+ * put Origin/Host validation in front of the handler — the entry itself is
1293
+ * deliberately validation-free:
1294
+ *
1295
+ * ```ts
1296
+ * import { hostHeaderValidationResponse, originValidationResponse, localhostAllowedHostnames, localhostAllowedOrigins } from '@modelcontextprotocol/server';
1297
+ *
1298
+ * export default {
1299
+ * async fetch(request: Request): Promise<Response> {
1300
+ * const rejected =
1301
+ * hostHeaderValidationResponse(request, localhostAllowedHostnames()) ??
1302
+ * originValidationResponse(request, localhostAllowedOrigins());
1303
+ * return rejected ?? handler.fetch(request);
1304
+ * }
1305
+ * };
1306
+ * ```
1307
+ *
1308
+ * Use ONE factory for both legs: the same tools/resources/prompts definition
1309
+ * backs the modern path and the stateless legacy fallback, so the two eras can
1310
+ * never drift apart. To keep an existing legacy deployment (for example a
1311
+ * sessionful streamable HTTP wiring) serving 2025 traffic instead of the
1312
+ * stateless fallback, route in user land with {@linkcode isLegacyRequest} in
1313
+ * front of a strict handler — see that predicate's documentation for the
1314
+ * pattern. Power users composing transport-neutral routing can also use the
1315
+ * exported building blocks directly: {@linkcode classifyInboundRequest} for
1316
+ * the era decision and `PerRequestHTTPServerTransport` for single-exchange
1317
+ * serving — such compositions must reject POSTs whose Content-Type media type
1318
+ * is not `application/json` (415) before parsing the body, using
1319
+ * {@linkcode isJsonContentType}; neither building block performs this
1320
+ * validation itself.
1321
+ *
1322
+ * The entry performs no token verification: `authInfo` given to `fetch` is
1323
+ * passed through to handlers and the factory as-is and is never derived from
1324
+ * request headers.
1325
+ */
1326
+ function createMcpHandler(factory, options = {}) {
1327
+ const { legacy, onerror, responseMode } = options;
1328
+ const maxRequestBodySize = resolveMaxRequestBodySize(options.maxRequestBodySize);
1329
+ if (typeof legacy === "function") throw new TypeError("The 'legacy' option only accepts 'stateless' or 'reject', not a handler function. To serve 2025-era traffic with your own handler, route in user land with the exported isLegacyRequest(request) predicate in front of a strict (legacy: 'reject') handler.");
1330
+ /** Modern per-request instances with an exchange still in flight (close() tears these down). */
1331
+ const inflight = /* @__PURE__ */ new Set();
1332
+ let closed = false;
1333
+ const reportError = (error) => {
1334
+ try {
1335
+ onerror?.(error);
1336
+ } catch {}
1337
+ };
1338
+ const bus = options.bus ?? new require_mcp.InMemoryServerEventBus(reportError);
1339
+ const notify = require_mcp.createServerNotifier(bus);
1340
+ const listenRouter = require_mcp.createListenRouter({
1341
+ bus,
1342
+ maxSubscriptions: options.maxSubscriptions ?? require_mcp.DEFAULT_MAX_SUBSCRIPTIONS,
1343
+ keepAliveMs: options.keepAliveMs ?? require_mcp.DEFAULT_SSE_KEEP_ALIVE_MS,
1344
+ onerror: reportError
1345
+ });
1346
+ if (responseMode === "json") console.warn("responseMode: 'json' drops mid-call notifications. subscriptions/listen streams are always served over SSE regardless; other notifications emitted before a result are dropped.");
1347
+ const legacyHandler = legacy === "reject" ? void 0 : createLegacyStatelessFallback(factory, reportError, options.keepAliveMs, maxRequestBodySize);
1348
+ async function serveModern(route, request, authInfo) {
1349
+ const claimedRevision = route.classification.revision;
1350
+ if (claimedRevision === void 0 || !require_src.SUPPORTED_MODERN_PROTOCOL_VERSIONS.includes(claimedRevision)) {
1351
+ const error = new require_src.UnsupportedProtocolVersionError({
1352
+ supported: [...require_src.SUPPORTED_MODERN_PROTOCOL_VERSIONS],
1353
+ requested: claimedRevision ?? "unknown"
1354
+ });
1355
+ reportError(error);
1356
+ return jsonRpcErrorResponse(400, error.code, error.message, error.data, echoableRequestId(route.message));
1357
+ }
1358
+ const stdHeaderRejection = require_src.validateStandardRequestHeaders({
1359
+ httpMethod: request.method,
1360
+ ...standardHeadersOf(request)
1361
+ }, route);
1362
+ if (stdHeaderRejection !== void 0) {
1363
+ reportError(/* @__PURE__ */ new Error(`Rejected inbound request (${stdHeaderRejection.cell}): ${stdHeaderRejection.message}`));
1364
+ return rejectionResponse(stdHeaderRejection, echoableRequestId(route.message));
1365
+ }
1366
+ const meta = route.messageKind === "request" ? require_src.requestMetaOf(route.message.params) : void 0;
1367
+ const declaredClientCapabilities = meta?.[_modelcontextprotocol_core_internal.CLIENT_CAPABILITIES_META_KEY];
1368
+ if (route.messageKind === "request") {
1369
+ const required = require_src.requiredClientCapabilitiesForRequest(route.message.method);
1370
+ if (required !== void 0) {
1371
+ const missing = require_src.missingClientCapabilities(required, declaredClientCapabilities);
1372
+ if (missing !== void 0) {
1373
+ const error = new require_src.MissingRequiredClientCapabilityError({ requiredCapabilities: missing });
1374
+ reportError(error);
1375
+ return jsonRpcErrorResponse(require_src.httpStatusForErrorCode(error.code, "ladder"), error.code, error.message, error.data, route.message.id);
1376
+ }
1377
+ }
1378
+ }
1379
+ const product = await factory({
1380
+ era: "modern",
1381
+ ...authInfo !== void 0 && { authInfo },
1382
+ requestInfo: request
1383
+ });
1384
+ const server = product instanceof require_mcp.McpServer ? product.server : product;
1385
+ assertNotServing(server);
1386
+ if (route.messageKind === "request" && route.message.method === "subscriptions/listen") {
1387
+ const capabilities = server.getCapabilities();
1388
+ const serverInfo = require_mcp.serverIdentityOf(server);
1389
+ product.close().catch(reportError);
1390
+ return listenRouter.serve(route.message, request.signal, capabilities, serverInfo);
1391
+ }
1392
+ if (route.messageKind === "request" && route.message.method === "tools/call" && product instanceof require_mcp.McpServer) {
1393
+ const callParams = route.message.params;
1394
+ const toolName = typeof callParams?.name === "string" ? callParams.name : void 0;
1395
+ const inputSchema = toolName === void 0 ? void 0 : product.toolInputSchemaJson(toolName);
1396
+ if (inputSchema !== void 0) {
1397
+ const scan = require_src.scanXMcpHeaderDeclarations(inputSchema);
1398
+ if (scan.valid && scan.declarations.length > 0) {
1399
+ const rejection = require_src.validateMcpParamHeaders(scan.declarations, callParams?.arguments, request.headers);
1400
+ if (rejection !== void 0) {
1401
+ product.close().catch(reportError);
1402
+ reportError(/* @__PURE__ */ new Error(`Rejected inbound request (${rejection.cell}): ${rejection.message}`));
1403
+ return rejectionResponse(rejection, route.message.id);
1404
+ }
1405
+ }
1406
+ }
1407
+ }
1408
+ if (route.messageKind === "request" && product instanceof require_mcp.McpServer) try {
1409
+ const challenge = await require_mcp.findScopeChallenge([route.message], authInfo, (context) => product.resolveScopeChallenge(context));
1410
+ if (challenge !== void 0) {
1411
+ product.close().catch(reportError);
1412
+ return require_mcp.createScopeChallengeResponse(challenge, require_mcp.scopeChallengeResourceMetadataUrl(authInfo));
1413
+ }
1414
+ } catch (error) {
1415
+ product.close().catch(reportError);
1416
+ reportError(toError(error));
1417
+ return internalServerErrorResponse(route.message.id);
1418
+ }
1419
+ assertNotServing(server);
1420
+ require_src.setNegotiatedProtocolVersion(server, claimedRevision);
1421
+ require_mcp.installModernOnlyHandlers(server, require_src.SUPPORTED_MODERN_PROTOCOL_VERSIONS);
1422
+ if (meta !== void 0) require_mcp.seedClientIdentityFromEnvelope(server, {
1423
+ clientInfo: meta[_modelcontextprotocol_core_internal.CLIENT_INFO_META_KEY],
1424
+ clientCapabilities: declaredClientCapabilities
1425
+ });
1426
+ const previousOnClose = server.onclose;
1427
+ inflight.add(server);
1428
+ const onExchangeClose = () => {
1429
+ inflight.delete(server);
1430
+ if (server.onclose === onExchangeClose) server.onclose = previousOnClose;
1431
+ previousOnClose?.();
1432
+ };
1433
+ server.onclose = onExchangeClose;
1434
+ try {
1435
+ const response = await invoke(product, route.message, {
1436
+ classification: route.classification,
1437
+ request,
1438
+ ...authInfo !== void 0 && { authInfo },
1439
+ ...responseMode !== void 0 && { responseMode },
1440
+ ...options.keepAliveMs !== void 0 && { keepAliveMs: options.keepAliveMs }
1441
+ });
1442
+ if (route.messageKind === "notification") queueMicrotask(() => void server.close().catch(() => {}));
1443
+ return response;
1444
+ } catch (error) {
1445
+ if (error instanceof require_src.SdkError && error.code === require_src.SdkErrorCode.ConnectionClosed) return new Response(null, { status: 499 });
1446
+ await server.close().catch(() => {});
1447
+ inflight.delete(server);
1448
+ reportError(toError(error));
1449
+ return internalServerErrorResponse(echoableRequestId(route.message));
1450
+ }
1451
+ }
1452
+ async function serveLegacyRoute(route, forwardRequest, authInfo, parsedBody) {
1453
+ if (legacyHandler !== void 0) return legacyHandler(forwardRequest, {
1454
+ ...authInfo !== void 0 && { authInfo },
1455
+ ...parsedBody !== void 0 && { parsedBody }
1456
+ });
1457
+ const strict = require_src.modernOnlyStrictRejection(route, require_src.SUPPORTED_MODERN_PROTOCOL_VERSIONS);
1458
+ if (strict === void 0) return new Response(null, { status: 202 });
1459
+ reportError(/* @__PURE__ */ new Error(`Rejected 2025-era request on a modern-only endpoint (${strict.cell}): ${strict.message}`));
1460
+ return rejectionResponse(strict, echoableRequestId(parsedBody));
1461
+ }
1462
+ async function handle(request, requestOptions) {
1463
+ const authInfo = requestOptions?.authInfo;
1464
+ if (request.method.toUpperCase() === "POST" && !require_src.isJsonContentType(request.headers.get("content-type"))) {
1465
+ reportError(/* @__PURE__ */ new Error("Unsupported Media Type: Content-Type must be application/json"));
1466
+ return jsonRpcErrorResponse(415, -32e3, "Unsupported Media Type: Content-Type must be application/json");
1467
+ }
1468
+ const classified = await classifyEntryRequest(request, requestOptions?.parsedBody, true, maxRequestBodySize);
1469
+ if (classified.step === "unreadable-body") return jsonRpcErrorResponse(400, -32700, "Parse error: the request body could not be read");
1470
+ if (classified.step === "body-too-large") return jsonRpcErrorResponse(413, -32e3, requestBodyTooLargeMessage(maxRequestBodySize));
1471
+ if (classified.step === "no-json-body") {
1472
+ if (legacyHandler !== void 0) return legacyHandler(classified.forwardRequest, { ...authInfo !== void 0 && { authInfo } });
1473
+ return jsonRpcErrorResponse(400, -32700, "Parse error: the request body is not valid JSON");
1474
+ }
1475
+ const { outcome, body, parsedBody, forwardRequest } = classified;
1476
+ try {
1477
+ switch (outcome.kind) {
1478
+ case "reject":
1479
+ reportError(/* @__PURE__ */ new Error(`Rejected inbound request (${outcome.cell}): ${outcome.message}`));
1480
+ return rejectionResponse(outcome, echoableRequestId(body));
1481
+ case "modern": return await serveModern(outcome, request, authInfo);
1482
+ case "legacy": return await serveLegacyRoute(outcome, forwardRequest, authInfo, parsedBody);
1483
+ }
1484
+ } catch (error) {
1485
+ reportError(toError(error));
1486
+ return internalServerErrorResponse(echoableRequestId(body));
1487
+ }
1488
+ }
1489
+ const fetchFace = async (request, requestOptions) => {
1490
+ if (closed) throw new Error("This MCP handler has been closed");
1491
+ try {
1492
+ return await handle(request, requestOptions);
1493
+ } catch (error) {
1494
+ reportError(toError(error));
1495
+ return internalServerErrorResponse(echoableRequestId(requestOptions?.parsedBody));
1496
+ }
1497
+ };
1498
+ return {
1499
+ fetch: fetchFace,
1500
+ notify,
1501
+ bus,
1502
+ close: async () => {
1503
+ closed = true;
1504
+ listenRouter.closeAll();
1505
+ const closing = [...inflight].map((server) => server.close().catch(() => {}));
1506
+ inflight.clear();
1507
+ await Promise.all(closing);
1508
+ }
1509
+ };
1510
+ }
1511
+
1512
+ //#endregion
1513
+ //#region src/server/middleware/hostHeaderValidation.ts
1514
+ /**
1515
+ * Parse and validate a `Host` header against an allowlist of hostnames (port-agnostic).
1516
+ *
1517
+ * - Input host header may include a port (e.g. `localhost:3000`) or IPv6 brackets (e.g. `[::1]:3000`).
1518
+ * - Allowlist items should be hostnames only (no ports). For IPv6, include brackets (e.g. `[::1]`).
1519
+ */
1520
+ function validateHostHeader(hostHeader, allowedHostnames) {
1521
+ if (!hostHeader) return {
1522
+ ok: false,
1523
+ errorCode: "missing_host",
1524
+ message: "Missing Host header"
1525
+ };
1526
+ let hostname;
1527
+ try {
1528
+ hostname = new URL(`http://${hostHeader}`).hostname;
1529
+ } catch {
1530
+ return {
1531
+ ok: false,
1532
+ errorCode: "invalid_host_header",
1533
+ message: `Invalid Host header: ${hostHeader}`,
1534
+ hostHeader
1535
+ };
1536
+ }
1537
+ if (!allowedHostnames.includes(hostname)) return {
1538
+ ok: false,
1539
+ errorCode: "invalid_host",
1540
+ message: `Invalid Host: ${hostname}`,
1541
+ hostHeader,
1542
+ hostname
1543
+ };
1544
+ return {
1545
+ ok: true,
1546
+ hostname
1547
+ };
1548
+ }
1549
+ /**
1550
+ * Convenience allowlist for `localhost` DNS rebinding protection.
1551
+ */
1552
+ function localhostAllowedHostnames() {
1553
+ return [
1554
+ "localhost",
1555
+ "127.0.0.1",
1556
+ "[::1]"
1557
+ ];
1558
+ }
1559
+ /**
1560
+ * Web-standard `Request` helper for DNS rebinding protection.
1561
+ * @example
1562
+ * ```ts source="./hostHeaderValidation.examples.ts#hostHeaderValidationResponse_basicUsage"
1563
+ * const result = validateHostHeader(req.headers.get('host'), ['localhost']);
1564
+ * ```
1565
+ */
1566
+ function hostHeaderValidationResponse(req, allowedHostnames) {
1567
+ const result = validateHostHeader(req.headers.get("host"), allowedHostnames);
1568
+ if (result.ok) return void 0;
1569
+ return Response.json({
1570
+ jsonrpc: "2.0",
1571
+ error: {
1572
+ code: -32e3,
1573
+ message: result.message
1574
+ },
1575
+ id: null
1576
+ }, {
1577
+ status: 403,
1578
+ headers: { "Content-Type": "application/json" }
1579
+ });
1580
+ }
1581
+
1582
+ //#endregion
1583
+ //#region src/server/middleware/originValidation.ts
1584
+ /**
1585
+ * Validate an `Origin` header against an allowlist of hostnames (port-agnostic).
1586
+ *
1587
+ * - A missing/empty `Origin` header passes: non-browser clients do not send one,
1588
+ * and only browser-originated requests carry the header this check defends against.
1589
+ * - Allowlist items are hostnames only (no scheme, no port), the same convention as
1590
+ * `validateHostHeader`. For IPv6, include brackets (e.g. `[::1]`).
1591
+ * - A browser extension's origin carries its extension ID as the hostname; list the
1592
+ * ID to allow one extension. An allowlist item of the form `<scheme>://*`
1593
+ * (lowercase, e.g. `moz-extension://*`) allows every origin of that scheme, which
1594
+ * Firefox needs because its extension IDs differ on every install.
1595
+ * `http://*` and `https://*` are not honoured: list websites by hostname.
1596
+ * - Any present value that cannot be parsed as an origin URL — including the literal
1597
+ * `null` origin browsers send for opaque contexts — is rejected (deny on failure).
1598
+ */
1599
+ function validateOriginHeader(originHeader, allowedOriginHostnames) {
1600
+ if (originHeader === null || originHeader === void 0 || originHeader === "") return { ok: true };
1601
+ let hostname;
1602
+ let scheme;
1603
+ try {
1604
+ const url = new URL(originHeader);
1605
+ hostname = url.hostname;
1606
+ scheme = url.protocol;
1607
+ } catch {
1608
+ return {
1609
+ ok: false,
1610
+ errorCode: "invalid_origin_header",
1611
+ message: `Invalid Origin header: ${originHeader}`,
1612
+ originHeader
1613
+ };
1614
+ }
1615
+ if (hostname === "") return {
1616
+ ok: false,
1617
+ errorCode: "invalid_origin_header",
1618
+ message: `Invalid Origin header: ${originHeader}`,
1619
+ originHeader
1620
+ };
1621
+ if (!(scheme !== "http:" && scheme !== "https:" && allowedOriginHostnames.includes(`${scheme}//*`)) && !allowedOriginHostnames.includes(hostname)) return {
1622
+ ok: false,
1623
+ errorCode: "invalid_origin",
1624
+ message: `Invalid Origin: ${hostname}`,
1625
+ originHeader,
1626
+ hostname
1627
+ };
1628
+ return {
1629
+ ok: true,
1630
+ origin: originHeader,
1631
+ hostname
1632
+ };
1633
+ }
1634
+ /**
1635
+ * Convenience allowlist of localhost-class origin hostnames, mirroring
1636
+ * `localhostAllowedHostnames`.
1637
+ */
1638
+ function localhostAllowedOrigins() {
1639
+ return [
1640
+ "localhost",
1641
+ "127.0.0.1",
1642
+ "[::1]"
1643
+ ];
1644
+ }
1645
+ /**
1646
+ * Web-standard `Request` helper for Origin validation: returns a `403` JSON-RPC
1647
+ * error response when the request's `Origin` header is not allowed, and
1648
+ * `undefined` when the request may proceed.
1649
+ *
1650
+ * ```ts
1651
+ * const rejected = originValidationResponse(request, localhostAllowedOrigins());
1652
+ * if (rejected) return rejected;
1653
+ * ```
1654
+ */
1655
+ function originValidationResponse(req, allowedOriginHostnames) {
1656
+ const result = validateOriginHeader(req.headers.get("origin"), allowedOriginHostnames);
1657
+ if (result.ok) return void 0;
1658
+ return Response.json({
1659
+ jsonrpc: "2.0",
1660
+ error: {
1661
+ code: -32e3,
1662
+ message: result.message
1663
+ },
1664
+ id: null
1665
+ }, {
1666
+ status: 403,
1667
+ headers: { "Content-Type": "application/json" }
1668
+ });
1669
+ }
1670
+
1671
+ //#endregion
1672
+ //#region src/server/requestStateCodec.ts
1673
+ const PREFIX = "v1.";
1674
+ function bytesToBase64Url(bytes) {
1675
+ let bin = "";
1676
+ for (const b of bytes) bin += String.fromCodePoint(b);
1677
+ return btoa(bin).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
1678
+ }
1679
+ function constantTimeTagEqual(a, b) {
1680
+ if (a.length !== b.length) return false;
1681
+ let r = 0;
1682
+ for (let i = 0; i < a.length; i++) r |= a.codePointAt(i) ^ b.codePointAt(i);
1683
+ return r === 0;
1684
+ }
1685
+ function base64UrlToBytes(s) {
1686
+ const b64 = s.replaceAll("-", "+").replaceAll("_", "/");
1687
+ const bin = atob(b64);
1688
+ const bytes = new Uint8Array(bin.length);
1689
+ for (let i = 0; i < bin.length; i++) bytes[i] = bin.codePointAt(i);
1690
+ return bytes;
1691
+ }
1692
+ /**
1693
+ * Create an opt-in HMAC-SHA256 codec for the multi-round-trip `requestState`
1694
+ * (protocol revision 2026-07-28).
1695
+ *
1696
+ * `requestState` round-trips through the client and is attacker-controlled
1697
+ * input on re-entry. The SDK applies no protection of its own; this helper is
1698
+ * the convenience implementation of the spec's integrity MUST so authors don't
1699
+ * hand-roll HMAC. Wire shape:
1700
+ *
1701
+ * "v1." b64url({"p":<payload>,"exp":<unixSeconds>,"b":<bindTag>?}) "." b64url(mac)
1702
+ *
1703
+ * where `bindTag` is `b64url(HMAC(key, "mcp.requestState.bind:" + bind(ctx))[:16])`
1704
+ * — the binding value is never embedded raw.
1705
+ *
1706
+ * The codec is **signed, not encrypted**: the body is integrity-protected but
1707
+ * the client can base64url-decode it and read the payload (`p`) in clear. Do
1708
+ * not put secrets in the payload; use an AEAD construction if confidentiality
1709
+ * is required. The handler reads its payload back via the typed
1710
+ * `ctx.mcpReq.requestState<T>()` accessor — the seam has already run `verify`
1711
+ * (integrity proven, payload decoded) by the time the handler is entered.
1712
+ *
1713
+ * Verification is fail-closed and constant-time (WebCrypto `subtle.verify` for
1714
+ * the body MAC; a fixed-length XOR-accumulator compare for the bind tag).
1715
+ * See `examples/mrtr/server.ts` for a worked end-to-end example.
1716
+ *
1717
+ * Design comparison (mcp.d `secureRequestState`, the peer SDK's reference
1718
+ * implementation): mcp.d additionally offers an AES-256-GCM encrypted mode and
1719
+ * derives independent cipher / bind-HMAC sub-keys from the operator secret via
1720
+ * HKDF-SHA256, with an auto-generated per-process ephemeral key when none is
1721
+ * supplied. This codec deliberately ships only the signed mode and a single
1722
+ * keyed HMAC (domain-separated by input prefix) — HKDF sub-key derivation and
1723
+ * an encrypted mode are intentionally out of scope for the initial release.
1724
+ */
1725
+ function createRequestStateCodec(options) {
1726
+ const subtle = globalThis.crypto?.subtle;
1727
+ if (subtle === void 0) throw new TypeError("createRequestStateCodec requires the Web Crypto API (globalThis.crypto.subtle); see https://ts.sdk.modelcontextprotocol.io/v2/troubleshooting for the Node.js polyfill instructions");
1728
+ const keyBytes = typeof options.key === "string" ? new TextEncoder().encode(options.key) : Uint8Array.from(options.key);
1729
+ if (keyBytes.byteLength < 32) throw new RangeError(`createRequestStateCodec: key must be at least 32 bytes (got ${keyBytes.byteLength})`);
1730
+ const ttlSeconds = options.ttlSeconds ?? 600;
1731
+ if (!Number.isFinite(ttlSeconds)) throw new RangeError("createRequestStateCodec: ttlSeconds must be a finite number");
1732
+ const bind = options.bind;
1733
+ let cryptoKey;
1734
+ const importedKey = () => cryptoKey ??= subtle.importKey("raw", keyBytes, {
1735
+ name: "HMAC",
1736
+ hash: "SHA-256"
1737
+ }, false, ["sign", "verify"]);
1738
+ const utf8 = new TextEncoder();
1739
+ const BIND_LABEL = "mcp.requestState.bind:";
1740
+ const bindTag = async (value) => {
1741
+ return bytesToBase64Url(new Uint8Array(await subtle.sign("HMAC", await importedKey(), utf8.encode(BIND_LABEL + value))).slice(0, 16));
1742
+ };
1743
+ return {
1744
+ async mint(payload, ctx) {
1745
+ const envelope = {
1746
+ p: payload,
1747
+ exp: Math.floor(Date.now() / 1e3) + ttlSeconds
1748
+ };
1749
+ if (bind !== void 0) {
1750
+ if (ctx === void 0) throw new TypeError("createRequestStateCodec: mint() requires ctx when a bind callback is configured");
1751
+ envelope.b = await bindTag(bind(ctx));
1752
+ }
1753
+ const body = bytesToBase64Url(utf8.encode(JSON.stringify(envelope)));
1754
+ return `${PREFIX}${body}.${bytesToBase64Url(new Uint8Array(await subtle.sign("HMAC", await importedKey(), utf8.encode(PREFIX + body))))}`;
1755
+ },
1756
+ async verify(state, ctx) {
1757
+ const dot = state.lastIndexOf(".");
1758
+ if (!state.startsWith(PREFIX) || dot <= 3) throw new Error("malformed");
1759
+ const body = state.slice(3, dot);
1760
+ let macBytes;
1761
+ try {
1762
+ macBytes = base64UrlToBytes(state.slice(dot + 1));
1763
+ } catch {
1764
+ throw new Error("malformed");
1765
+ }
1766
+ if (!await subtle.verify("HMAC", await importedKey(), macBytes, utf8.encode(PREFIX + body))) throw new Error("mac");
1767
+ let envelope;
1768
+ try {
1769
+ envelope = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(base64UrlToBytes(body)));
1770
+ } catch {
1771
+ throw new Error("malformed");
1772
+ }
1773
+ if (typeof envelope.exp !== "number" || envelope.exp < Math.floor(Date.now() / 1e3)) throw new Error("expired");
1774
+ if (bind !== void 0) {
1775
+ const expected = await bindTag(bind(ctx));
1776
+ if (envelope.b === void 0 || !constantTimeTagEqual(envelope.b, expected)) throw new Error("bind");
1777
+ } else if (envelope.b !== void 0) throw new Error("bind");
1778
+ return envelope.p;
1779
+ }
1780
+ };
1781
+ }
1782
+
1783
+ //#endregion
1784
+ //#region src/fromJsonSchema.ts
1785
+ let _defaultValidator;
1786
+ function fromJsonSchema(schema, validator) {
1787
+ return require_src.fromJsonSchema(schema, validator ?? (_defaultValidator ??= new _modelcontextprotocol_server__shims.DefaultJsonSchemaValidator()));
1788
+ }
1789
+
1790
+ //#endregion
1791
+ Object.defineProperty(exports, 'BAGGAGE_META_KEY', {
1792
+ enumerable: true,
1793
+ get: function () {
1794
+ return _modelcontextprotocol_core_internal.BAGGAGE_META_KEY;
1795
+ }
1796
+ });
1797
+ Object.defineProperty(exports, 'CLIENT_CAPABILITIES_META_KEY', {
1798
+ enumerable: true,
1799
+ get: function () {
1800
+ return _modelcontextprotocol_core_internal.CLIENT_CAPABILITIES_META_KEY;
1801
+ }
1802
+ });
1803
+ Object.defineProperty(exports, 'CLIENT_INFO_META_KEY', {
1804
+ enumerable: true,
1805
+ get: function () {
1806
+ return _modelcontextprotocol_core_internal.CLIENT_INFO_META_KEY;
1807
+ }
1808
+ });
1809
+ exports.DEFAULT_MAX_REQUEST_BODY_SIZE = DEFAULT_MAX_REQUEST_BODY_SIZE;
1810
+ Object.defineProperty(exports, 'DEFAULT_NEGOTIATED_PROTOCOL_VERSION', {
1811
+ enumerable: true,
1812
+ get: function () {
1813
+ return _modelcontextprotocol_core_internal.DEFAULT_NEGOTIATED_PROTOCOL_VERSION;
1814
+ }
1815
+ });
1816
+ exports.DEFAULT_REQUEST_TIMEOUT_MSEC = require_src.DEFAULT_REQUEST_TIMEOUT_MSEC;
1817
+ Object.defineProperty(exports, 'INTERNAL_ERROR', {
1818
+ enumerable: true,
1819
+ get: function () {
1820
+ return _modelcontextprotocol_core_internal.INTERNAL_ERROR;
1821
+ }
1822
+ });
1823
+ Object.defineProperty(exports, 'INVALID_PARAMS', {
1824
+ enumerable: true,
1825
+ get: function () {
1826
+ return _modelcontextprotocol_core_internal.INVALID_PARAMS;
1827
+ }
1828
+ });
1829
+ Object.defineProperty(exports, 'INVALID_REQUEST', {
1830
+ enumerable: true,
1831
+ get: function () {
1832
+ return _modelcontextprotocol_core_internal.INVALID_REQUEST;
1833
+ }
1834
+ });
1835
+ exports.InMemoryServerEventBus = require_mcp.InMemoryServerEventBus;
1836
+ exports.InMemoryTransport = require_src.InMemoryTransport;
1837
+ Object.defineProperty(exports, 'JSONRPC_VERSION', {
1838
+ enumerable: true,
1839
+ get: function () {
1840
+ return _modelcontextprotocol_core_internal.JSONRPC_VERSION;
1841
+ }
1842
+ });
1843
+ Object.defineProperty(exports, 'LATEST_PROTOCOL_VERSION', {
1844
+ enumerable: true,
1845
+ get: function () {
1846
+ return _modelcontextprotocol_core_internal.LATEST_PROTOCOL_VERSION;
1847
+ }
1848
+ });
1849
+ Object.defineProperty(exports, 'LOG_LEVEL_META_KEY', {
1850
+ enumerable: true,
1851
+ get: function () {
1852
+ return _modelcontextprotocol_core_internal.LOG_LEVEL_META_KEY;
1853
+ }
1854
+ });
1855
+ Object.defineProperty(exports, 'METHOD_NOT_FOUND', {
1856
+ enumerable: true,
1857
+ get: function () {
1858
+ return _modelcontextprotocol_core_internal.METHOD_NOT_FOUND;
1859
+ }
1860
+ });
1861
+ exports.McpServer = require_mcp.McpServer;
1862
+ exports.MissingRequiredClientCapabilityError = require_src.MissingRequiredClientCapabilityError;
1863
+ exports.OAuthError = require_src.OAuthError;
1864
+ exports.OAuthErrorCode = require_src.OAuthErrorCode;
1865
+ Object.defineProperty(exports, 'PARSE_ERROR', {
1866
+ enumerable: true,
1867
+ get: function () {
1868
+ return _modelcontextprotocol_core_internal.PARSE_ERROR;
1869
+ }
1870
+ });
1871
+ Object.defineProperty(exports, 'PROTOCOL_VERSION_META_KEY', {
1872
+ enumerable: true,
1873
+ get: function () {
1874
+ return _modelcontextprotocol_core_internal.PROTOCOL_VERSION_META_KEY;
1875
+ }
1876
+ });
1877
+ exports.PerRequestHTTPServerTransport = PerRequestHTTPServerTransport;
1878
+ exports.Protocol = require_src.Protocol;
1879
+ exports.ProtocolError = require_src.ProtocolError;
1880
+ exports.ProtocolErrorCode = require_src.ProtocolErrorCode;
1881
+ Object.defineProperty(exports, 'RELATED_TASK_META_KEY', {
1882
+ enumerable: true,
1883
+ get: function () {
1884
+ return _modelcontextprotocol_core_internal.RELATED_TASK_META_KEY;
1885
+ }
1886
+ });
1887
+ exports.ReadBuffer = require_src.ReadBuffer;
1888
+ exports.ResourceNotFoundError = require_src.ResourceNotFoundError;
1889
+ exports.ResourceTemplate = require_mcp.ResourceTemplate;
1890
+ Object.defineProperty(exports, 'SERVER_INFO_META_KEY', {
1891
+ enumerable: true,
1892
+ get: function () {
1893
+ return _modelcontextprotocol_core_internal.SERVER_INFO_META_KEY;
1894
+ }
1895
+ });
1896
+ exports.STDIO_DEFAULT_MAX_BUFFER_SIZE = require_src.STDIO_DEFAULT_MAX_BUFFER_SIZE;
1897
+ Object.defineProperty(exports, 'SUBSCRIPTION_ID_META_KEY', {
1898
+ enumerable: true,
1899
+ get: function () {
1900
+ return _modelcontextprotocol_core_internal.SUBSCRIPTION_ID_META_KEY;
1901
+ }
1902
+ });
1903
+ Object.defineProperty(exports, 'SUPPORTED_PROTOCOL_VERSIONS', {
1904
+ enumerable: true,
1905
+ get: function () {
1906
+ return _modelcontextprotocol_core_internal.SUPPORTED_PROTOCOL_VERSIONS;
1907
+ }
1908
+ });
1909
+ exports.SdkError = require_src.SdkError;
1910
+ exports.SdkErrorCode = require_src.SdkErrorCode;
1911
+ exports.SdkHttpError = require_src.SdkHttpError;
1912
+ exports.Server = require_mcp.Server;
1913
+ Object.defineProperty(exports, 'TRACEPARENT_META_KEY', {
1914
+ enumerable: true,
1915
+ get: function () {
1916
+ return _modelcontextprotocol_core_internal.TRACEPARENT_META_KEY;
1917
+ }
1918
+ });
1919
+ Object.defineProperty(exports, 'TRACESTATE_META_KEY', {
1920
+ enumerable: true,
1921
+ get: function () {
1922
+ return _modelcontextprotocol_core_internal.TRACESTATE_META_KEY;
1923
+ }
1924
+ });
1925
+ exports.UnsupportedProtocolVersionError = require_src.UnsupportedProtocolVersionError;
1926
+ exports.UriTemplate = require_src.UriTemplate;
1927
+ exports.UrlElicitationRequiredError = require_src.UrlElicitationRequiredError;
1928
+ exports.WebStandardStreamableHTTPServerTransport = WebStandardStreamableHTTPServerTransport;
1929
+ exports.acceptedContent = require_src.acceptedContent;
1930
+ exports.assertCompleteRequestPrompt = require_src.assertCompleteRequestPrompt;
1931
+ exports.assertCompleteRequestResourceTemplate = require_src.assertCompleteRequestResourceTemplate;
1932
+ exports.bearerAuthChallengeResponse = require_mcp.bearerAuthChallengeResponse;
1933
+ exports.buildOAuthProtectedResourceMetadata = require_mcp.buildOAuthProtectedResourceMetadata;
1934
+ exports.checkResourceAllowed = require_src.checkResourceAllowed;
1935
+ exports.classifyInboundRequest = require_src.classifyInboundRequest;
1936
+ exports.completable = require_mcp.completable;
1937
+ exports.createFetchWithInit = require_src.createFetchWithInit;
1938
+ exports.createMcpHandler = createMcpHandler;
1939
+ exports.createRequestStateCodec = createRequestStateCodec;
1940
+ exports.deserializeMessage = require_src.deserializeMessage;
1941
+ exports.fromJsonSchema = fromJsonSchema;
1942
+ exports.getDisplayName = require_src.getDisplayName;
1943
+ exports.getOAuthProtectedResourceMetadataUrl = require_mcp.getOAuthProtectedResourceMetadataUrl;
1944
+ exports.hostHeaderValidationResponse = hostHeaderValidationResponse;
1945
+ exports.inputRequired = require_src.inputRequired;
1946
+ exports.inputResponse = require_src.inputResponse;
1947
+ exports.isCallToolResult = require_src.isCallToolResult;
1948
+ exports.isCompletable = require_mcp.isCompletable;
1949
+ exports.isInitializeRequest = require_src.isInitializeRequest;
1950
+ exports.isInitializedNotification = require_src.isInitializedNotification;
1951
+ exports.isInputRequiredResult = require_src.isInputRequiredResult;
1952
+ exports.isJSONRPCErrorResponse = require_src.isJSONRPCErrorResponse;
1953
+ exports.isJSONRPCNotification = require_src.isJSONRPCNotification;
1954
+ exports.isJSONRPCRequest = require_src.isJSONRPCRequest;
1955
+ exports.isJSONRPCResponse = require_src.isJSONRPCResponse;
1956
+ exports.isJSONRPCResultResponse = require_src.isJSONRPCResultResponse;
1957
+ exports.isJsonContentType = require_src.isJsonContentType;
1958
+ exports.isLegacyRequest = isLegacyRequest;
1959
+ exports.isSpecType = require_src.isSpecType;
1960
+ exports.isTaskAugmentedRequestParams = require_src.isTaskAugmentedRequestParams;
1961
+ exports.legacyStatelessFallback = legacyStatelessFallback;
1962
+ exports.localhostAllowedHostnames = localhostAllowedHostnames;
1963
+ exports.localhostAllowedOrigins = localhostAllowedOrigins;
1964
+ exports.mergeCapabilities = require_src.mergeCapabilities;
1965
+ exports.oauthMetadataResponse = require_mcp.oauthMetadataResponse;
1966
+ exports.originValidationResponse = originValidationResponse;
1967
+ exports.parseJSONRPCMessage = require_src.parseJSONRPCMessage;
1968
+ exports.preloadSchemas = require_src.preloadSchemas;
1969
+ exports.readRequestBody = readRequestBody;
1970
+ exports.requireBearerAuth = require_mcp.requireBearerAuth;
1971
+ exports.requireScopes = require_mcp.requireScopes;
1972
+ exports.resourceUrlFromServerUrl = require_src.resourceUrlFromServerUrl;
1973
+ exports.serializeMessage = require_src.serializeMessage;
1974
+ exports.specTypeSchemas = require_src.specTypeSchemas;
1975
+ exports.validateHostHeader = validateHostHeader;
1976
+ exports.validateOriginHeader = validateOriginHeader;
1977
+ exports.verifyBearerToken = require_mcp.verifyBearerToken;
1978
+ //# sourceMappingURL=index.cjs.map