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