outask 0.0.0-stage → 1.7.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 +38 -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 +145 -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 +146 -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 +337 -0
  826. package/src/tasks.mjs +290 -0
  827. package/src/timestamps.mjs +22 -0
  828. package/src/transition.mjs +181 -0
  829. package/src/update.mjs +56 -0
  830. package/src/validation.mjs +144 -0
  831. package/src/version.mjs +5 -0
@@ -0,0 +1,2326 @@
1
+ import { A as promptArgumentsFromStandardSchema, At as LATEST_PROTOCOL_VERSION, B as scanXMcpHeaderDeclarations, C as REQUEST_STATE_ONLY_LEG_PACING_MS, Ct as CLIENT_CAPABILITIES_META_KEY, E as sleep, H as assertCompleteRequestPrompt, Ht as requiredClientCapabilitiesForInputRequest, It as SERVER_INFO_META_KEY, Kt as SdkError, Lt as SUBSCRIPTION_ID_META_KEY, M as validateStandardSchema, N as parseSchema, T as linkedRoundAbort, U as assertCompleteRequestResourceTemplate, Vt as missingClientCapabilities, Xt as OAuthErrorCode, Yt as OAuthError, _ as mergeCapabilities, _t as normalizeContentlessToolResult, a as UriTemplate, b as withRequestStateValue, bt as legacyProtocolVersions, ct as codecForVersion, dt as ResourceNotFoundError, g as Protocol, gt as attachCacheHintFallback, ht as assertValidCacheHint, j as standardSchemaToJsonSchema, jt as LOG_LEVEL_META_KEY, lt as MissingRequiredClientCapabilityError, mt as ProtocolErrorCode, nt as LoggingLevelSchema, q as isInputRequiredResult, qt as SdkErrorCode, r as normalizeRawShapeSchema, s as validateAndWarnToolName, st as MODERN_WIRE_REVISION, ut as ProtocolError, v as requestStateAccessor, w as inputRequiredRoundsExceededMessage, xt as modernProtocolVersions, yt as isModernProtocolVersion } from "./src-Cqbh3MYc.mjs";
2
+ import { DefaultJsonSchemaValidator } from "@modelcontextprotocol/server/_shims";
3
+
4
+ //#region src/server/completable.ts
5
+ const COMPLETABLE_SYMBOL = Symbol.for("mcp.completable");
6
+ /**
7
+ * Wraps a schema to provide autocompletion capabilities. Useful for, e.g., prompt arguments in MCP.
8
+ *
9
+ * @example
10
+ * ```ts source="./completable.examples.ts#completable_basicUsage"
11
+ * server.registerPrompt(
12
+ * 'review-code',
13
+ * {
14
+ * title: 'Code Review',
15
+ * argsSchema: z.object({
16
+ * language: completable(z.string().describe('Programming language'), value =>
17
+ * ['typescript', 'javascript', 'python', 'rust', 'go'].filter(lang => lang.startsWith(value))
18
+ * )
19
+ * })
20
+ * },
21
+ * ({ language }) => ({
22
+ * messages: [
23
+ * {
24
+ * role: 'user' as const,
25
+ * content: {
26
+ * type: 'text' as const,
27
+ * text: `Review this ${language} code.`
28
+ * }
29
+ * }
30
+ * ]
31
+ * })
32
+ * );
33
+ * ```
34
+ *
35
+ * @see {@linkcode server/mcp.McpServer.registerPrompt | McpServer.registerPrompt} for using completable schemas in prompt argument definitions
36
+ */
37
+ function completable(schema, complete) {
38
+ Object.defineProperty(schema, COMPLETABLE_SYMBOL, {
39
+ value: { complete },
40
+ enumerable: false,
41
+ writable: false,
42
+ configurable: false
43
+ });
44
+ return schema;
45
+ }
46
+ /**
47
+ * Checks if a schema is completable (has completion metadata).
48
+ */
49
+ function isCompletable(schema) {
50
+ return !!schema && typeof schema === "object" && COMPLETABLE_SYMBOL in schema;
51
+ }
52
+ /**
53
+ * Gets the completer callback from a completable schema, if it exists.
54
+ */
55
+ function getCompleter(schema) {
56
+ return schema[COMPLETABLE_SYMBOL]?.complete;
57
+ }
58
+
59
+ //#endregion
60
+ //#region src/server/sseKeepAlive.ts
61
+ /** Default interval between SSE keep-alive comment frames. */
62
+ const DEFAULT_SSE_KEEP_ALIVE_MS = 15e3;
63
+ const MAX_TIMER_DELAY_MS = 2 ** 31 - 1;
64
+ /** Arms an unref'd timer, or disables keep-alive for invalid delays. */
65
+ function armSseKeepAlive(intervalMs, onTick) {
66
+ if (!Number.isFinite(intervalMs) || intervalMs < 1) return;
67
+ const timer = setInterval(onTick, Math.min(intervalMs, MAX_TIMER_DELAY_MS));
68
+ timer.unref?.();
69
+ return timer;
70
+ }
71
+
72
+ //#endregion
73
+ //#region src/server/serverEventBus.ts
74
+ /**
75
+ * A `ServerEventBus` backed by an in-process listener set.
76
+ *
77
+ * `publish()` delivers synchronously to the live listener set (a listener
78
+ * unsubscribing itself mid-dispatch is safe; the entry's listen-router
79
+ * listeners never unsubscribe peers). A throwing listener does not stop
80
+ * delivery to the others.
81
+ */
82
+ var InMemoryServerEventBus = class {
83
+ _listeners = /* @__PURE__ */ new Set();
84
+ /**
85
+ * @param onerror - Optional callback for errors thrown by listeners
86
+ * during dispatch.
87
+ */
88
+ constructor(onerror) {
89
+ this.onerror = onerror;
90
+ }
91
+ publish(event) {
92
+ for (const listener of this._listeners) try {
93
+ listener(event);
94
+ } catch (error) {
95
+ this.onerror?.(error instanceof Error ? error : new Error(String(error)));
96
+ }
97
+ }
98
+ subscribe(listener) {
99
+ this._listeners.add(listener);
100
+ let live = true;
101
+ return () => {
102
+ if (!live) return;
103
+ live = false;
104
+ this._listeners.delete(listener);
105
+ };
106
+ }
107
+ /** The number of currently registered listeners (test/introspection only — the routers track capacity via their own open-subscription set). */
108
+ get listenerCount() {
109
+ return this._listeners.size;
110
+ }
111
+ };
112
+ /** Build a {@linkcode ServerNotifier} over a bus. */
113
+ function createServerNotifier(bus) {
114
+ return {
115
+ toolsChanged: () => bus.publish({ kind: "tools_list_changed" }),
116
+ promptsChanged: () => bus.publish({ kind: "prompts_list_changed" }),
117
+ resourcesChanged: () => bus.publish({ kind: "resources_list_changed" }),
118
+ resourceUpdated: (uri) => bus.publish({
119
+ kind: "resource_updated",
120
+ uri
121
+ })
122
+ };
123
+ }
124
+ /**
125
+ * Whether a `subscriptions/listen` filter accepts a given change event.
126
+ *
127
+ * Pure: no I/O, no mutation. The filter governs ONLY the four
128
+ * subscription-gated change types — non-gated notifications never reach the
129
+ * bus and are not modeled here.
130
+ *
131
+ * `resource_updated` matches only when `resourceSubscriptions` is present and
132
+ * contains the event's URI exactly (per the spec: "for these resource URIs").
133
+ */
134
+ function listenFilterAccepts(filter, event) {
135
+ switch (event.kind) {
136
+ case "tools_list_changed": return filter.toolsListChanged === true;
137
+ case "prompts_list_changed": return filter.promptsListChanged === true;
138
+ case "resources_list_changed": return filter.resourcesListChanged === true;
139
+ case "resource_updated": return filter.resourceSubscriptions !== void 0 && filter.resourceSubscriptions.includes(event.uri);
140
+ }
141
+ }
142
+ /**
143
+ * The honored subset of a requested filter: keeps only the fields the client
144
+ * explicitly opted in to (drops `false` and absent fields), narrowed against
145
+ * the server's declared capabilities when supplied. The serving entry sends
146
+ * this back in `notifications/subscriptions/acknowledged` so the ack reflects
147
+ * what the server can actually deliver.
148
+ *
149
+ * - `toolsListChanged` is honored only when `capabilities.tools.listChanged`
150
+ * is advertised; likewise `promptsListChanged` / `resourcesListChanged`.
151
+ * - `resourceSubscriptions` is honored only when
152
+ * `capabilities.resources.subscribe` is advertised.
153
+ *
154
+ * `capabilities` is optional on this pure helper for test convenience only —
155
+ * both wired routers REQUIRE capabilities at the call site (the HTTP router's
156
+ * `serve()` takes a required parameter; `StdioListenRouter.serve()` throws
157
+ * before `setServerCapabilities()` was called), so the fail-open
158
+ * `undefined → honor everything` branch is never reachable on a wired entry.
159
+ */
160
+ function honoredSubset(requested, capabilities) {
161
+ const honored = {};
162
+ const allow = (bit) => capabilities === void 0 || bit === true;
163
+ if (requested.toolsListChanged === true && allow(capabilities?.tools?.listChanged)) honored.toolsListChanged = true;
164
+ if (requested.promptsListChanged === true && allow(capabilities?.prompts?.listChanged)) honored.promptsListChanged = true;
165
+ if (requested.resourcesListChanged === true && allow(capabilities?.resources?.listChanged)) honored.resourcesListChanged = true;
166
+ if (requested.resourceSubscriptions !== void 0 && requested.resourceSubscriptions.length > 0 && allow(capabilities?.resources?.subscribe)) honored.resourceSubscriptions = [...requested.resourceSubscriptions];
167
+ return honored;
168
+ }
169
+ /** Map a {@linkcode ServerEvent} onto its wire notification `{method, params}`. */
170
+ function serverEventToNotification(event) {
171
+ switch (event.kind) {
172
+ case "tools_list_changed": return { method: "notifications/tools/list_changed" };
173
+ case "prompts_list_changed": return { method: "notifications/prompts/list_changed" };
174
+ case "resources_list_changed": return { method: "notifications/resources/list_changed" };
175
+ case "resource_updated": return {
176
+ method: "notifications/resources/updated",
177
+ params: { uri: event.uri }
178
+ };
179
+ }
180
+ }
181
+
182
+ //#endregion
183
+ //#region src/server/listenRouter.ts
184
+ /** Default capacity guard: refuse a new subscription when this many are already open. */
185
+ const DEFAULT_MAX_SUBSCRIPTIONS = 1024;
186
+ function jsonRpcError(id, code, message) {
187
+ return Response.json({
188
+ jsonrpc: "2.0",
189
+ error: {
190
+ code,
191
+ message
192
+ },
193
+ id
194
+ }, { status: 200 });
195
+ }
196
+ /** Stamp the subscription id onto a notification's `_meta`. Non-mutating. */
197
+ function stampSubscriptionId(notification, subscriptionId) {
198
+ return {
199
+ method: notification.method,
200
+ params: {
201
+ ...notification.params,
202
+ _meta: {
203
+ ...notification.params?._meta,
204
+ [SUBSCRIPTION_ID_META_KEY]: subscriptionId
205
+ }
206
+ }
207
+ };
208
+ }
209
+ /**
210
+ * Read the requested filter off a `subscriptions/listen` request body.
211
+ * Returns the validated filter, or `undefined` when `params.notifications`
212
+ * is absent or fails the schema (the caller answers `-32602` — the spec
213
+ * marks `notifications` REQUIRED on the listen request).
214
+ */
215
+ function parseListenFilter(message) {
216
+ const outcome = codecForVersion(MODERN_WIRE_REVISION).validateRequest("subscriptions/listen", message);
217
+ return outcome.ok ? outcome.value.params?.notifications : void 0;
218
+ }
219
+ function createListenRouter(options) {
220
+ const { bus, onerror } = options;
221
+ const maxSubscriptions = options.maxSubscriptions ?? DEFAULT_MAX_SUBSCRIPTIONS;
222
+ const keepAliveMs = options.keepAliveMs ?? DEFAULT_SSE_KEEP_ALIVE_MS;
223
+ const open = /* @__PURE__ */ new Set();
224
+ function serve(message, signal, capabilities, serverInfo) {
225
+ if (open.size >= maxSubscriptions) {
226
+ onerror?.(/* @__PURE__ */ new Error(`subscriptions/listen refused: subscription limit reached (${maxSubscriptions})`));
227
+ return jsonRpcError(message.id, -32603, "Subscription limit reached");
228
+ }
229
+ const filter = parseListenFilter(message);
230
+ if (filter === void 0) return jsonRpcError(message.id, -32602, "Invalid params: 'notifications' is required and must be a valid SubscriptionFilter");
231
+ const honored = honoredSubset(filter, capabilities);
232
+ const subscriptionId = message.id;
233
+ const encoder = new TextEncoder();
234
+ let controller;
235
+ let closed = false;
236
+ let unsubscribe;
237
+ let keepAliveTimer;
238
+ let abortCleanup;
239
+ const writeFrame = (frame) => {
240
+ if (closed) return;
241
+ try {
242
+ controller.enqueue(encoder.encode(frame));
243
+ } catch (error) {
244
+ onerror?.(error instanceof Error ? error : new Error(String(error)));
245
+ }
246
+ };
247
+ const writeNotification = (method, params) => {
248
+ writeFrame(`event: message\ndata: ${JSON.stringify({
249
+ jsonrpc: "2.0",
250
+ method,
251
+ params
252
+ })}\n\n`);
253
+ };
254
+ const teardown = (graceful) => {
255
+ if (closed) return;
256
+ if (graceful) writeFrame(`event: message\ndata: ${JSON.stringify({
257
+ jsonrpc: "2.0",
258
+ id: subscriptionId,
259
+ result: {
260
+ resultType: "complete",
261
+ _meta: {
262
+ [SUBSCRIPTION_ID_META_KEY]: subscriptionId,
263
+ [SERVER_INFO_META_KEY]: serverInfo
264
+ }
265
+ }
266
+ })}\n\n`);
267
+ closed = true;
268
+ try {
269
+ unsubscribe?.();
270
+ } catch (error) {
271
+ onerror?.(error instanceof Error ? error : new Error(String(error)));
272
+ }
273
+ if (keepAliveTimer !== void 0) clearInterval(keepAliveTimer);
274
+ abortCleanup?.();
275
+ open.delete(teardown);
276
+ try {
277
+ controller.close();
278
+ } catch {}
279
+ };
280
+ const readable = new ReadableStream({
281
+ start(streamController) {
282
+ controller = streamController;
283
+ const ack = stampSubscriptionId({
284
+ method: "notifications/subscriptions/acknowledged",
285
+ params: { notifications: honored }
286
+ }, subscriptionId);
287
+ writeNotification(ack.method, ack.params);
288
+ if (Object.keys(honored).length === 0) {
289
+ teardown(true);
290
+ return;
291
+ }
292
+ unsubscribe = bus.subscribe((event) => {
293
+ if (closed || !listenFilterAccepts(honored, event)) return;
294
+ const note = stampSubscriptionId(serverEventToNotification(event), subscriptionId);
295
+ writeNotification(note.method, note.params);
296
+ });
297
+ keepAliveTimer = armSseKeepAlive(keepAliveMs, () => writeFrame(": keepalive\n\n"));
298
+ open.add(teardown);
299
+ },
300
+ cancel() {
301
+ teardown(false);
302
+ }
303
+ });
304
+ if (signal !== void 0) if (signal.aborted) teardown(false);
305
+ else {
306
+ const onAbort = () => teardown(false);
307
+ signal.addEventListener("abort", onAbort, { once: true });
308
+ abortCleanup = () => signal.removeEventListener("abort", onAbort);
309
+ }
310
+ return new Response(readable, {
311
+ status: 200,
312
+ headers: {
313
+ "Content-Type": "text/event-stream",
314
+ "Cache-Control": "no-cache, no-transform",
315
+ Connection: "keep-alive",
316
+ "X-Accel-Buffering": "no"
317
+ }
318
+ });
319
+ }
320
+ return {
321
+ serve,
322
+ closeAll() {
323
+ for (const teardown of open) teardown(true);
324
+ },
325
+ get openCount() {
326
+ return open.size;
327
+ }
328
+ };
329
+ }
330
+ const CHANGE_NOTIFICATION_METHODS = new Set([
331
+ "notifications/tools/list_changed",
332
+ "notifications/prompts/list_changed",
333
+ "notifications/resources/list_changed",
334
+ "notifications/resources/updated"
335
+ ]);
336
+ /**
337
+ * Per-connection listen state for the stdio entry. One instance is held by
338
+ * `serveStdio` for the connection lifetime; it routes inbound
339
+ * `subscriptions/listen` / `notifications/cancelled` and rewrites outbound
340
+ * change notifications onto the active subscriptions. No bus — the long-lived
341
+ * pinned instance's existing `send*ListChanged()` calls feed straight into
342
+ * `routeOutbound()`.
343
+ */
344
+ var StdioListenRouter = class {
345
+ /** Active subscriptions, keyed by the listen request's JSON-RPC id verbatim. */
346
+ _subs = /* @__PURE__ */ new Map();
347
+ /**
348
+ * The serving instance's declared capabilities. Filled in by the entry
349
+ * once the modern instance is constructed (the router is created before
350
+ * the instance exists), so the acknowledged filter is narrowed against
351
+ * what the server can actually deliver.
352
+ */
353
+ _serverCapabilities;
354
+ /**
355
+ * The serving instance's identity, stamped onto the graceful-close
356
+ * results' `_meta` (the spec's `SubscriptionsListenResultMetaObject` extends
357
+ * `ResultMetaObject`). Handed over together with the capabilities.
358
+ */
359
+ _serverInfo;
360
+ constructor(_maxSubscriptions = DEFAULT_MAX_SUBSCRIPTIONS, serverCapabilities, serverInfo) {
361
+ this._maxSubscriptions = _maxSubscriptions;
362
+ this._serverCapabilities = serverCapabilities;
363
+ this._serverInfo = serverInfo;
364
+ }
365
+ /**
366
+ * Record the serving instance's declared capabilities and identity once
367
+ * it has been constructed. Called by `serveStdio`'s connect path;
368
+ * subsequent `serve()` calls narrow the honored filter against the
369
+ * capabilities, and `teardownAll()` stamps the identity.
370
+ */
371
+ setServerCapabilities(capabilities, serverInfo) {
372
+ this._serverCapabilities = capabilities;
373
+ if (serverInfo !== void 0) this._serverInfo = serverInfo;
374
+ }
375
+ /** Whether `id` is an active listen subscription on this connection. */
376
+ has(id) {
377
+ return this._subs.has(id);
378
+ }
379
+ /**
380
+ * Serve one inbound `subscriptions/listen` request: registers the
381
+ * subscription and returns the stamped acknowledged notification (or, on
382
+ * capacity / params rejection, the in-band JSON-RPC error response).
383
+ *
384
+ * @throws when called before {@linkcode setServerCapabilities} (or the
385
+ * constructor) has supplied the serving instance's capabilities. Honoring a
386
+ * filter without knowing the server's advertised capabilities would fail
387
+ * open (deliver unadvertised types); the entry guarantees capabilities are
388
+ * set before any listen request is routed here.
389
+ */
390
+ serve(message) {
391
+ if (this._serverCapabilities === void 0) throw new Error("StdioListenRouter.serve() called before setServerCapabilities(); refusing to honor a filter without capabilities");
392
+ if (this._subs.size >= this._maxSubscriptions) return {
393
+ jsonrpc: "2.0",
394
+ id: message.id,
395
+ error: {
396
+ code: -32603,
397
+ message: "Subscription limit reached"
398
+ }
399
+ };
400
+ const filter = parseListenFilter(message);
401
+ if (filter === void 0) return {
402
+ jsonrpc: "2.0",
403
+ id: message.id,
404
+ error: {
405
+ code: -32602,
406
+ message: "Invalid params: 'notifications' is required and must be a valid SubscriptionFilter"
407
+ }
408
+ };
409
+ const honored = honoredSubset(filter, this._serverCapabilities);
410
+ this._subs.set(message.id, honored);
411
+ return stampSubscriptionId({
412
+ method: "notifications/subscriptions/acknowledged",
413
+ params: { notifications: honored }
414
+ }, message.id);
415
+ }
416
+ /**
417
+ * Tear down one subscription (inbound `notifications/cancelled`). Returns
418
+ * `true` when a subscription was removed. After this call NOTHING further
419
+ * is delivered for that subscription id (the post-cancel hardening).
420
+ */
421
+ cancel(id) {
422
+ return this._subs.delete(id);
423
+ }
424
+ /**
425
+ * Route an outbound notification through the active subscriptions.
426
+ *
427
+ * - For a subscription-gated change notification, returns one stamped copy
428
+ * per subscription that opted in to it (an empty array means it is
429
+ * dropped — the modern era never delivers an un-requested change type).
430
+ * - For any other outbound message, returns `'passthrough'` (the entry
431
+ * forwards it as-is).
432
+ */
433
+ routeOutbound(message) {
434
+ if (!CHANGE_NOTIFICATION_METHODS.has(message.method)) return "passthrough";
435
+ const uriParam = message.params?.["uri"];
436
+ const uri = typeof uriParam === "string" ? uriParam : void 0;
437
+ const event = notificationToServerEvent(message.method, uri);
438
+ const out = [];
439
+ for (const [subscriptionId, filter] of this._subs) if (listenFilterAccepts(filter, event)) out.push(stampSubscriptionId({
440
+ method: message.method,
441
+ params: message.params ?? {}
442
+ }, subscriptionId));
443
+ return out;
444
+ }
445
+ /**
446
+ * Server-side graceful teardown of every active subscription: returns the
447
+ * empty `subscriptions/listen` JSON-RPC result for each subscription id —
448
+ * the spec's graceful-close signal, `_meta` carrying the subscription id
449
+ * and the serving instance's identity — for the entry to emit before
450
+ * closing the wire. Clears the set so nothing further is delivered.
451
+ */
452
+ teardownAll() {
453
+ const out = [];
454
+ for (const id of this._subs.keys()) out.push({
455
+ jsonrpc: "2.0",
456
+ id,
457
+ result: {
458
+ resultType: "complete",
459
+ _meta: {
460
+ [SUBSCRIPTION_ID_META_KEY]: id,
461
+ ...this._serverInfo !== void 0 && { [SERVER_INFO_META_KEY]: this._serverInfo }
462
+ }
463
+ }
464
+ });
465
+ this._subs.clear();
466
+ return out;
467
+ }
468
+ };
469
+ function notificationToServerEvent(method, uri) {
470
+ switch (method) {
471
+ case "notifications/tools/list_changed": return { kind: "tools_list_changed" };
472
+ case "notifications/prompts/list_changed": return { kind: "prompts_list_changed" };
473
+ case "notifications/resources/list_changed": return { kind: "resources_list_changed" };
474
+ default: return {
475
+ kind: "resource_updated",
476
+ uri: uri ?? ""
477
+ };
478
+ }
479
+ }
480
+
481
+ //#endregion
482
+ //#region src/server/middleware/bearerAuth.ts
483
+ function comparableResource(value) {
484
+ const text = String(value);
485
+ const hash = text.indexOf("#");
486
+ return (hash === -1 ? text : text.slice(0, hash)).replace(/\/$/, "");
487
+ }
488
+ function sameResource(reported, expected) {
489
+ if (!reported) return false;
490
+ return comparableResource(reported) === comparableResource(expected);
491
+ }
492
+ function headerQuotedValue(value) {
493
+ return value.replaceAll(/[\\"]/g, String.raw`\$&`).replaceAll(/[^\u0020-\u007E]/g, " ");
494
+ }
495
+ /**
496
+ * Build a `WWW-Authenticate: Bearer …` challenge header value (RFC 6750).
497
+ *
498
+ * The single formatter behind every challenge this package emits — the
499
+ * bearer-auth 401/403 answers and the per-operation scope-challenge 403 — so
500
+ * all challenges from one server agree on parameter order and quoting. Every
501
+ * parameter value is emitted as an HTTP quoted-string with `\` and `"`
502
+ * escaped and non-printable characters replaced.
503
+ */
504
+ function buildWwwAuthenticateHeader(errorCode, description, requiredScopes, resourceMetadataUrl) {
505
+ let header = `Bearer error="${headerQuotedValue(errorCode)}", error_description="${headerQuotedValue(description)}"`;
506
+ if (requiredScopes.length > 0) header += `, scope="${headerQuotedValue(requiredScopes.join(" "))}"`;
507
+ if (resourceMetadataUrl) header += `, resource_metadata="${headerQuotedValue(resourceMetadataUrl)}"`;
508
+ return header;
509
+ }
510
+ /**
511
+ * Validate a raw `Authorization` header value as a Bearer token and return
512
+ * the verified {@link AuthInfo}.
513
+ *
514
+ * The runtime-neutral core of Bearer authentication: it parses the header,
515
+ * runs the verifier, compares the token's resource with `expectedResource`,
516
+ * enforces `requiredScopes`, and rejects tokens without an
517
+ * expiration or past it. On any failure it throws an {@link OAuthError} —
518
+ * pass that to {@link bearerAuthChallengeResponse} for the matching HTTP
519
+ * answer, or use {@link requireBearerAuth} to get both steps as one call.
520
+ *
521
+ * Framework adapters build on this: `requireBearerAuth` from
522
+ * `@modelcontextprotocol/express` feeds it `req.headers.authorization`.
523
+ */
524
+ async function verifyBearerToken(authorizationHeader, options) {
525
+ const { verifier, requiredScopes = [], expectedResource } = options;
526
+ if (!authorizationHeader) throw new OAuthError(OAuthErrorCode.InvalidToken, "Missing Authorization header");
527
+ const [type, token] = authorizationHeader.split(" ");
528
+ if (type?.toLowerCase() !== "bearer" || !token) throw new OAuthError(OAuthErrorCode.InvalidToken, "Invalid Authorization header format, expected 'Bearer TOKEN'");
529
+ const authInfo = await verifier.verifyAccessToken(token);
530
+ if (expectedResource !== void 0 && !sameResource(authInfo.resource, expectedResource)) throw new OAuthError(OAuthErrorCode.InvalidToken, "Token was not issued for this resource");
531
+ if (requiredScopes.length > 0) {
532
+ if (!requiredScopes.every((scope) => authInfo.scopes.includes(scope))) throw new OAuthError(OAuthErrorCode.InsufficientScope, "Insufficient scope");
533
+ }
534
+ if (typeof authInfo.expiresAt !== "number" || Number.isNaN(authInfo.expiresAt)) throw new OAuthError(OAuthErrorCode.InvalidToken, "Token has no expiration time");
535
+ else if (authInfo.expiresAt < Date.now() / 1e3) throw new OAuthError(OAuthErrorCode.InvalidToken, "Token has expired");
536
+ if (options.resourceMetadataUrl !== void 0 && authInfo.resourceMetadataUrl === void 0) return {
537
+ ...authInfo,
538
+ resourceMetadataUrl: options.resourceMetadataUrl
539
+ };
540
+ return authInfo;
541
+ }
542
+ /**
543
+ * Build the HTTP answer for a Bearer authentication failure.
544
+ *
545
+ * Maps an {@link OAuthError} to its status — `401` for `invalid_token` and
546
+ * `403` for `insufficient_scope` (both carrying the `WWW-Authenticate: Bearer …`
547
+ * challenge, with `resource_metadata` when configured so clients can discover
548
+ * the Authorization Server), `500` for `server_error`, `400` for anything
549
+ * else. A non-`OAuthError` value answers `500 server_error`. The body is the
550
+ * OAuth error JSON.
551
+ */
552
+ function bearerAuthChallengeResponse(error, options) {
553
+ const { requiredScopes = [], resourceMetadataUrl } = options ?? {};
554
+ if (!(error instanceof OAuthError)) {
555
+ const serverError = new OAuthError(OAuthErrorCode.ServerError, "Internal Server Error");
556
+ return Response.json(serverError.toResponseObject(), { status: 500 });
557
+ }
558
+ switch (error.code) {
559
+ case OAuthErrorCode.InvalidToken: {
560
+ const challenge = buildWwwAuthenticateHeader(error.code, error.message, requiredScopes, resourceMetadataUrl);
561
+ return Response.json(error.toResponseObject(), {
562
+ status: 401,
563
+ headers: { "WWW-Authenticate": challenge }
564
+ });
565
+ }
566
+ case OAuthErrorCode.InsufficientScope: {
567
+ const challenge = buildWwwAuthenticateHeader(error.code, error.message, requiredScopes, resourceMetadataUrl);
568
+ return Response.json(error.toResponseObject(), {
569
+ status: 403,
570
+ headers: { "WWW-Authenticate": challenge }
571
+ });
572
+ }
573
+ case OAuthErrorCode.ServerError: return Response.json(error.toResponseObject(), { status: 500 });
574
+ default: return Response.json(error.toResponseObject(), { status: 400 });
575
+ }
576
+ }
577
+ /**
578
+ * Require a valid Bearer token on web-standard requests.
579
+ *
580
+ * The framework-free counterpart of `requireBearerAuth` from
581
+ * `@modelcontextprotocol/express`, for hosts whose HTTP surface is a
582
+ * `fetch(request)` handler — Cloudflare Workers, Deno, Bun, Hono. The
583
+ * returned gate resolves to the verified {@link AuthInfo}, or to the
584
+ * ready-to-return challenge `Response` when the request must be refused.
585
+ *
586
+ * @example
587
+ * ```ts source="./bearerAuth.examples.ts#requireBearerAuth_fetchGate"
588
+ * const gate = requireBearerAuth({ verifier, requiredScopes: ['mcp'] });
589
+ *
590
+ * async function fetchHandler(request: Request): Promise<Response> {
591
+ * const auth: AuthInfo | Response = await gate(request);
592
+ * if (auth instanceof Response) return auth;
593
+ * return handler.fetch(request, { authInfo: auth });
594
+ * }
595
+ * ```
596
+ */
597
+ function requireBearerAuth(options) {
598
+ const { verifier, requiredScopes = [], resourceMetadataUrl, expectedResource } = options;
599
+ const resolved = {
600
+ verifier,
601
+ requiredScopes,
602
+ resourceMetadataUrl,
603
+ expectedResource
604
+ };
605
+ return async (request) => {
606
+ const [authorizationHeader] = (request.headers.get("authorization") ?? "").split(",");
607
+ try {
608
+ return await verifyBearerToken(authorizationHeader || void 0, resolved);
609
+ } catch (error) {
610
+ return bearerAuthChallengeResponse(error, resolved);
611
+ }
612
+ };
613
+ }
614
+
615
+ //#endregion
616
+ //#region src/server/middleware/oauthMetadata.ts
617
+ function checkIssuerUrl(issuer, allowInsecure) {
618
+ if (issuer.protocol !== "https:" && issuer.hostname !== "localhost" && issuer.hostname !== "127.0.0.1" && !allowInsecure) throw new Error("Issuer URL must be HTTPS");
619
+ if (issuer.hash) throw new Error(`Issuer URL must not have a fragment: ${issuer}`);
620
+ if (issuer.search) throw new Error(`Issuer URL must not have a query string: ${issuer}`);
621
+ }
622
+ /**
623
+ * Derive the RFC 9728 Protected Resource Metadata document from
624
+ * {@link AuthMetadataOptions}, validating the Authorization Server issuer URL
625
+ * (HTTPS required outside localhost) in the process.
626
+ *
627
+ * `oauthMetadataResponse` and the Express `mcpAuthMetadataRouter` both build
628
+ * on this; use it directly when serving the document through your own
629
+ * routing — or call it once at startup to fail fast on a misconfigured
630
+ * issuer before any request arrives.
631
+ */
632
+ function buildOAuthProtectedResourceMetadata(options) {
633
+ checkIssuerUrl(new URL(options.oauthMetadata.issuer), options.dangerouslyAllowInsecureIssuerUrl);
634
+ return {
635
+ resource: options.resourceServerUrl.href,
636
+ authorization_servers: [options.oauthMetadata.issuer],
637
+ scopes_supported: options.scopesSupported,
638
+ resource_name: options.resourceName,
639
+ resource_documentation: options.serviceDocumentationUrl?.href
640
+ };
641
+ }
642
+ /**
643
+ * Builds the RFC 9728 Protected Resource Metadata URL for a given MCP server
644
+ * URL by inserting `/.well-known/oauth-protected-resource` ahead of the path.
645
+ *
646
+ * @example
647
+ * ```ts
648
+ * getOAuthProtectedResourceMetadataUrl(new URL('https://api.example.com/mcp'))
649
+ * // → 'https://api.example.com/.well-known/oauth-protected-resource/mcp'
650
+ * ```
651
+ */
652
+ function getOAuthProtectedResourceMetadataUrl(serverUrl) {
653
+ const metadataUrl = new URL(serverUrl);
654
+ metadataUrl.pathname = protectedResourceMetadataPath(serverUrl);
655
+ metadataUrl.hash = "";
656
+ return metadataUrl.href;
657
+ }
658
+ /** The RFC 9728 path-aware well-known path for a resource URL. */
659
+ function protectedResourceMetadataPath(resourceServerUrl) {
660
+ const rsPath = stripTrailingSlash(resourceServerUrl.pathname);
661
+ return `/.well-known/oauth-protected-resource${rsPath === "/" ? "" : rsPath}`;
662
+ }
663
+ function stripTrailingSlash(path) {
664
+ return path.length > 1 && path.endsWith("/") ? path.slice(0, -1) : path;
665
+ }
666
+ const ALLOWED_METHODS = "GET, HEAD, OPTIONS";
667
+ function metadataDocumentResponse(request, metadata) {
668
+ if (request.method === "OPTIONS") {
669
+ const requestedHeaders = request.headers.get("access-control-request-headers");
670
+ return new Response(null, {
671
+ status: 204,
672
+ headers: {
673
+ "Access-Control-Allow-Origin": "*",
674
+ "Access-Control-Allow-Methods": ALLOWED_METHODS,
675
+ ...requestedHeaders === null ? {} : {
676
+ "Access-Control-Allow-Headers": requestedHeaders,
677
+ Vary: "Access-Control-Request-Headers"
678
+ }
679
+ }
680
+ });
681
+ }
682
+ if (request.method !== "GET" && request.method !== "HEAD") {
683
+ const error = new OAuthError(OAuthErrorCode.MethodNotAllowed, `The method ${request.method} is not allowed for this endpoint`);
684
+ return Response.json(error.toResponseObject(), {
685
+ status: 405,
686
+ headers: {
687
+ Allow: ALLOWED_METHODS,
688
+ "Access-Control-Allow-Origin": "*"
689
+ }
690
+ });
691
+ }
692
+ const response = Response.json(metadata, { headers: { "Access-Control-Allow-Origin": "*" } });
693
+ return request.method === "HEAD" ? new Response(null, {
694
+ status: response.status,
695
+ headers: response.headers
696
+ }) : response;
697
+ }
698
+ /**
699
+ * Serve the two OAuth discovery documents an MCP server acting as a Resource
700
+ * Server exposes, from a web-standard `fetch(request)` handler:
701
+ *
702
+ * - `/.well-known/oauth-protected-resource[/<path>]` — RFC 9728 Protected
703
+ * Resource Metadata, derived from the supplied options (path-aware: the
704
+ * resource URL's path is reflected in the route).
705
+ * - `/.well-known/oauth-authorization-server` — RFC 8414 Authorization
706
+ * Server Metadata, passed through verbatim.
707
+ *
708
+ * Returns the matched document `Response` (JSON with permissive CORS, `405`
709
+ * with an `Allow` header for non-GET methods, `204` for CORS preflight), or
710
+ * `undefined` when the request path is neither well-known route — fall
711
+ * through to your own routing. The framework-free counterpart of
712
+ * `mcpAuthMetadataRouter` from `@modelcontextprotocol/express`; pair it with
713
+ * `requireBearerAuth` and `getOAuthProtectedResourceMetadataUrl` so
714
+ * unauthenticated clients can discover the AS from the `401` challenge.
715
+ *
716
+ * @example
717
+ * ```ts source="./oauthMetadata.examples.ts#oauthMetadataResponse_fetchHandler"
718
+ * async function fetchHandler(request: Request): Promise<Response> {
719
+ * return oauthMetadataResponse(request, options) ?? serveMcp(request);
720
+ * }
721
+ * ```
722
+ */
723
+ function oauthMetadataResponse(request, options) {
724
+ const requestPath = stripTrailingSlash(new URL(request.url).pathname);
725
+ if (requestPath === protectedResourceMetadataPath(options.resourceServerUrl)) return metadataDocumentResponse(request, buildOAuthProtectedResourceMetadata(options));
726
+ if (requestPath === "/.well-known/oauth-authorization-server") {
727
+ buildOAuthProtectedResourceMetadata(options);
728
+ return metadataDocumentResponse(request, options.oauthMetadata);
729
+ }
730
+ }
731
+
732
+ //#endregion
733
+ //#region src/server/scopeChallenge.ts
734
+ /** @internal */
735
+ function supportsScopeChallengeResolver(transport) {
736
+ return typeof transport === "object" && transport !== null && "setScopeChallengeResolver" in transport && typeof transport.setScopeChallengeResolver === "function";
737
+ }
738
+ function assertScope(scope, location) {
739
+ if (typeof scope !== "string" || !/^[\u0021\u0023-\u005B\u005D-\u007E]+$/.test(scope)) throw new TypeError(`${location} must satisfy the OAuth scope-token grammar`);
740
+ }
741
+ function validateScopeChallenge(challenge) {
742
+ if (challenge === null || typeof challenge !== "object" || !Array.isArray(challenge.scopes) || challenge.scopes.length === 0) throw new TypeError("scope challenge must contain at least one scope");
743
+ for (const [index, scope] of challenge.scopes.entries()) assertScope(scope, `scope challenge scopes[${index}]`);
744
+ if (challenge.errorDescription !== void 0 && typeof challenge.errorDescription !== "string") throw new TypeError("scope challenge errorDescription must be a string");
745
+ if (challenge.errorDescription !== void 0 && !/^[\u0020-\u0021\u0023-\u005B\u005D-\u007E]+$/.test(challenge.errorDescription)) throw new TypeError("scope challenge errorDescription must satisfy the RFC 6750 error-description grammar");
746
+ return challenge;
747
+ }
748
+ /**
749
+ * Creates a handler that requires every supplied scope exactly.
750
+ *
751
+ * Requests without authentication are left to the server's authentication gate.
752
+ */
753
+ function requireScopes(...scopes) {
754
+ if (scopes.length === 0) throw new TypeError("requireScopes must contain at least one scope");
755
+ for (const [index, scope] of scopes.entries()) assertScope(scope, `requireScopes scope[${index}]`);
756
+ const requiredScopes = [...scopes];
757
+ return ({ authInfo }) => {
758
+ if (authInfo === void 0) return;
759
+ const activeScopes = new Set(authInfo.scopes);
760
+ if (requiredScopes.every((scope) => activeScopes.has(scope))) return;
761
+ return { scopes: requiredScopes };
762
+ };
763
+ }
764
+ /** @internal */
765
+ async function findScopeChallenge(requests, authInfo, resolve) {
766
+ for (const request of requests) {
767
+ const challenge = await resolve({
768
+ request,
769
+ ...authInfo !== void 0 && { authInfo }
770
+ });
771
+ if (challenge !== void 0) return validateScopeChallenge(challenge);
772
+ }
773
+ }
774
+ /**
775
+ * The RFC 9728 Protected Resource Metadata URL to advertise on a scope
776
+ * challenge, derived from the verified {@link AuthInfo}: the URL the
777
+ * authentication gate stamped (`authInfo.resourceMetadataUrl`, set by the
778
+ * bearer-auth helpers from their `resourceMetadataUrl` option), falling back
779
+ * to the well-known location for an HTTP(S) RFC 8707 `resource` identifier, or
780
+ * `undefined` when neither is available (the `resource_metadata` parameter is
781
+ * then omitted, matching the bearer-auth challenges).
782
+ *
783
+ * @internal
784
+ */
785
+ function scopeChallengeResourceMetadataUrl(authInfo) {
786
+ if (authInfo?.resourceMetadataUrl !== void 0) return authInfo.resourceMetadataUrl;
787
+ if (authInfo?.resource?.protocol === "https:" || authInfo?.resource?.protocol === "http:") return getOAuthProtectedResourceMetadataUrl(authInfo.resource);
788
+ }
789
+ /** @internal */
790
+ function createScopeChallengeResponse(challenge, resourceMetadataUrl) {
791
+ return bearerAuthChallengeResponse(new OAuthError(OAuthErrorCode.InsufficientScope, challenge.errorDescription ?? "Insufficient scope"), {
792
+ requiredScopes: [...challenge.scopes],
793
+ resourceMetadataUrl
794
+ });
795
+ }
796
+
797
+ //#endregion
798
+ //#region src/server/legacyInputRequiredShim.ts
799
+ /**
800
+ * Default handler re-entries per originating request — tighter than the
801
+ * client driver's 10 because the shim holds a live wire request open.
802
+ */
803
+ const DEFAULT_LEGACY_SHIM_MAX_ROUNDS = 8;
804
+ /** Default per-leg timeout: legs are human-paced, so the 60s protocol default is wrong. */
805
+ const DEFAULT_LEGACY_SHIM_ROUND_TIMEOUT_MS = 6e5;
806
+ /** Resolves and validates `ServerOptions.inputRequired`, failing loudly at construction time. */
807
+ function resolveLegacyShimOptions(options) {
808
+ if (options?.maxRounds !== void 0 && (!Number.isInteger(options.maxRounds) || options.maxRounds < 1)) throw new RangeError(`inputRequired.maxRounds must be a positive integer (got ${options.maxRounds})`);
809
+ if (options?.roundTimeoutMs !== void 0 && (!Number.isFinite(options.roundTimeoutMs) || options.roundTimeoutMs <= 0)) throw new RangeError(`inputRequired.roundTimeoutMs must be a positive number (got ${options.roundTimeoutMs})`);
810
+ return {
811
+ maxRounds: options?.maxRounds ?? DEFAULT_LEGACY_SHIM_MAX_ROUNDS,
812
+ roundTimeoutMs: options?.roundTimeoutMs ?? DEFAULT_LEGACY_SHIM_ROUND_TIMEOUT_MS,
813
+ legacyShim: options?.legacyShim ?? true
814
+ };
815
+ }
816
+ /**
817
+ * Validates one `inputRequests` entry: malformed or unknown kinds are server
818
+ * bugs and fail loudly on both eras. Shared by the modern seam's capability
819
+ * check and the shim's gate.
820
+ */
821
+ function coerceEmbeddedInputRequest(method, key, entry) {
822
+ if (entry === null || typeof entry !== "object" || typeof entry.method !== "string") throw new ProtocolError(ProtocolErrorCode.InternalError, `Handler for ${method} returned an invalid input request '${key}': each inputRequests entry must be an embedded elicitation/create, sampling/createMessage, or roots/list request`);
823
+ const embedded = entry;
824
+ const required = requiredClientCapabilitiesForInputRequest(embedded);
825
+ if (required === void 0) throw new ProtocolError(ProtocolErrorCode.InternalError, `Handler for ${method} returned an input request '${key}' of kind '${embedded.method}', which is not an embedded request the 2026-07-28 revision defines`);
826
+ return {
827
+ embedded,
828
+ required
829
+ };
830
+ }
831
+ /**
832
+ * The 2025-11-25 URL-mode wire shape requires an `elicitationId`; the 2026
833
+ * in-band shape has none, so URL legs mint one (CSPRNG-backed, with a
834
+ * getRandomValues fallback for runtimes without `randomUUID`).
835
+ */
836
+ function syntheticElicitationId() {
837
+ const webCrypto = globalThis.crypto;
838
+ if (webCrypto?.randomUUID !== void 0) return webCrypto.randomUUID();
839
+ const bytes = new Uint8Array(16);
840
+ webCrypto.getRandomValues(bytes);
841
+ bytes[6] = bytes[6] & 15 | 64;
842
+ bytes[8] = bytes[8] & 63 | 128;
843
+ const hex = [...bytes].map((byte) => byte.toString(16).padStart(2, "0")).join("");
844
+ return `${hex.slice(0, 8)}-${hex.slice(8, 12)}-${hex.slice(12, 16)}-${hex.slice(16, 20)}-${hex.slice(20)}`;
845
+ }
846
+ /** Per-family surfacing: tools/call → isError result (the 2025 idiom); prompts/resources → JSON-RPC error. */
847
+ function legacyShimFailure(method, message) {
848
+ if (method === "tools/call") return {
849
+ content: [{
850
+ type: "text",
851
+ text: message
852
+ }],
853
+ isError: true
854
+ };
855
+ throw new ProtocolError(ProtocolErrorCode.InternalError, message);
856
+ }
857
+ /** The fulfilment loop — see the module doc for the contract. */
858
+ var LegacyInputRequiredShim = class {
859
+ constructor(_host) {
860
+ this._host = _host;
861
+ }
862
+ async fulfill(method, handler, request, ctx, firstResult) {
863
+ const { maxRounds, roundTimeoutMs } = this._host;
864
+ const outerSignal = ctx.mcpReq.signal;
865
+ let current = firstResult;
866
+ let round = 0;
867
+ while (true) {
868
+ round += 1;
869
+ if (round > maxRounds) return legacyShimFailure(method, inputRequiredRoundsExceededMessage(method, maxRounds));
870
+ const inputRequests = current.inputRequests;
871
+ const hasInputRequests = inputRequests != null && Object.keys(inputRequests).length > 0;
872
+ const requestState = typeof current.requestState === "string" ? current.requestState : void 0;
873
+ if (!hasInputRequests && requestState === void 0) throw new ProtocolError(ProtocolErrorCode.InternalError, `Handler for ${method} returned an input-required result with neither inputRequests nor requestState (every InputRequiredResult must include at least one of the two)`);
874
+ let responses;
875
+ if (hasInputRequests) {
876
+ const declared = this._host.resolvedClientCapabilities(ctx);
877
+ const coerced = [];
878
+ for (const [key, entry] of Object.entries(inputRequests)) {
879
+ const { embedded, required } = coerceEmbeddedInputRequest(method, key, entry);
880
+ if (embedded.method !== "roots/list" && embedded.params === void 0) throw new ProtocolError(ProtocolErrorCode.InternalError, `Handler for ${method} returned an input request '${key}' of kind '${embedded.method}' without params`);
881
+ if (missingClientCapabilities(required, declared) !== void 0) return legacyShimFailure(method, `Cannot request input '${key}' (${embedded.method}): the client on this 2025-era connection did not declare the required capability${declared === void 0 ? " (no client capabilities are available on this connection — per-request legacy serving cannot receive server-to-client requests)" : ""}`);
882
+ coerced.push([key, embedded]);
883
+ }
884
+ const roundAbort = linkedRoundAbort(outerSignal);
885
+ try {
886
+ const legOptions = {
887
+ relatedRequestId: ctx.mcpReq.id,
888
+ timeout: roundTimeoutMs,
889
+ resetTimeoutOnProgress: true,
890
+ onprogress: () => {},
891
+ signal: roundAbort.signal
892
+ };
893
+ const fulfilled = await Promise.all(coerced.map(async ([key, embedded]) => {
894
+ try {
895
+ return [key, await this._dispatchLeg(embedded, legOptions)];
896
+ } catch (error) {
897
+ roundAbort.abort(error);
898
+ throw error;
899
+ }
900
+ }));
901
+ responses = Object.fromEntries(fulfilled);
902
+ } catch (error) {
903
+ if (outerSignal.aborted) throw error;
904
+ return legacyShimFailure(method, `Fulfilling input required by '${method}' failed: ${error instanceof Error ? error.message : String(error)}`);
905
+ } finally {
906
+ roundAbort.dispose();
907
+ }
908
+ } else await sleep(REQUEST_STATE_ONLY_LEG_PACING_MS, outerSignal);
909
+ let ctxNext = {
910
+ ...ctx,
911
+ mcpReq: {
912
+ ...ctx.mcpReq,
913
+ inputResponses: responses,
914
+ droppedInputResponseKeys: void 0,
915
+ requestState: requestStateAccessor(requestState)
916
+ }
917
+ };
918
+ if (requestState !== void 0) {
919
+ const decoded = await this._host.verifyRequestState(requestState, ctxNext, method);
920
+ if (decoded !== void 0) ctxNext = withRequestStateValue(ctxNext, decoded);
921
+ }
922
+ const next = await handler(request, ctxNext);
923
+ if (!isInputRequiredResult(next)) return next;
924
+ current = next;
925
+ }
926
+ }
927
+ /** Routes one embedded request through the host's existing 2025-era senders (gate already ran). */
928
+ async _dispatchLeg(embedded, options) {
929
+ switch (embedded.method) {
930
+ case "elicitation/create": {
931
+ let params = embedded.params;
932
+ if (params.mode === "url" && params.elicitationId === void 0) params = {
933
+ ...params,
934
+ elicitationId: syntheticElicitationId()
935
+ };
936
+ return await this._host.sendElicitation(params, options);
937
+ }
938
+ case "sampling/createMessage": return await this._host.sendSampling(embedded.params, options);
939
+ case "roots/list": return await this._host.listRoots(embedded.params, options);
940
+ }
941
+ }
942
+ };
943
+
944
+ //#endregion
945
+ //#region src/server/server.ts
946
+ /**
947
+ * The request methods whose 2026-07-28 result vocabulary includes
948
+ * `input_required` (the multi round-trip methods). Returning an
949
+ * input-required result from any other handler is a server bug.
950
+ */
951
+ const INPUT_REQUIRED_CAPABLE_METHODS = new Set([
952
+ "tools/call",
953
+ "prompts/get",
954
+ "resources/read"
955
+ ]);
956
+ let writeClientIdentity;
957
+ let installDiscoverHandler;
958
+ let readServerIdentity;
959
+ /**
960
+ * Package-internal: backfills the connection-scoped client-identity fields of a
961
+ * per-request server instance from the request's validated `_meta` envelope, so the
962
+ * (deprecated) {@linkcode Server.getClientCapabilities} / {@linkcode Server.getClientVersion}
963
+ * accessors keep answering on instances that never see an `initialize` handshake.
964
+ * Not public API.
965
+ */
966
+ function seedClientIdentityFromEnvelope(server, identity) {
967
+ writeClientIdentity(server, identity);
968
+ }
969
+ /**
970
+ * Package-internal: installs the modern-only `server/discover` handler on an instance
971
+ * the HTTP entry has marked as serving the 2026-07-28 era, and makes sure the modern
972
+ * revisions the entry serves appear in the instance's supported-versions list (so the
973
+ * discover advertisement and version-mismatch errors name them). Idempotent.
974
+ * Hand-constructed instances are unaffected: nothing else calls this, so they keep
975
+ * answering `-32601` unless their own supported-versions list opts into a modern
976
+ * revision. Not public API.
977
+ */
978
+ function installModernOnlyHandlers(server, servedModernVersions) {
979
+ installDiscoverHandler(server, servedModernVersions);
980
+ }
981
+ /**
982
+ * Package-internal: the instance's implementation identity, for the serving
983
+ * entries to stamp onto entry-built results (the `subscriptions/listen`
984
+ * graceful-close result — built outside the encode seam, but the spec's
985
+ * `SubscriptionsListenResultMetaObject` extends `ResultMetaObject`, so it carries
986
+ * the serverInfo SHOULD like every other result). Not public API.
987
+ */
988
+ function serverIdentityOf(server) {
989
+ return readServerIdentity(server);
990
+ }
991
+ /**
992
+ * An MCP server on top of a pluggable transport.
993
+ *
994
+ * This server will automatically respond to the initialization flow as initiated from the client.
995
+ *
996
+ * @deprecated Use {@linkcode server/mcp.McpServer | McpServer} instead for the high-level API. Only use `Server` for advanced use cases.
997
+ */
998
+ var Server = class extends Protocol {
999
+ _clientCapabilities;
1000
+ _clientVersion;
1001
+ static {
1002
+ writeClientIdentity = (server, identity) => {
1003
+ if (identity.clientCapabilities !== void 0) server._clientCapabilities = identity.clientCapabilities;
1004
+ if (identity.clientInfo !== void 0) server._clientVersion = identity.clientInfo;
1005
+ };
1006
+ installDiscoverHandler = (server, servedModernVersions) => {
1007
+ const missing = servedModernVersions.filter((version) => !server._supportedProtocolVersions.includes(version));
1008
+ if (missing.length > 0) server._supportedProtocolVersions = [...server._supportedProtocolVersions, ...missing];
1009
+ server.setRequestHandler("server/discover", () => server._ondiscover());
1010
+ };
1011
+ readServerIdentity = (server) => server._serverInfo;
1012
+ }
1013
+ _capabilities;
1014
+ _instructions;
1015
+ _jsonSchemaValidator;
1016
+ _cacheHints;
1017
+ _requestStateVerify;
1018
+ _inputRequiredServing;
1019
+ _legacyShim;
1020
+ /** Lazily-built legacy shim; the loop lives in legacyInputRequiredShim.ts behind a narrow host contract. */
1021
+ _legacyInputRequiredShim() {
1022
+ return this._legacyShim ??= new LegacyInputRequiredShim({
1023
+ maxRounds: this._inputRequiredServing.maxRounds,
1024
+ roundTimeoutMs: this._inputRequiredServing.roundTimeoutMs,
1025
+ resolvedClientCapabilities: (ctx) => this._inputRequestCapabilityView(ctx),
1026
+ verifyRequestState: (state, ctx, method) => this._verifyRequestState(state, ctx, method),
1027
+ sendElicitation: (params, options) => this._sendElicitationLeg(params, options, { validateAcceptedContent: false }),
1028
+ sendSampling: (params, options) => this.createMessage(params, options),
1029
+ listRoots: (params, options) => this.listRoots(params, options)
1030
+ });
1031
+ }
1032
+ /**
1033
+ * Callback for when initialization has fully completed (i.e., the client has sent an `notifications/initialized` notification).
1034
+ */
1035
+ oninitialized;
1036
+ /**
1037
+ * Initializes this server with the given name and version information.
1038
+ */
1039
+ constructor(_serverInfo, options) {
1040
+ super(options);
1041
+ this._serverInfo = _serverInfo;
1042
+ this._capabilities = options?.capabilities ? { ...options.capabilities } : {};
1043
+ this._instructions = options?.instructions;
1044
+ this._jsonSchemaValidator = options?.jsonSchemaValidator ?? new DefaultJsonSchemaValidator();
1045
+ this._requestStateVerify = options?.requestState?.verify;
1046
+ this._inputRequiredServing = resolveLegacyShimOptions(options?.inputRequired);
1047
+ if (options?.cacheHints !== void 0) {
1048
+ for (const [operation, hint] of Object.entries(options.cacheHints)) if (hint !== void 0) assertValidCacheHint(hint, `cacheHints['${operation}']`);
1049
+ this._cacheHints = options.cacheHints;
1050
+ }
1051
+ this.setRequestHandler("initialize", (request) => this._oninitialize(request));
1052
+ this.setNotificationHandler("notifications/initialized", () => this.oninitialized?.());
1053
+ if (modernProtocolVersions(this._supportedProtocolVersions).length > 0) this.setRequestHandler("server/discover", () => this._ondiscover());
1054
+ if (this._capabilities.logging) this._registerLoggingHandler();
1055
+ }
1056
+ /** Attaches to the given transport; rejects while this instance is connected to another one. */
1057
+ async connect(transport) {
1058
+ if (this.transport !== void 0) throw new SdkError(SdkErrorCode.AlreadyConnected, "Use a separate Server instance per connection: this instance is already connected to a transport. To connect it to a new transport, call close() first.");
1059
+ await super.connect(transport);
1060
+ }
1061
+ /**
1062
+ * Registers the built-in `logging/setLevel` request handler.
1063
+ *
1064
+ * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).
1065
+ * Remains functional during the deprecation window (at least twelve months).
1066
+ * Migrate to stderr logging (STDIO servers) or OpenTelemetry.
1067
+ */
1068
+ _registerLoggingHandler() {
1069
+ this.setRequestHandler("logging/setLevel", async (request, ctx) => {
1070
+ const transportSessionId = ctx.sessionId || ctx.http?.req?.headers.get("mcp-session-id") || void 0;
1071
+ const { level } = request.params;
1072
+ const parseResult = parseSchema(LoggingLevelSchema, level);
1073
+ if (parseResult.success) this._loggingLevels.set(transportSessionId, parseResult.data);
1074
+ return {};
1075
+ });
1076
+ }
1077
+ buildContext(ctx, transportInfo) {
1078
+ const hasHttpInfo = ctx.http || transportInfo?.request || transportInfo?.closeSSEStream || transportInfo?.closeStandaloneSSEStream;
1079
+ return {
1080
+ ...ctx,
1081
+ mcpReq: {
1082
+ ...ctx.mcpReq,
1083
+ log: (level, data, logger) => {
1084
+ if (!this._capabilities.logging) return Promise.resolve();
1085
+ let threshold;
1086
+ if (this._servedModernEra()) {
1087
+ threshold = ctx.mcpReq.envelope?.[LOG_LEVEL_META_KEY];
1088
+ if (threshold === void 0) return Promise.resolve();
1089
+ } else threshold = this._loggingLevels.get(ctx.sessionId) ?? this._loggingLevels.get(void 0);
1090
+ if (threshold !== void 0 && this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(threshold)) return Promise.resolve();
1091
+ return ctx.mcpReq.notify({
1092
+ method: "notifications/message",
1093
+ params: {
1094
+ level,
1095
+ data,
1096
+ logger
1097
+ }
1098
+ });
1099
+ },
1100
+ elicitInput: (params, options) => this.elicitInput(params, options),
1101
+ requestSampling: (params, options) => this.createMessage(params, options)
1102
+ },
1103
+ http: hasHttpInfo ? {
1104
+ ...ctx.http,
1105
+ req: transportInfo?.request,
1106
+ closeSSE: transportInfo?.closeSSEStream,
1107
+ closeStandaloneSSE: transportInfo?.closeStandaloneSSEStream
1108
+ } : void 0
1109
+ };
1110
+ }
1111
+ _loggingLevels = /* @__PURE__ */ new Map();
1112
+ LOG_LEVEL_SEVERITY = new Map(LoggingLevelSchema.options.map((level, index) => [level, index]));
1113
+ isMessageIgnored = (level, sessionId) => {
1114
+ const currentLevel = this._loggingLevels.get(sessionId);
1115
+ return currentLevel ? this.LOG_LEVEL_SEVERITY.get(level) < this.LOG_LEVEL_SEVERITY.get(currentLevel) : false;
1116
+ };
1117
+ /**
1118
+ * Registers new capabilities. This can only be called before connecting to a transport.
1119
+ *
1120
+ * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
1121
+ */
1122
+ registerCapabilities(capabilities) {
1123
+ if (this.transport) throw new SdkError(SdkErrorCode.AlreadyConnected, "Cannot register capabilities after connecting to transport");
1124
+ const hadLogging = !!this._capabilities.logging;
1125
+ this._capabilities = mergeCapabilities(this._capabilities, capabilities);
1126
+ if (!hadLogging && this._capabilities.logging) this._registerLoggingHandler();
1127
+ }
1128
+ /**
1129
+ * Enforces server-side validation for `tools/call` results regardless of how the
1130
+ * handler was registered, attaches the configured per-operation cache hint
1131
+ * (when one exists) so the 2026-07-28 encode seam can fill `ttlMs`/`cacheScope`
1132
+ * for results that do not provide their own, and owns the multi-round-trip
1133
+ * seam: on the methods whose 2026-07-28 result vocabulary includes
1134
+ * `input_required` (`tools/call`, `prompts/get`, `resources/read`) an
1135
+ * input-required return skips result-schema validation and is checked
1136
+ * against the served era, the at-least-one rule, and the request's own
1137
+ * declared client capabilities; on every other method an input-required
1138
+ * return is a server bug and fails loudly. The hint rides a symbol-keyed
1139
+ * property that is never serialized, so 2025-era responses are unaffected.
1140
+ */
1141
+ _wrapHandler(method, handler) {
1142
+ if (method !== "tools/call") {
1143
+ const cacheHint = this._cacheHints?.[method];
1144
+ const isInputRequiredCapable = INPUT_REQUIRED_CAPABLE_METHODS.has(method);
1145
+ if (cacheHint === void 0 && !isInputRequiredCapable) return async (request, ctx) => {
1146
+ const result = await handler(request, ctx);
1147
+ if (isInputRequiredResult(result)) throw new ProtocolError(ProtocolErrorCode.InternalError, `Handler for ${method} returned an input-required result, but only tools/call, prompts/get and resources/read support input_required (protocol revision 2026-07-28)`);
1148
+ return result;
1149
+ };
1150
+ return async (request, ctx) => {
1151
+ const result = isInputRequiredCapable ? await this._invokeInputRequiredCapableHandler(method, handler, request, ctx) : await handler(request, ctx);
1152
+ if (isInputRequiredResult(result)) {
1153
+ if (!isInputRequiredCapable) throw new ProtocolError(ProtocolErrorCode.InternalError, `Handler for ${method} returned an input-required result, but only tools/call, prompts/get and resources/read support input_required (protocol revision 2026-07-28)`);
1154
+ return result;
1155
+ }
1156
+ return cacheHint === void 0 ? result : attachCacheHintFallback(result, cacheHint);
1157
+ };
1158
+ }
1159
+ return async (request, ctx) => {
1160
+ const codec = codecForVersion(this._negotiatedProtocolVersion);
1161
+ const validatedRequest = codec.validateRequest("tools/call", request);
1162
+ if (!validatedRequest.ok) throw new ProtocolError(validatedRequest.reason === "not-in-era" ? ProtocolErrorCode.InternalError : ProtocolErrorCode.InvalidParams, validatedRequest.reason === "not-in-era" ? "No wire schema for tools/call in the resolved era" : `Invalid tools/call request: ${validatedRequest.message}`);
1163
+ const result = await this._invokeInputRequiredCapableHandler("tools/call", handler, request, ctx);
1164
+ if (isInputRequiredResult(result)) return result;
1165
+ const normalizedResult = normalizeContentlessToolResult(result);
1166
+ const validationResult = codec.validateResult("tools/call", normalizedResult);
1167
+ if (!validationResult.ok) throw new ProtocolError(validationResult.reason === "not-in-era" ? ProtocolErrorCode.InternalError : ProtocolErrorCode.InvalidParams, validationResult.reason === "not-in-era" ? "No wire schema for tools/call in the resolved era" : `Invalid tools/call result: ${validationResult.message}`);
1168
+ return validationResult.value;
1169
+ };
1170
+ }
1171
+ /**
1172
+ * Whether this instance is bound to a 2026-07-28-or-later protocol
1173
+ * revision. Era is instance state — a serving entry (`createMcpHandler`,
1174
+ * `serveStdio`) marks the instance modern at construction; a 2025-era
1175
+ * `initialize` handshake binds it legacy. The multi-round-trip seam reads
1176
+ * this directly: there is no per-request era consult.
1177
+ */
1178
+ _servedModernEra() {
1179
+ return this._negotiatedProtocolVersion !== void 0 && isModernProtocolVersion(this._negotiatedProtocolVersion);
1180
+ }
1181
+ /**
1182
+ * Invokes a handler for one of the multi-round-trip methods and applies
1183
+ * the input-required seam:
1184
+ *
1185
+ * - a `UrlElicitationRequiredError` (or any 2025-style server→client
1186
+ * request idiom) escaping the handler on a request served on the
1187
+ * 2026-07-28 era fails LOUDLY with a clear steer to
1188
+ * `inputRequired.elicitUrl(...)` — the `-32042` error never reaches the
1189
+ * 2026-07-28 wire and the throw is not silently converted. Requests
1190
+ * served on the 2025 era keep today's `-32042` behavior byte-exact (the
1191
+ * error is rethrown unchanged).
1192
+ * - an input-required RETURN toward a 2026-07-28 request must satisfy
1193
+ * the at-least-one rule, and every embedded request must be covered by
1194
+ * the capabilities declared on the request's envelope (violations
1195
+ * answer the typed `-32021` error). Toward a 2025-era request the
1196
+ * return is fulfilled by the default-on legacy shim, whose own gate
1197
+ * consults the initialize-declared capabilities and surfaces
1198
+ * violations per family; `inputRequired.legacyShim: false` restores
1199
+ * the pre-shim loud failure.
1200
+ */
1201
+ async _invokeInputRequiredCapableHandler(method, handler, request, ctx) {
1202
+ const servedModern = this._servedModernEra();
1203
+ const rawRequestState = ctx.mcpReq.requestState();
1204
+ if (rawRequestState !== void 0 && typeof rawRequestState !== "string") throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Invalid or expired requestState", { reason: "invalid_request_state" });
1205
+ let ctxForHandler = ctx;
1206
+ if (typeof rawRequestState === "string") {
1207
+ const decoded = await this._verifyRequestState(rawRequestState, ctx, method);
1208
+ if (decoded !== void 0) ctxForHandler = withRequestStateValue(ctx, decoded);
1209
+ }
1210
+ let result;
1211
+ try {
1212
+ result = await handler(request, ctxForHandler);
1213
+ } catch (error) {
1214
+ if (error instanceof ProtocolError && error.code === ProtocolErrorCode.UrlElicitationRequired) {
1215
+ if (!servedModern) throw error;
1216
+ throw new ProtocolError(ProtocolErrorCode.InternalError, `URL elicitation cannot be signalled by throwing UrlElicitationRequiredError on protocol revision ${this._negotiatedProtocolVersion}: return inputRequired({ inputRequests: { …: inputRequired.elicitUrl(...) } }) from the handler instead. The urlElicitationRequired error (-32042) of earlier revisions is not available on this revision.`);
1217
+ }
1218
+ throw error;
1219
+ }
1220
+ if (!isInputRequiredResult(result)) return result;
1221
+ if (!servedModern) {
1222
+ if (!this._inputRequiredServing.legacyShim) throw new ProtocolError(ProtocolErrorCode.InternalError, `Handler for ${method} returned an input-required result, but this request is served on protocol revision ${this._negotiatedProtocolVersion ?? LATEST_PROTOCOL_VERSION}, which has no input_required vocabulary`);
1223
+ return await this._legacyInputRequiredShim().fulfill(method, handler, request, ctxForHandler, result);
1224
+ }
1225
+ const inputRequests = result.inputRequests;
1226
+ const hasInputRequests = inputRequests != null && Object.keys(inputRequests).length > 0;
1227
+ const hasRequestState = typeof result.requestState === "string";
1228
+ if (!hasInputRequests && !hasRequestState) throw new ProtocolError(ProtocolErrorCode.InternalError, `Handler for ${method} returned an input-required result with neither inputRequests nor requestState (every InputRequiredResult must include at least one of the two)`);
1229
+ if (hasInputRequests) {
1230
+ const declared = this._inputRequestCapabilityView(ctx);
1231
+ for (const [key, entry] of Object.entries(inputRequests)) {
1232
+ const { embedded, required } = coerceEmbeddedInputRequest(method, key, entry);
1233
+ const missing = missingClientCapabilities(required, declared);
1234
+ if (missing !== void 0) throw new MissingRequiredClientCapabilityError({ requiredCapabilities: missing }, `Cannot request input '${key}' (${embedded.method}): the request's client capabilities do not declare the required capability`);
1235
+ }
1236
+ }
1237
+ return result;
1238
+ }
1239
+ /**
1240
+ * Runs the configured `requestState.verify` hook and returns its
1241
+ * resolved value (`undefined` when unconfigured or the hook returns
1242
+ * nothing). Deny-on-error: any hook failure answers the frozen `-32602`;
1243
+ * the reason goes to `onerror` only.
1244
+ */
1245
+ async _verifyRequestState(state, ctx, method) {
1246
+ if (this._requestStateVerify === void 0) return;
1247
+ try {
1248
+ return await this._requestStateVerify(state, ctx);
1249
+ } catch (error) {
1250
+ this.onerror?.(/* @__PURE__ */ new Error(`requestState verification rejected ${method}: ${error instanceof Error ? error.message : String(error)}`));
1251
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Invalid or expired requestState", { reason: "invalid_request_state" });
1252
+ }
1253
+ }
1254
+ /**
1255
+ * The per-request resolved client-capabilities view: the request's own
1256
+ * `_meta` envelope on the 2026 era; the `initialize`-declared state on a
1257
+ * 2025-era connection. Per-request instances that never saw an
1258
+ * initialize (stateless legacy) hold nothing, so gates refuse there.
1259
+ */
1260
+ _inputRequestCapabilityView(ctx) {
1261
+ return this._servedModernEra() ? ctx.mcpReq.envelope?.[CLIENT_CAPABILITIES_META_KEY] : this._clientCapabilities;
1262
+ }
1263
+ /**
1264
+ * Guard for the push-style server→client request APIs ({@linkcode createMessage},
1265
+ * {@linkcode elicitInput}, {@linkcode listRoots}, {@linkcode ping}) on a
1266
+ * modern-era instance: the 2026-07-28 revision has no server→client request
1267
+ * channel, so the call fails before any wire traffic with a typed error
1268
+ * whose message steers to `inputRequired(...)`. The base era gate would
1269
+ * also reject it; this guard runs first to carry the steer.
1270
+ */
1271
+ _assertPushApiInServedEra(method) {
1272
+ if (this._servedModernEra()) throw new SdkError(SdkErrorCode.MethodNotSupportedByProtocolVersion, `Server-to-client requests are not available on protocol revision ${this._negotiatedProtocolVersion}: '${method}' cannot be sent while serving a request on that revision. Return inputRequired({ ... }) from the handler instead — the client fulfils the embedded requests and retries the original request (multi round-trip requests).`, {
1273
+ method,
1274
+ era: "2026-07-28"
1275
+ });
1276
+ }
1277
+ assertCapabilityForMethod(method) {
1278
+ switch (method) {
1279
+ case "sampling/createMessage":
1280
+ if (!this._clientCapabilities?.sampling) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Client does not support sampling (required for ${method})`);
1281
+ break;
1282
+ case "elicitation/create":
1283
+ if (!this._clientCapabilities?.elicitation) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Client does not support elicitation (required for ${method})`);
1284
+ break;
1285
+ case "roots/list":
1286
+ if (!this._clientCapabilities?.roots) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Client does not support listing roots (required for ${method})`);
1287
+ break;
1288
+ case "ping": break;
1289
+ }
1290
+ }
1291
+ assertNotificationCapability(method) {
1292
+ switch (method) {
1293
+ case "notifications/message":
1294
+ if (!this._capabilities.logging) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support logging (required for ${method})`);
1295
+ break;
1296
+ case "notifications/resources/updated":
1297
+ case "notifications/resources/list_changed":
1298
+ if (!this._capabilities.resources) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support notifying about resources (required for ${method})`);
1299
+ break;
1300
+ case "notifications/tools/list_changed":
1301
+ if (!this._capabilities.tools) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support notifying of tool list changes (required for ${method})`);
1302
+ break;
1303
+ case "notifications/prompts/list_changed":
1304
+ if (!this._capabilities.prompts) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support notifying of prompt list changes (required for ${method})`);
1305
+ break;
1306
+ case "notifications/elicitation/complete":
1307
+ if (!this._clientCapabilities?.elicitation?.url) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Client does not support URL elicitation (required for ${method})`);
1308
+ break;
1309
+ case "notifications/cancelled": break;
1310
+ case "notifications/progress": break;
1311
+ }
1312
+ }
1313
+ assertRequestHandlerCapability(method) {
1314
+ switch (method) {
1315
+ case "completion/complete":
1316
+ if (!this._capabilities.completions) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support completions (required for ${method})`);
1317
+ break;
1318
+ case "logging/setLevel":
1319
+ if (!this._capabilities.logging) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support logging (required for ${method})`);
1320
+ break;
1321
+ case "prompts/get":
1322
+ case "prompts/list":
1323
+ if (!this._capabilities.prompts) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support prompts (required for ${method})`);
1324
+ break;
1325
+ case "resources/list":
1326
+ case "resources/templates/list":
1327
+ case "resources/read":
1328
+ if (!this._capabilities.resources) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support resources (required for ${method})`);
1329
+ break;
1330
+ case "tools/call":
1331
+ case "tools/list":
1332
+ if (!this._capabilities.tools) throw new SdkError(SdkErrorCode.CapabilityNotSupported, `Server does not support tools (required for ${method})`);
1333
+ break;
1334
+ case "ping":
1335
+ case "initialize": break;
1336
+ }
1337
+ }
1338
+ async _oninitialize(request) {
1339
+ const requestedVersion = request.params.protocolVersion;
1340
+ this._clientCapabilities = request.params.capabilities;
1341
+ this._clientVersion = request.params.clientInfo;
1342
+ const legacyVersions = legacyProtocolVersions(this._supportedProtocolVersions);
1343
+ const protocolVersion = legacyVersions.includes(requestedVersion) ? requestedVersion : legacyVersions[0] ?? LATEST_PROTOCOL_VERSION;
1344
+ this._negotiatedProtocolVersion = protocolVersion;
1345
+ this.transport?.setProtocolVersion?.(protocolVersion);
1346
+ return {
1347
+ protocolVersion,
1348
+ capabilities: this.getCapabilities(),
1349
+ serverInfo: this._serverInfo,
1350
+ ...this._instructions && { instructions: this._instructions }
1351
+ };
1352
+ }
1353
+ /**
1354
+ * Answers `server/discover` (protocol revision 2026-07-28). `supportedVersions`
1355
+ * lists only modern revisions (2025-era versions are negotiated via `initialize`);
1356
+ * the capabilities are advertised as-is, listChanged/subscribe bits included
1357
+ * (see {@linkcode discoverAdvertisedCapabilities}).
1358
+ */
1359
+ _ondiscover() {
1360
+ return {
1361
+ supportedVersions: modernProtocolVersions(this._supportedProtocolVersions),
1362
+ capabilities: discoverAdvertisedCapabilities(this.getCapabilities()),
1363
+ ...this._instructions && { instructions: this._instructions }
1364
+ };
1365
+ }
1366
+ /**
1367
+ * The identity the 2026-era encode seam stamps into every outbound
1368
+ * result's `_meta` under `io.modelcontextprotocol/serverInfo` (spec PR
1369
+ * #3002: servers SHOULD identify themselves on every response).
1370
+ */
1371
+ _outboundServerInfo() {
1372
+ return this._serverInfo;
1373
+ }
1374
+ /**
1375
+ * After initialization has completed, this will be populated with the client's reported capabilities.
1376
+ *
1377
+ * @deprecated Read client identity from the per-request handler context instead: on
1378
+ * 2026-07-28 (per-request envelope) requests `ctx.mcpReq.envelope` carries the client's
1379
+ * declared capabilities, while on 2025-era connections this accessor keeps returning the
1380
+ * `initialize`-scoped value. The accessor remains functional — instances serving the
1381
+ * 2026-07-28 era are backfilled per request from the validated envelope.
1382
+ */
1383
+ getClientCapabilities() {
1384
+ return this._clientCapabilities;
1385
+ }
1386
+ /**
1387
+ * After initialization has completed, this will be populated with information about the client's name and version.
1388
+ *
1389
+ * @deprecated Read client identity from the per-request handler context instead: on
1390
+ * 2026-07-28 (per-request envelope) requests `ctx.mcpReq.envelope` carries the client's
1391
+ * name and version, while on 2025-era connections this accessor keeps returning the
1392
+ * `initialize`-scoped value. The accessor remains functional — instances serving the
1393
+ * 2026-07-28 era are backfilled per request from the validated envelope.
1394
+ */
1395
+ getClientVersion() {
1396
+ return this._clientVersion;
1397
+ }
1398
+ /**
1399
+ * After initialization has completed, this will be populated with the protocol version negotiated
1400
+ * with the client (the version the server responded with during the initialize handshake), or
1401
+ * `undefined` before initialization.
1402
+ *
1403
+ * @deprecated Read the protocol revision from the per-request handler context instead: on
1404
+ * 2026-07-28 (per-request envelope) requests `ctx.mcpReq.envelope` names the revision the
1405
+ * request was sent for, while on 2025-era connections this accessor keeps returning the
1406
+ * `initialize`-negotiated version. The accessor remains functional — instances serving the
1407
+ * 2026-07-28 era report that revision.
1408
+ */
1409
+ getNegotiatedProtocolVersion() {
1410
+ return this._negotiatedProtocolVersion;
1411
+ }
1412
+ /**
1413
+ * Project a `tools/call` result through this instance's negotiated wire
1414
+ * codec — the era-agnostic SEP-2106 §4.3 TextContent auto-append, plus on
1415
+ * the 2025 era the `{result:…}` wrap when `structuredContent` is a
1416
+ * non-object value or the advertised `outputSchema` had a non-object root.
1417
+ * Identity for object-shaped `structuredContent` on the 2026 era.
1418
+ *
1419
+ * `McpServer`'s built-in `tools/call` handler routes through this method.
1420
+ * Low-level `setRequestHandler('tools/call', …)` authors call it
1421
+ * themselves so the projection lives in one place (the codec) and the
1422
+ * server-side handler stays era-blind.
1423
+ *
1424
+ * This is the only codec function exposed on `Server` — the full
1425
+ * `WireCodec` is intentionally not part of the public surface.
1426
+ */
1427
+ projectCallToolResult(result, advertisedOutputSchema) {
1428
+ return this._wireCodec().projectCallToolResult(result, advertisedOutputSchema);
1429
+ }
1430
+ /**
1431
+ * Returns the current server capabilities.
1432
+ */
1433
+ getCapabilities() {
1434
+ return this._capabilities;
1435
+ }
1436
+ /**
1437
+ * Sends a `ping` request to the connected client.
1438
+ *
1439
+ * @deprecated The 2026-07-28 protocol removed ping; it throws on a 2026-07-28-era instance.
1440
+ * If your factory serves both eras, this only works on the legacy path.
1441
+ */
1442
+ async ping() {
1443
+ this._assertPushApiInServedEra("ping");
1444
+ return this.request({ method: "ping" });
1445
+ }
1446
+ async createMessage(params, options) {
1447
+ this._assertPushApiInServedEra("sampling/createMessage");
1448
+ if ((params.tools || params.toolChoice) && !this._clientCapabilities?.sampling?.tools) throw new SdkError(SdkErrorCode.CapabilityNotSupported, "Client does not support sampling tools capability.");
1449
+ if (params.messages.length > 0) {
1450
+ const lastMessage = params.messages.at(-1);
1451
+ const lastContent = Array.isArray(lastMessage.content) ? lastMessage.content : [lastMessage.content];
1452
+ const hasToolResults = lastContent.some((c) => c.type === "tool_result");
1453
+ const previousMessage = params.messages.length > 1 ? params.messages.at(-2) : void 0;
1454
+ const previousContent = previousMessage ? Array.isArray(previousMessage.content) ? previousMessage.content : [previousMessage.content] : [];
1455
+ const hasPreviousToolUse = previousContent.some((c) => c.type === "tool_use");
1456
+ if (hasToolResults) {
1457
+ if (lastContent.some((c) => c.type !== "tool_result")) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "The last message must contain only tool_result content if any is present");
1458
+ if (!hasPreviousToolUse) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "tool_result blocks are not matching any tool_use from the previous message");
1459
+ }
1460
+ if (hasPreviousToolUse) {
1461
+ const toolUseIds = new Set(previousContent.filter((c) => c.type === "tool_use").map((c) => c.id));
1462
+ const toolResultIds = new Set(lastContent.filter((c) => c.type === "tool_result").map((c) => c.toolUseId));
1463
+ if (toolUseIds.size !== toolResultIds.size || ![...toolUseIds].every((id) => toolResultIds.has(id))) throw new ProtocolError(ProtocolErrorCode.InvalidParams, "ids of tool_result blocks and tool_use blocks from previous message do not match");
1464
+ }
1465
+ }
1466
+ const hasTools = Boolean(params.tools || params.toolChoice);
1467
+ const wide = await this.request({
1468
+ method: "sampling/createMessage",
1469
+ params
1470
+ }, options);
1471
+ const outcome = this._wireCodec().samplingResultVariant(hasTools, wide);
1472
+ if (!outcome.ok) throw new SdkError(SdkErrorCode.InvalidResult, `Invalid sampling/createMessage result: ${outcome.reason === "invalid" ? outcome.message : outcome.reason}`);
1473
+ return outcome.value;
1474
+ }
1475
+ /**
1476
+ * Creates an elicitation request for the given parameters.
1477
+ * For backwards compatibility, `mode` may be omitted for form requests and will default to `"form"`.
1478
+ * @param params The parameters for the elicitation request.
1479
+ * @param options Optional request options.
1480
+ * @returns The result of the elicitation request.
1481
+ *
1482
+ * @deprecated Throws on a 2026-07-28-era request — use {@link index.inputRequired | inputRequired} (multi-round-trip)
1483
+ * instead. The 2025 push-style server-to-client request model is replaced by input_required
1484
+ * results in the 2026-07-28 protocol. If your factory serves both eras, this only works on the
1485
+ * legacy path.
1486
+ */
1487
+ async elicitInput(params, options) {
1488
+ this._assertPushApiInServedEra("elicitation/create");
1489
+ switch (params.mode ?? "form") {
1490
+ case "url":
1491
+ if (!this._clientCapabilities?.elicitation?.url) throw new SdkError(SdkErrorCode.CapabilityNotSupported, "Client does not support url elicitation.");
1492
+ break;
1493
+ case "form":
1494
+ if (!this._clientCapabilities?.elicitation?.form) throw new SdkError(SdkErrorCode.CapabilityNotSupported, "Client does not support form elicitation.");
1495
+ break;
1496
+ }
1497
+ return this._sendElicitationLeg(params, options);
1498
+ }
1499
+ /**
1500
+ * The capability-check-free core of {@linkcode elicitInput}. The shim
1501
+ * uses it because its gate differs from the public checks: a bare
1502
+ * `elicitation: {}` counts as form support (the pre-mode rule), and
1503
+ * accepted content passes through unvalidated for parity with the
1504
+ * modern client driver (handlers validate via the schema-aware
1505
+ * `acceptedContent` overload and can re-ask).
1506
+ */
1507
+ async _sendElicitationLeg(params, options, behavior) {
1508
+ const mode = params.mode ?? "form";
1509
+ const validateAcceptedContent = behavior?.validateAcceptedContent ?? true;
1510
+ switch (mode) {
1511
+ case "url": {
1512
+ const urlParams = params;
1513
+ return this.request({
1514
+ method: "elicitation/create",
1515
+ params: urlParams
1516
+ }, options);
1517
+ }
1518
+ case "form": {
1519
+ const formParams = params.mode === "form" ? params : {
1520
+ ...params,
1521
+ mode: "form"
1522
+ };
1523
+ const result = await this.request({
1524
+ method: "elicitation/create",
1525
+ params: formParams
1526
+ }, options);
1527
+ if (validateAcceptedContent && result.action === "accept" && result.content && formParams.requestedSchema) try {
1528
+ const validationResult = this._jsonSchemaValidator.getValidator(formParams.requestedSchema)(result.content);
1529
+ if (!validationResult.valid) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Elicitation response content does not match requested schema: ${validationResult.errorMessage}`);
1530
+ } catch (error) {
1531
+ if (error instanceof ProtocolError) throw error;
1532
+ throw new ProtocolError(ProtocolErrorCode.InternalError, `Error validating elicitation response: ${error instanceof Error ? error.message : String(error)}`);
1533
+ }
1534
+ return result;
1535
+ }
1536
+ }
1537
+ }
1538
+ /**
1539
+ * Creates a reusable callback that, when invoked, will send a `notifications/elicitation/complete`
1540
+ * notification for the specified elicitation ID.
1541
+ *
1542
+ * The notification (and the `elicitationId` it references) exists only on protocol revision
1543
+ * 2025-11-25 — the 2026-07-28 revision removed both. On a connection negotiated at 2026-07-28 the
1544
+ * returned callback rejects with a typed local error before anything reaches the transport
1545
+ * (the method is not part of that revision's wire registry).
1546
+ *
1547
+ * @param elicitationId The ID of the elicitation to mark as complete.
1548
+ * @param options Optional notification options. Useful when the completion notification should be related to a prior request.
1549
+ * @returns A function that emits the completion notification when awaited.
1550
+ */
1551
+ createElicitationCompletionNotifier(elicitationId, options) {
1552
+ if (!this._clientCapabilities?.elicitation?.url) throw new SdkError(SdkErrorCode.CapabilityNotSupported, "Client does not support URL elicitation (required for notifications/elicitation/complete)");
1553
+ return () => this.notification({
1554
+ method: "notifications/elicitation/complete",
1555
+ params: { elicitationId }
1556
+ }, options);
1557
+ }
1558
+ /**
1559
+ * Requests the list of roots from the client.
1560
+ *
1561
+ * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).
1562
+ * Throws on a 2026-07-28-era request — use {@link index.inputRequired | inputRequired} (multi-round-trip) instead,
1563
+ * or migrate to passing paths via tool parameters, resource URIs, or configuration. The 2025
1564
+ * push-style server-to-client request model is replaced by input_required results in the
1565
+ * 2026-07-28 protocol. If your factory serves both eras, this only works on the legacy path.
1566
+ */
1567
+ async listRoots(params, options) {
1568
+ this._assertPushApiInServedEra("roots/list");
1569
+ return this.request({
1570
+ method: "roots/list",
1571
+ params
1572
+ }, options);
1573
+ }
1574
+ /**
1575
+ * Sends a logging message to the client, if connected.
1576
+ * Note: You only need to send the parameters object, not the entire JSON-RPC message.
1577
+ * @see {@linkcode LoggingMessageNotification}
1578
+ * @param params
1579
+ * @param sessionId Optional for stateless transports and backward compatibility.
1580
+ *
1581
+ * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).
1582
+ * Remains functional during the deprecation window (at least twelve months).
1583
+ * Migrate to stderr logging (STDIO servers) or OpenTelemetry.
1584
+ */
1585
+ async sendLoggingMessage(params, sessionId) {
1586
+ if (this._capabilities.logging && !this.isMessageIgnored(params.level, sessionId)) return this.notification({
1587
+ method: "notifications/message",
1588
+ params
1589
+ });
1590
+ }
1591
+ async sendResourceUpdated(params) {
1592
+ return this.notification({
1593
+ method: "notifications/resources/updated",
1594
+ params
1595
+ });
1596
+ }
1597
+ async sendResourceListChanged() {
1598
+ return this.notification({ method: "notifications/resources/list_changed" });
1599
+ }
1600
+ async sendToolListChanged() {
1601
+ return this.notification({ method: "notifications/tools/list_changed" });
1602
+ }
1603
+ async sendPromptListChanged() {
1604
+ return this.notification({ method: "notifications/prompts/list_changed" });
1605
+ }
1606
+ };
1607
+ /**
1608
+ * The capability set a server advertises on `server/discover`. Pure — never
1609
+ * mutates the input; the legacy `initialize` advertisement is untouched.
1610
+ *
1611
+ * The serving entries serve `subscriptions/listen` themselves, so the
1612
+ * `listChanged` and `resources.subscribe` capability bits are advertised
1613
+ * as-is: a modern-era client uses them to decide which notification types to
1614
+ * request on its listen filter.
1615
+ */
1616
+ function discoverAdvertisedCapabilities(capabilities) {
1617
+ return { ...capabilities };
1618
+ }
1619
+
1620
+ //#endregion
1621
+ //#region src/server/mcp.ts
1622
+ function toolInputElementCount(value, max) {
1623
+ let count = 0;
1624
+ const stack = [value];
1625
+ while (stack.length > 0) {
1626
+ const node = stack.pop();
1627
+ if (node === null || typeof node !== "object") continue;
1628
+ if (Array.isArray(node)) for (const child of node) {
1629
+ if (++count > max) return count;
1630
+ if (child !== null && typeof child === "object") stack.push(child);
1631
+ }
1632
+ else for (const key in node) {
1633
+ if (!Object.prototype.hasOwnProperty.call(node, key)) continue;
1634
+ if (++count > max) return count;
1635
+ const child = node[key];
1636
+ if (child !== null && typeof child === "object") stack.push(child);
1637
+ }
1638
+ }
1639
+ return count;
1640
+ }
1641
+ function resolveMaxToolInputElements(value) {
1642
+ if (value === void 0 || value === Infinity) return void 0;
1643
+ if (typeof value !== "number" || Number.isNaN(value) || value < 1) throw new RangeError(`maxToolInputElements must be a number of at least 1, or Infinity, got ${String(value)}`);
1644
+ return value;
1645
+ }
1646
+ /**
1647
+ * High-level MCP server that provides a simpler API for working with resources, tools, and prompts.
1648
+ * For advanced usage (like sending notifications or setting custom request handlers), use the underlying
1649
+ * {@linkcode Server} instance available via the {@linkcode McpServer.server | server} property.
1650
+ *
1651
+ * @example
1652
+ * ```ts source="./mcp.examples.ts#McpServer_basicUsage"
1653
+ * const server = new McpServer({
1654
+ * name: 'my-server',
1655
+ * version: '1.0.0'
1656
+ * });
1657
+ * ```
1658
+ */
1659
+ var McpServer = class {
1660
+ /**
1661
+ * The underlying {@linkcode Server} instance, useful for advanced operations like sending notifications.
1662
+ */
1663
+ server;
1664
+ _maxToolInputElements;
1665
+ _registeredResources = {};
1666
+ _registeredResourceTemplates = {};
1667
+ _registeredTools = {};
1668
+ _registeredPrompts = {};
1669
+ /** Per-tool JSON-converted `inputSchema`, filled on first use by `toolInputSchemaJson()`. */
1670
+ _toolInputSchemaJson = {};
1671
+ /**
1672
+ * The JSON-serialized `inputSchema` of a registered tool, or `undefined`
1673
+ * when no such tool is registered. Used by the HTTP entry's pre-dispatch
1674
+ * SEP-2243 `Mcp-Param-*` validation step (which needs the same JSON Schema
1675
+ * `tools/list` would emit, before dispatch reaches the handler).
1676
+ *
1677
+ * @internal
1678
+ */
1679
+ toolInputSchemaJson(name) {
1680
+ const tool = this._registeredTools[name];
1681
+ if (tool === void 0 || !tool.enabled) return void 0;
1682
+ if (Object.hasOwn(this._toolInputSchemaJson, name)) return this._toolInputSchemaJson[name];
1683
+ if (tool.inputSchema === void 0) return EMPTY_OBJECT_JSON_SCHEMA;
1684
+ try {
1685
+ const json = standardSchemaToJsonSchema(tool.inputSchema, "input");
1686
+ this._toolInputSchemaJson[name] = json;
1687
+ return json;
1688
+ } catch {
1689
+ return;
1690
+ }
1691
+ }
1692
+ constructor(serverInfo, options) {
1693
+ this.server = new Server(serverInfo, options);
1694
+ this._maxToolInputElements = resolveMaxToolInputElements(options?.maxToolInputElements);
1695
+ if (options?.capabilities?.tools) this.setToolRequestHandlers();
1696
+ if (options?.capabilities?.resources) this.setResourceRequestHandlers();
1697
+ if (options?.capabilities?.prompts) this.setPromptRequestHandlers();
1698
+ }
1699
+ /**
1700
+ * Attaches to the given transport, starts it, and starts listening for messages.
1701
+ *
1702
+ * The `server` object assumes ownership of the {@linkcode Transport}, replacing any callbacks that have already been set, and expects that it is the only user of the {@linkcode Transport} instance going forward.
1703
+ *
1704
+ * @example
1705
+ * ```ts source="./mcp.examples.ts#McpServer_connect_stdio"
1706
+ * const server = new McpServer({ name: 'my-server', version: '1.0.0' });
1707
+ * const transport = new StdioServerTransport();
1708
+ * await server.connect(transport);
1709
+ * ```
1710
+ */
1711
+ async connect(transport) {
1712
+ if (supportsScopeChallengeResolver(transport)) transport.setScopeChallengeResolver((context) => this.resolveScopeChallenge(context));
1713
+ return await this.server.connect(transport);
1714
+ }
1715
+ /**
1716
+ * Closes the connection.
1717
+ */
1718
+ async close() {
1719
+ await this.server.close();
1720
+ }
1721
+ /** @internal */
1722
+ resolveScopeChallenge = (context) => {
1723
+ switch (context.request.method) {
1724
+ case "tools/call": {
1725
+ const toolName = context.request.params?.name;
1726
+ if (typeof toolName !== "string") return;
1727
+ const tool = this._registeredTools[toolName];
1728
+ if (tool === void 0 || !tool.enabled) return;
1729
+ return tool.scopeChallenge?.(context);
1730
+ }
1731
+ case "resources/read": {
1732
+ const resourceUri = context.request.params?.uri;
1733
+ if (typeof resourceUri !== "string") return;
1734
+ let uri;
1735
+ try {
1736
+ uri = new URL(resourceUri);
1737
+ } catch {
1738
+ return;
1739
+ }
1740
+ const resource = this._registeredResources[uri.toString()];
1741
+ if (resource !== void 0) return resource.enabled ? resource.scopeChallenge?.(context) : void 0;
1742
+ for (const template of Object.values(this._registeredResourceTemplates)) if (template.resourceTemplate.uriTemplate.match(uri.toString())) return template.enabled ? template.scopeChallenge?.(context) : void 0;
1743
+ return;
1744
+ }
1745
+ case "prompts/get": {
1746
+ const promptName = context.request.params?.name;
1747
+ if (typeof promptName !== "string") return;
1748
+ const prompt = this._registeredPrompts[promptName];
1749
+ if (prompt === void 0 || !prompt.enabled) return;
1750
+ return prompt.scopeChallenge?.(context);
1751
+ }
1752
+ default: return;
1753
+ }
1754
+ };
1755
+ _toolHandlersInitialized = false;
1756
+ setToolRequestHandlers() {
1757
+ if (this._toolHandlersInitialized) return;
1758
+ this.server.assertCanSetRequestHandler("tools/list");
1759
+ this.server.assertCanSetRequestHandler("tools/call");
1760
+ this.server.registerCapabilities({ tools: { listChanged: this.server.getCapabilities().tools?.listChanged ?? true } });
1761
+ this.server.setRequestHandler("tools/list", () => ({ tools: Object.entries(this._registeredTools).filter(([, tool]) => tool.enabled).map(([name, tool]) => {
1762
+ const toolDefinition = {
1763
+ name,
1764
+ title: tool.title,
1765
+ description: tool.description,
1766
+ inputSchema: tool.inputSchema ? convertListedInputSchema(name, tool.inputSchema) : EMPTY_OBJECT_JSON_SCHEMA,
1767
+ annotations: tool.annotations,
1768
+ icons: tool.icons,
1769
+ execution: tool.execution,
1770
+ _meta: tool._meta
1771
+ };
1772
+ if (tool.outputSchema) toolDefinition.outputSchema = standardSchemaToJsonSchema(tool.outputSchema, "output");
1773
+ return toolDefinition;
1774
+ }) }));
1775
+ this.server.setRequestHandler("tools/call", async (request, ctx) => {
1776
+ const tool = this._registeredTools[request.params.name];
1777
+ if (!tool) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Tool ${request.params.name} not found`);
1778
+ if (!tool.enabled) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Tool ${request.params.name} disabled`);
1779
+ try {
1780
+ const args = await this.validateToolInput(tool, request.params.arguments, request.params.name);
1781
+ const result = await this.executeToolHandler(tool, args, ctx);
1782
+ await this.validateToolOutput(tool, result, request.params.name);
1783
+ if (isInputRequiredResult(result)) return result;
1784
+ return this.server.projectCallToolResult(result, tool.outputSchemaJson);
1785
+ } catch (error) {
1786
+ if (error instanceof ProtocolError && error.code === ProtocolErrorCode.UrlElicitationRequired) throw error;
1787
+ return this.createToolError(error instanceof Error ? error.message : String(error));
1788
+ }
1789
+ });
1790
+ this._toolHandlersInitialized = true;
1791
+ }
1792
+ /**
1793
+ * Creates a tool error result.
1794
+ *
1795
+ * @param errorMessage - The error message.
1796
+ * @returns The tool error result.
1797
+ */
1798
+ createToolError(errorMessage) {
1799
+ return {
1800
+ content: [{
1801
+ type: "text",
1802
+ text: errorMessage
1803
+ }],
1804
+ isError: true
1805
+ };
1806
+ }
1807
+ /**
1808
+ * Validates tool input arguments against the tool's input schema.
1809
+ */
1810
+ async validateToolInput(tool, args, toolName) {
1811
+ if (this._maxToolInputElements !== void 0 && toolInputElementCount(args, this._maxToolInputElements) > this._maxToolInputElements) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for tool ${toolName}: arguments contain more than the maximum of ${this._maxToolInputElements} elements`);
1812
+ if (!tool.inputSchema) return;
1813
+ const parseResult = await validateStandardSchema(tool.inputSchema, args ?? {});
1814
+ if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Input validation error: Invalid arguments for tool ${toolName}: ${parseResult.error}`);
1815
+ return parseResult.data;
1816
+ }
1817
+ /**
1818
+ * Validates tool output against the tool's output schema.
1819
+ */
1820
+ async validateToolOutput(tool, result, toolName) {
1821
+ if (!tool.outputSchema) return;
1822
+ if (isInputRequiredResult(result)) return;
1823
+ if (result.isError) return;
1824
+ if (result.structuredContent === void 0) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Tool ${toolName} has an output schema but no structured content was provided`);
1825
+ const parseResult = await validateStandardSchema(tool.outputSchema, result.structuredContent);
1826
+ if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Output validation error: Invalid structured content for tool ${toolName}: ${parseResult.error}`);
1827
+ }
1828
+ /**
1829
+ * Executes a tool handler.
1830
+ */
1831
+ async executeToolHandler(tool, args, ctx) {
1832
+ return tool.executor(args, ctx);
1833
+ }
1834
+ _completionHandlerInitialized = false;
1835
+ setCompletionRequestHandler() {
1836
+ if (this._completionHandlerInitialized) return;
1837
+ this.server.assertCanSetRequestHandler("completion/complete");
1838
+ this.server.registerCapabilities({ completions: {} });
1839
+ this.server.setRequestHandler("completion/complete", async (request) => {
1840
+ switch (request.params.ref.type) {
1841
+ case "ref/prompt":
1842
+ assertCompleteRequestPrompt(request);
1843
+ return this.handlePromptCompletion(request, request.params.ref);
1844
+ case "ref/resource":
1845
+ assertCompleteRequestResourceTemplate(request);
1846
+ return this.handleResourceCompletion(request, request.params.ref);
1847
+ default: throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid completion reference: ${request.params.ref}`);
1848
+ }
1849
+ });
1850
+ this._completionHandlerInitialized = true;
1851
+ }
1852
+ async handlePromptCompletion(request, ref) {
1853
+ const prompt = this._registeredPrompts[ref.name];
1854
+ if (!prompt) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Prompt ${ref.name} not found`);
1855
+ if (!prompt.enabled) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Prompt ${ref.name} disabled`);
1856
+ if (!prompt.argsSchema) return EMPTY_COMPLETION_RESULT;
1857
+ const field = unwrapOptionalSchema(getSchemaShape(prompt.argsSchema)?.[request.params.argument.name]);
1858
+ if (!isCompletable(field)) return EMPTY_COMPLETION_RESULT;
1859
+ const completer = getCompleter(field);
1860
+ if (!completer) return EMPTY_COMPLETION_RESULT;
1861
+ return createCompletionResult(await completer(request.params.argument.value, request.params.context));
1862
+ }
1863
+ async handleResourceCompletion(request, ref) {
1864
+ const template = Object.values(this._registeredResourceTemplates).find((t) => t.resourceTemplate.uriTemplate.toString() === ref.uri);
1865
+ if (!template) {
1866
+ if (this._registeredResources[ref.uri]) return EMPTY_COMPLETION_RESULT;
1867
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource template ${request.params.ref.uri} not found`);
1868
+ }
1869
+ const completer = template.resourceTemplate.completeCallback(request.params.argument.name);
1870
+ if (!completer) return EMPTY_COMPLETION_RESULT;
1871
+ return createCompletionResult(await completer(request.params.argument.value, request.params.context));
1872
+ }
1873
+ _resourceHandlersInitialized = false;
1874
+ setResourceRequestHandlers() {
1875
+ if (this._resourceHandlersInitialized) return;
1876
+ this.server.assertCanSetRequestHandler("resources/list");
1877
+ this.server.assertCanSetRequestHandler("resources/templates/list");
1878
+ this.server.assertCanSetRequestHandler("resources/read");
1879
+ this.server.registerCapabilities({ resources: { listChanged: this.server.getCapabilities().resources?.listChanged ?? true } });
1880
+ this.server.setRequestHandler("resources/list", async (_request, ctx) => {
1881
+ const resources = Object.entries(this._registeredResources).filter(([_, resource]) => resource.enabled).map(([uri, resource]) => ({
1882
+ uri,
1883
+ name: resource.name,
1884
+ ...resource.metadata
1885
+ }));
1886
+ const templateResources = [];
1887
+ for (const template of Object.values(this._registeredResourceTemplates)) {
1888
+ if (!template.resourceTemplate.listCallback) continue;
1889
+ const result = await template.resourceTemplate.listCallback(ctx);
1890
+ for (const resource of result.resources) templateResources.push({
1891
+ ...template.metadata,
1892
+ ...resource
1893
+ });
1894
+ }
1895
+ return { resources: [...resources, ...templateResources] };
1896
+ });
1897
+ this.server.setRequestHandler("resources/templates/list", async () => {
1898
+ return { resourceTemplates: Object.entries(this._registeredResourceTemplates).map(([name, template]) => ({
1899
+ name,
1900
+ uriTemplate: template.resourceTemplate.uriTemplate.toString(),
1901
+ ...template.metadata
1902
+ })) };
1903
+ });
1904
+ this.server.setRequestHandler("resources/read", async (request, ctx) => {
1905
+ let uri;
1906
+ try {
1907
+ uri = new URL(request.params.uri);
1908
+ } catch {
1909
+ throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource URI ${request.params.uri} is invalid`, {
1910
+ uri: request.params.uri,
1911
+ reason: "invalid_uri"
1912
+ });
1913
+ }
1914
+ const resource = this._registeredResources[uri.toString()];
1915
+ if (resource) {
1916
+ if (!resource.enabled) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource ${uri} disabled`);
1917
+ return attachCacheHintFallback(await resource.readCallback(uri, ctx), resource.cacheHint);
1918
+ }
1919
+ for (const template of Object.values(this._registeredResourceTemplates)) {
1920
+ const variables = template.resourceTemplate.uriTemplate.match(uri.toString());
1921
+ if (variables) {
1922
+ if (!template.enabled) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Resource template ${template.resourceTemplate.uriTemplate} disabled`);
1923
+ return attachCacheHintFallback(await template.readCallback(uri, variables, ctx), template.cacheHint);
1924
+ }
1925
+ }
1926
+ throw new ResourceNotFoundError(request.params.uri);
1927
+ });
1928
+ this._resourceHandlersInitialized = true;
1929
+ }
1930
+ _promptHandlersInitialized = false;
1931
+ setPromptRequestHandlers() {
1932
+ if (this._promptHandlersInitialized) return;
1933
+ this.server.assertCanSetRequestHandler("prompts/list");
1934
+ this.server.assertCanSetRequestHandler("prompts/get");
1935
+ this.server.registerCapabilities({ prompts: { listChanged: this.server.getCapabilities().prompts?.listChanged ?? true } });
1936
+ this.server.setRequestHandler("prompts/list", () => ({ prompts: Object.entries(this._registeredPrompts).filter(([, prompt]) => prompt.enabled).map(([name, prompt]) => {
1937
+ return {
1938
+ name,
1939
+ title: prompt.title,
1940
+ description: prompt.description,
1941
+ arguments: prompt.argsSchema ? promptArgumentsFromStandardSchema(prompt.argsSchema) : void 0,
1942
+ icons: prompt.icons,
1943
+ _meta: prompt._meta
1944
+ };
1945
+ }) }));
1946
+ this.server.setRequestHandler("prompts/get", async (request, ctx) => {
1947
+ const prompt = this._registeredPrompts[request.params.name];
1948
+ if (!prompt) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Prompt ${request.params.name} not found`);
1949
+ if (!prompt.enabled) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Prompt ${request.params.name} disabled`);
1950
+ return prompt.handler(request.params.arguments, ctx);
1951
+ });
1952
+ this._promptHandlersInitialized = true;
1953
+ }
1954
+ registerResource(name, uriOrTemplate, config, readCallback) {
1955
+ const { cacheHint, scopeChallenge, ...resourceMetadata } = config;
1956
+ const metadata = resourceMetadata;
1957
+ if (cacheHint !== void 0) assertValidCacheHint(cacheHint, `resource ${name}`);
1958
+ if (typeof uriOrTemplate === "string") {
1959
+ if (this._registeredResources[uriOrTemplate]) throw new Error(`Resource ${uriOrTemplate} is already registered`);
1960
+ const registeredResource = this._createRegisteredResource(name, config.title, uriOrTemplate, metadata, scopeChallenge, readCallback);
1961
+ if (cacheHint !== void 0) registeredResource.cacheHint = cacheHint;
1962
+ this.setResourceRequestHandlers();
1963
+ this.sendResourceListChanged();
1964
+ return registeredResource;
1965
+ } else {
1966
+ if (this._registeredResourceTemplates[name]) throw new Error(`Resource template ${name} is already registered`);
1967
+ const registeredResourceTemplate = this._createRegisteredResourceTemplate(name, config.title, uriOrTemplate, metadata, scopeChallenge, readCallback);
1968
+ if (cacheHint !== void 0) registeredResourceTemplate.cacheHint = cacheHint;
1969
+ this.setResourceRequestHandlers();
1970
+ this.sendResourceListChanged();
1971
+ return registeredResourceTemplate;
1972
+ }
1973
+ }
1974
+ _createRegisteredResource(name, title, uri, metadata, scopeChallenge, readCallback) {
1975
+ const registeredResource = {
1976
+ name,
1977
+ title,
1978
+ metadata,
1979
+ readCallback,
1980
+ scopeChallenge,
1981
+ enabled: true,
1982
+ disable: () => registeredResource.update({ enabled: false }),
1983
+ enable: () => registeredResource.update({ enabled: true }),
1984
+ remove: () => registeredResource.update({ uri: null }),
1985
+ update: (updates) => {
1986
+ if (updates.uri !== void 0 && updates.uri !== uri) {
1987
+ delete this._registeredResources[uri];
1988
+ if (updates.uri) this._registeredResources[updates.uri] = registeredResource;
1989
+ }
1990
+ if (updates.name !== void 0) registeredResource.name = updates.name;
1991
+ if (updates.title !== void 0) registeredResource.title = updates.title;
1992
+ if (updates.metadata !== void 0) registeredResource.metadata = updates.metadata;
1993
+ if (updates.callback !== void 0) registeredResource.readCallback = updates.callback;
1994
+ if (updates.scopeChallenge !== void 0) registeredResource.scopeChallenge = updates.scopeChallenge === null ? void 0 : updates.scopeChallenge;
1995
+ if (updates.enabled !== void 0) registeredResource.enabled = updates.enabled;
1996
+ this.sendResourceListChanged();
1997
+ }
1998
+ };
1999
+ this._registeredResources[uri] = registeredResource;
2000
+ return registeredResource;
2001
+ }
2002
+ _createRegisteredResourceTemplate(name, title, template, metadata, scopeChallenge, readCallback) {
2003
+ const registeredResourceTemplate = {
2004
+ resourceTemplate: template,
2005
+ title,
2006
+ metadata,
2007
+ readCallback,
2008
+ scopeChallenge,
2009
+ enabled: true,
2010
+ disable: () => registeredResourceTemplate.update({ enabled: false }),
2011
+ enable: () => registeredResourceTemplate.update({ enabled: true }),
2012
+ remove: () => registeredResourceTemplate.update({ name: null }),
2013
+ update: (updates) => {
2014
+ if (updates.name !== void 0 && updates.name !== name) {
2015
+ delete this._registeredResourceTemplates[name];
2016
+ if (updates.name) this._registeredResourceTemplates[updates.name] = registeredResourceTemplate;
2017
+ }
2018
+ if (updates.title !== void 0) registeredResourceTemplate.title = updates.title;
2019
+ if (updates.template !== void 0) registeredResourceTemplate.resourceTemplate = updates.template;
2020
+ if (updates.metadata !== void 0) registeredResourceTemplate.metadata = updates.metadata;
2021
+ if (updates.callback !== void 0) registeredResourceTemplate.readCallback = updates.callback;
2022
+ if (updates.scopeChallenge !== void 0) registeredResourceTemplate.scopeChallenge = updates.scopeChallenge === null ? void 0 : updates.scopeChallenge;
2023
+ if (updates.enabled !== void 0) registeredResourceTemplate.enabled = updates.enabled;
2024
+ this.sendResourceListChanged();
2025
+ }
2026
+ };
2027
+ this._registeredResourceTemplates[name] = registeredResourceTemplate;
2028
+ const variableNames = template.uriTemplate.variableNames;
2029
+ if (Array.isArray(variableNames) && variableNames.some((v) => !!template.completeCallback(v))) this.setCompletionRequestHandler();
2030
+ return registeredResourceTemplate;
2031
+ }
2032
+ _createRegisteredPrompt(name, title, description, argsSchema, callback, icons, scopeChallenge, _meta) {
2033
+ let currentArgsSchema = argsSchema;
2034
+ let currentCallback = callback;
2035
+ const registeredPrompt = {
2036
+ title,
2037
+ description,
2038
+ argsSchema,
2039
+ icons,
2040
+ scopeChallenge,
2041
+ _meta,
2042
+ handler: createPromptHandler(name, argsSchema, callback),
2043
+ enabled: true,
2044
+ disable: () => registeredPrompt.update({ enabled: false }),
2045
+ enable: () => registeredPrompt.update({ enabled: true }),
2046
+ remove: () => registeredPrompt.update({ name: null }),
2047
+ update: (updates) => {
2048
+ if (updates.name !== void 0 && updates.name !== name) {
2049
+ delete this._registeredPrompts[name];
2050
+ if (updates.name) this._registeredPrompts[updates.name] = registeredPrompt;
2051
+ }
2052
+ if (updates.title !== void 0) registeredPrompt.title = updates.title;
2053
+ if (updates.description !== void 0) registeredPrompt.description = updates.description;
2054
+ if (updates.icons !== void 0) registeredPrompt.icons = updates.icons;
2055
+ if (updates.scopeChallenge !== void 0) registeredPrompt.scopeChallenge = updates.scopeChallenge === null ? void 0 : updates.scopeChallenge;
2056
+ if (updates._meta !== void 0) registeredPrompt._meta = updates._meta;
2057
+ let needsHandlerRegen = false;
2058
+ if (updates.argsSchema !== void 0) {
2059
+ registeredPrompt.argsSchema = updates.argsSchema;
2060
+ currentArgsSchema = updates.argsSchema;
2061
+ needsHandlerRegen = true;
2062
+ }
2063
+ if (updates.callback !== void 0) {
2064
+ currentCallback = updates.callback;
2065
+ needsHandlerRegen = true;
2066
+ }
2067
+ if (needsHandlerRegen) registeredPrompt.handler = createPromptHandler(name, currentArgsSchema, currentCallback);
2068
+ if (updates.enabled !== void 0) registeredPrompt.enabled = updates.enabled;
2069
+ this.sendPromptListChanged();
2070
+ }
2071
+ };
2072
+ this._registeredPrompts[name] = registeredPrompt;
2073
+ if (argsSchema) {
2074
+ const shape = getSchemaShape(argsSchema);
2075
+ if (shape) {
2076
+ if (Object.values(shape).some((field) => {
2077
+ return isCompletable(unwrapOptionalSchema(field));
2078
+ })) this.setCompletionRequestHandler();
2079
+ }
2080
+ }
2081
+ return registeredPrompt;
2082
+ }
2083
+ _createRegisteredTool(name, title, description, inputSchema, outputSchema, annotations, icons, execution, scopeChallenge, _meta, handler) {
2084
+ validateAndWarnToolName(name);
2085
+ let currentHandler = handler;
2086
+ let outputSchemaJson;
2087
+ const registeredTool = {
2088
+ title,
2089
+ description,
2090
+ inputSchema,
2091
+ outputSchema,
2092
+ get outputSchemaJson() {
2093
+ return outputSchemaJson ??= convertOutputSchemaJson(registeredTool.outputSchema);
2094
+ },
2095
+ set outputSchemaJson(value) {
2096
+ outputSchemaJson = value;
2097
+ },
2098
+ annotations,
2099
+ icons,
2100
+ execution,
2101
+ scopeChallenge,
2102
+ _meta,
2103
+ handler,
2104
+ executor: createToolExecutor(inputSchema, handler),
2105
+ enabled: true,
2106
+ disable: () => registeredTool.update({ enabled: false }),
2107
+ enable: () => registeredTool.update({ enabled: true }),
2108
+ remove: () => registeredTool.update({ name: null }),
2109
+ update: (updates) => {
2110
+ if (updates.name !== void 0 && updates.name !== name) {
2111
+ if (typeof updates.name === "string") validateAndWarnToolName(updates.name);
2112
+ delete this._registeredTools[name];
2113
+ delete this._toolInputSchemaJson[name];
2114
+ if (updates.name) {
2115
+ delete this._toolInputSchemaJson[updates.name];
2116
+ this._registeredTools[updates.name] = registeredTool;
2117
+ name = updates.name;
2118
+ }
2119
+ }
2120
+ if (updates.title !== void 0) registeredTool.title = updates.title;
2121
+ if (updates.description !== void 0) registeredTool.description = updates.description;
2122
+ let needsExecutorRegen = false;
2123
+ if (updates.paramsSchema !== void 0) {
2124
+ registeredTool.inputSchema = updates.paramsSchema;
2125
+ delete this._toolInputSchemaJson[name];
2126
+ needsExecutorRegen = true;
2127
+ }
2128
+ if (updates.callback !== void 0) {
2129
+ registeredTool.handler = updates.callback;
2130
+ currentHandler = updates.callback;
2131
+ needsExecutorRegen = true;
2132
+ }
2133
+ if (needsExecutorRegen) registeredTool.executor = createToolExecutor(registeredTool.inputSchema, currentHandler);
2134
+ if (updates.outputSchema !== void 0) {
2135
+ registeredTool.outputSchema = updates.outputSchema;
2136
+ registeredTool.outputSchemaJson = convertOutputSchemaJson(updates.outputSchema);
2137
+ }
2138
+ if (updates.annotations !== void 0) registeredTool.annotations = updates.annotations;
2139
+ if (updates.icons !== void 0) registeredTool.icons = updates.icons;
2140
+ if (updates.scopeChallenge !== void 0) registeredTool.scopeChallenge = updates.scopeChallenge === null ? void 0 : updates.scopeChallenge;
2141
+ if (updates._meta !== void 0) registeredTool._meta = updates._meta;
2142
+ if (updates.enabled !== void 0) registeredTool.enabled = updates.enabled;
2143
+ this.sendToolListChanged();
2144
+ }
2145
+ };
2146
+ this._registeredTools[name] = registeredTool;
2147
+ this.setToolRequestHandlers();
2148
+ this.sendToolListChanged();
2149
+ return registeredTool;
2150
+ }
2151
+ registerTool(name, config, cb) {
2152
+ if (this._registeredTools[name]) throw new Error(`Tool ${name} is already registered`);
2153
+ const { title, description, inputSchema, outputSchema, annotations, icons, scopeChallenge, _meta } = config;
2154
+ return this._createRegisteredTool(name, title, description, normalizeRawShapeSchema(inputSchema), normalizeRawShapeSchema(outputSchema), annotations, icons, void 0, scopeChallenge, _meta, cb);
2155
+ }
2156
+ registerPrompt(name, config, cb) {
2157
+ if (this._registeredPrompts[name]) throw new Error(`Prompt ${name} is already registered`);
2158
+ const { title, description, argsSchema, icons, scopeChallenge, _meta } = config;
2159
+ const registeredPrompt = this._createRegisteredPrompt(name, title, description, normalizeRawShapeSchema(argsSchema), cb, icons, scopeChallenge, _meta);
2160
+ this.setPromptRequestHandlers();
2161
+ this.sendPromptListChanged();
2162
+ return registeredPrompt;
2163
+ }
2164
+ /**
2165
+ * Checks if the server is connected to a transport.
2166
+ * @returns `true` if the server is connected
2167
+ */
2168
+ isConnected() {
2169
+ return this.server.transport !== void 0;
2170
+ }
2171
+ /**
2172
+ * Sends a logging message to the client, if connected.
2173
+ * Note: You only need to send the parameters object, not the entire JSON-RPC message.
2174
+ * @see {@linkcode LoggingMessageNotification}
2175
+ * @param params
2176
+ * @param sessionId Optional for stateless transports and backward compatibility.
2177
+ *
2178
+ * @example
2179
+ * ```ts source="./mcp.examples.ts#McpServer_sendLoggingMessage_basic"
2180
+ * await server.sendLoggingMessage({
2181
+ * level: 'info',
2182
+ * data: 'Processing complete'
2183
+ * });
2184
+ * ```
2185
+ *
2186
+ * @deprecated Deprecated as of protocol version 2026-07-28 (SEP-2577).
2187
+ * Remains functional during the deprecation window (at least twelve months).
2188
+ * Migrate to stderr logging (STDIO servers) or OpenTelemetry.
2189
+ */
2190
+ async sendLoggingMessage(params, sessionId) {
2191
+ return this.server.sendLoggingMessage(params, sessionId);
2192
+ }
2193
+ /**
2194
+ * Sends a resource list changed event to the client, if connected.
2195
+ */
2196
+ sendResourceListChanged() {
2197
+ if (this.isConnected()) this.server.sendResourceListChanged();
2198
+ }
2199
+ /**
2200
+ * Sends a tool list changed event to the client, if connected.
2201
+ */
2202
+ sendToolListChanged() {
2203
+ if (this.isConnected()) this.server.sendToolListChanged();
2204
+ }
2205
+ /**
2206
+ * Sends a prompt list changed event to the client, if connected.
2207
+ */
2208
+ sendPromptListChanged() {
2209
+ if (this.isConnected()) this.server.sendPromptListChanged();
2210
+ }
2211
+ };
2212
+ /**
2213
+ * A resource template combines a URI pattern with optional functionality to enumerate
2214
+ * all resources matching that pattern.
2215
+ */
2216
+ var ResourceTemplate = class {
2217
+ _uriTemplate;
2218
+ constructor(uriTemplate, _callbacks) {
2219
+ this._callbacks = _callbacks;
2220
+ this._uriTemplate = typeof uriTemplate === "string" ? new UriTemplate(uriTemplate) : uriTemplate;
2221
+ }
2222
+ /**
2223
+ * Gets the URI template pattern.
2224
+ */
2225
+ get uriTemplate() {
2226
+ return this._uriTemplate;
2227
+ }
2228
+ /**
2229
+ * Gets the list callback, if one was provided.
2230
+ */
2231
+ get listCallback() {
2232
+ return this._callbacks.list;
2233
+ }
2234
+ /**
2235
+ * Gets the callback for completing a specific URI template variable, if one was provided.
2236
+ */
2237
+ completeCallback(variable) {
2238
+ return this._callbacks.complete?.[variable];
2239
+ }
2240
+ };
2241
+ /**
2242
+ * Creates an executor that invokes the handler with the appropriate arguments.
2243
+ * When `inputSchema` is defined, the handler is called with `(args, ctx)`.
2244
+ * When `inputSchema` is undefined, the handler is called with just `(ctx)`.
2245
+ */
2246
+ function createToolExecutor(inputSchema, handler) {
2247
+ if (inputSchema) {
2248
+ const callback$1 = handler;
2249
+ return async (args, ctx) => callback$1(args, ctx);
2250
+ }
2251
+ const callback = handler;
2252
+ return async (_args, ctx) => callback(ctx);
2253
+ }
2254
+ const EMPTY_OBJECT_JSON_SCHEMA = {
2255
+ type: "object",
2256
+ properties: {}
2257
+ };
2258
+ /** Converts a tool's `inputSchema` for `tools/list` and warns on an invalid SEP-2243 `x-mcp-header` declaration. */
2259
+ function convertListedInputSchema(name, inputSchema) {
2260
+ const json = standardSchemaToJsonSchema(inputSchema, "input");
2261
+ const scan = scanXMcpHeaderDeclarations(json);
2262
+ if (!scan.valid) console.warn(`[mcp-sdk] tool '${name}' carries an invalid x-mcp-header declaration and will be excluded by conforming Streamable HTTP clients: ${scan.reason}`);
2263
+ return json;
2264
+ }
2265
+ /**
2266
+ * Convert a registered `outputSchema` to JSON Schema, memoised on {@link RegisteredTool.outputSchemaJson}
2267
+ * so `tools/call` passes the SAME advertised schema to the wire codec's `projectCallToolResult` that
2268
+ * `tools/list` emits (and that the 2025 codec's `encodeResult('tools/list', …)` may wrap). A conversion
2269
+ * failure yields `undefined` so the failure surfaces where it always has (`tools/list`).
2270
+ */
2271
+ function convertOutputSchemaJson(outputSchema) {
2272
+ if (outputSchema === void 0) return void 0;
2273
+ try {
2274
+ return standardSchemaToJsonSchema(outputSchema, "output");
2275
+ } catch {
2276
+ return;
2277
+ }
2278
+ }
2279
+ /**
2280
+ * Creates a type-safe prompt handler that captures the schema and callback in a closure.
2281
+ * This eliminates the need for type assertions at the call site.
2282
+ */
2283
+ function createPromptHandler(name, argsSchema, callback) {
2284
+ if (argsSchema) {
2285
+ const typedCallback = callback;
2286
+ return async (args, ctx) => {
2287
+ const parseResult = await validateStandardSchema(argsSchema, args ?? {});
2288
+ if (!parseResult.success) throw new ProtocolError(ProtocolErrorCode.InvalidParams, `Invalid arguments for prompt ${name}: ${parseResult.error}`);
2289
+ return typedCallback(parseResult.data, ctx);
2290
+ };
2291
+ } else {
2292
+ const typedCallback = callback;
2293
+ return async (_args, ctx) => {
2294
+ return typedCallback(ctx);
2295
+ };
2296
+ }
2297
+ }
2298
+ function createCompletionResult(suggestions) {
2299
+ return { completion: {
2300
+ values: suggestions.map(String).slice(0, 100),
2301
+ total: suggestions.length,
2302
+ hasMore: suggestions.length > 100
2303
+ } };
2304
+ }
2305
+ const EMPTY_COMPLETION_RESULT = { completion: {
2306
+ values: [],
2307
+ hasMore: false
2308
+ } };
2309
+ /** @internal Gets the shape of a Zod object schema */
2310
+ function getSchemaShape(schema) {
2311
+ const candidate = schema;
2312
+ if (candidate.shape && typeof candidate.shape === "object") return candidate.shape;
2313
+ }
2314
+ /** @internal Checks if a Zod schema is optional */
2315
+ function isOptionalSchema(schema) {
2316
+ return schema?.type === "optional";
2317
+ }
2318
+ /** @internal Unwraps an optional Zod schema */
2319
+ function unwrapOptionalSchema(schema) {
2320
+ if (!isOptionalSchema(schema)) return schema;
2321
+ return schema.def?.innerType ?? schema;
2322
+ }
2323
+
2324
+ //#endregion
2325
+ export { armSseKeepAlive as C, DEFAULT_SSE_KEEP_ALIVE_MS as S, isCompletable as T, DEFAULT_MAX_SUBSCRIPTIONS as _, seedClientIdentityFromEnvelope as a, InMemoryServerEventBus as b, findScopeChallenge as c, buildOAuthProtectedResourceMetadata as d, getOAuthProtectedResourceMetadataUrl as f, verifyBearerToken as g, requireBearerAuth as h, installModernOnlyHandlers as i, requireScopes as l, bearerAuthChallengeResponse as m, ResourceTemplate as n, serverIdentityOf as o, oauthMetadataResponse as p, Server as r, createScopeChallengeResponse as s, McpServer as t, scopeChallengeResourceMetadataUrl as u, StdioListenRouter as v, completable as w, createServerNotifier as x, createListenRouter as y };
2326
+ //# sourceMappingURL=mcp-DIH4cS6P.mjs.map