@mcpview/compose 0.0.0-stage → 0.10.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 (450) hide show
  1. package/CHANGELOG.md +242 -0
  2. package/LICENSE +21 -0
  3. package/README.md +494 -2
  4. package/esm/_dnt.polyfills.d.ts +18 -0
  5. package/esm/_dnt.polyfills.d.ts.map +1 -0
  6. package/esm/_dnt.polyfills.js +15 -0
  7. package/esm/_dnt.shims.d.ts +2 -0
  8. package/esm/_dnt.shims.d.ts.map +1 -0
  9. package/esm/_dnt.shims.js +57 -0
  10. package/esm/deps/jsr.io/@std/yaml/1.3.0/_chars.d.ts +33 -0
  11. package/esm/deps/jsr.io/@std/yaml/1.3.0/_chars.d.ts.map +1 -0
  12. package/esm/deps/jsr.io/@std/yaml/1.3.0/_chars.js +48 -0
  13. package/esm/deps/jsr.io/@std/yaml/1.3.0/_dumper_state.d.ts +106 -0
  14. package/esm/deps/jsr.io/@std/yaml/1.3.0/_dumper_state.d.ts.map +1 -0
  15. package/esm/deps/jsr.io/@std/yaml/1.3.0/_dumper_state.js +636 -0
  16. package/esm/deps/jsr.io/@std/yaml/1.3.0/_loader_state.d.ts +67 -0
  17. package/esm/deps/jsr.io/@std/yaml/1.3.0/_loader_state.d.ts.map +1 -0
  18. package/esm/deps/jsr.io/@std/yaml/1.3.0/_loader_state.js +1393 -0
  19. package/esm/deps/jsr.io/@std/yaml/1.3.0/_schema.d.ts +44 -0
  20. package/esm/deps/jsr.io/@std/yaml/1.3.0/_schema.d.ts.map +1 -0
  21. package/esm/deps/jsr.io/@std/yaml/1.3.0/_schema.js +117 -0
  22. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/binary.d.ts +3 -0
  23. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/binary.d.ts.map +1 -0
  24. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/binary.js +103 -0
  25. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/bool.d.ts +3 -0
  26. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/bool.d.ts.map +1 -0
  27. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/bool.js +32 -0
  28. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/float.d.ts +3 -0
  29. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/float.d.ts.map +1 -0
  30. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/float.js +96 -0
  31. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/int.d.ts +3 -0
  32. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/int.d.ts.map +1 -0
  33. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/int.js +159 -0
  34. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/map.d.ts +3 -0
  35. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/map.d.ts.map +1 -0
  36. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/map.js +14 -0
  37. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/merge.d.ts +3 -0
  38. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/merge.d.ts.map +1 -0
  39. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/merge.js +10 -0
  40. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/nil.d.ts +3 -0
  41. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/nil.d.ts.map +1 -0
  42. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/nil.js +22 -0
  43. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/omap.d.ts +3 -0
  44. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/omap.d.ts.map +1 -0
  45. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/omap.js +29 -0
  46. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/pairs.d.ts +3 -0
  47. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/pairs.d.ts.map +1 -0
  48. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/pairs.js +19 -0
  49. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/regexp.d.ts +3 -0
  50. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/regexp.d.ts.map +1 -0
  51. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/regexp.js +30 -0
  52. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/seq.d.ts +3 -0
  53. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/seq.d.ts.map +1 -0
  54. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/seq.js +10 -0
  55. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/set.d.ts +3 -0
  56. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/set.d.ts.map +1 -0
  57. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/set.js +14 -0
  58. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/str.d.ts +3 -0
  59. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/str.d.ts.map +1 -0
  60. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/str.js +9 -0
  61. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/timestamp.d.ts +3 -0
  62. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/timestamp.d.ts.map +1 -0
  63. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/timestamp.js +81 -0
  64. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/undefined.d.ts +3 -0
  65. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/undefined.d.ts.map +1 -0
  66. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type/undefined.js +20 -0
  67. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type.d.ts +32 -0
  68. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type.d.ts.map +1 -0
  69. package/esm/deps/jsr.io/@std/yaml/1.3.0/_type.js +6 -0
  70. package/esm/deps/jsr.io/@std/yaml/1.3.0/_utils.d.ts +4 -0
  71. package/esm/deps/jsr.io/@std/yaml/1.3.0/_utils.d.ts.map +1 -0
  72. package/esm/deps/jsr.io/@std/yaml/1.3.0/_utils.js +13 -0
  73. package/esm/deps/jsr.io/@std/yaml/1.3.0/mod.d.ts +51 -0
  74. package/esm/deps/jsr.io/@std/yaml/1.3.0/mod.d.ts.map +1 -0
  75. package/esm/deps/jsr.io/@std/yaml/1.3.0/mod.js +53 -0
  76. package/esm/deps/jsr.io/@std/yaml/1.3.0/parse.d.ts +79 -0
  77. package/esm/deps/jsr.io/@std/yaml/1.3.0/parse.d.ts.map +1 -0
  78. package/esm/deps/jsr.io/@std/yaml/1.3.0/parse.js +91 -0
  79. package/esm/deps/jsr.io/@std/yaml/1.3.0/stringify.d.ts +108 -0
  80. package/esm/deps/jsr.io/@std/yaml/1.3.0/stringify.d.ts.map +1 -0
  81. package/esm/deps/jsr.io/@std/yaml/1.3.0/stringify.js +33 -0
  82. package/esm/deps/jsr.io/@std/yaml/1.3.0/types.d.ts +111 -0
  83. package/esm/deps/jsr.io/@std/yaml/1.3.0/types.d.ts.map +1 -0
  84. package/esm/deps/jsr.io/@std/yaml/1.3.0/types.js +104 -0
  85. package/esm/mod.d.ts +49 -0
  86. package/esm/mod.d.ts.map +1 -0
  87. package/esm/mod.js +42 -0
  88. package/esm/package.json +3 -0
  89. package/esm/src/core/collector/collector.d.ts +58 -0
  90. package/esm/src/core/collector/collector.d.ts.map +1 -0
  91. package/esm/src/core/collector/collector.js +60 -0
  92. package/esm/src/core/collector/extractor.d.ts +33 -0
  93. package/esm/src/core/collector/extractor.d.ts.map +1 -0
  94. package/esm/src/core/collector/extractor.js +53 -0
  95. package/esm/src/core/collector/mod.d.ts +9 -0
  96. package/esm/src/core/collector/mod.d.ts.map +1 -0
  97. package/esm/src/core/collector/mod.js +7 -0
  98. package/esm/src/core/components/components.d.ts +4 -0
  99. package/esm/src/core/components/components.d.ts.map +1 -0
  100. package/esm/src/core/components/components.js +28 -0
  101. package/esm/src/core/components/mod.d.ts +2 -0
  102. package/esm/src/core/components/mod.d.ts.map +1 -0
  103. package/esm/src/core/components/mod.js +1 -0
  104. package/esm/src/core/composer/composer.d.ts +35 -0
  105. package/esm/src/core/composer/composer.d.ts.map +1 -0
  106. package/esm/src/core/composer/composer.js +72 -0
  107. package/esm/src/core/composer/mod.d.ts +7 -0
  108. package/esm/src/core/composer/mod.d.ts.map +1 -0
  109. package/esm/src/core/composer/mod.js +6 -0
  110. package/esm/src/core/mod.d.ts +15 -0
  111. package/esm/src/core/mod.d.ts.map +1 -0
  112. package/esm/src/core/mod.js +16 -0
  113. package/esm/src/core/sync/mod.d.ts +9 -0
  114. package/esm/src/core/sync/mod.d.ts.map +1 -0
  115. package/esm/src/core/sync/mod.js +7 -0
  116. package/esm/src/core/sync/resolver.d.ts +51 -0
  117. package/esm/src/core/sync/resolver.d.ts.map +1 -0
  118. package/esm/src/core/sync/resolver.js +88 -0
  119. package/esm/src/core/sync/validator.d.ts +39 -0
  120. package/esm/src/core/sync/validator.d.ts.map +1 -0
  121. package/esm/src/core/sync/validator.js +65 -0
  122. package/esm/src/core/types/components.d.ts +46 -0
  123. package/esm/src/core/types/components.d.ts.map +1 -0
  124. package/esm/src/core/types/components.js +2 -0
  125. package/esm/src/core/types/descriptor.d.ts +47 -0
  126. package/esm/src/core/types/descriptor.d.ts.map +1 -0
  127. package/esm/src/core/types/descriptor.js +6 -0
  128. package/esm/src/core/types/errors.d.ts +69 -0
  129. package/esm/src/core/types/errors.d.ts.map +1 -0
  130. package/esm/src/core/types/errors.js +32 -0
  131. package/esm/src/core/types/layout.d.ts +100 -0
  132. package/esm/src/core/types/layout.d.ts.map +1 -0
  133. package/esm/src/core/types/layout.js +49 -0
  134. package/esm/src/core/types/mcp-apps.d.ts +56 -0
  135. package/esm/src/core/types/mcp-apps.d.ts.map +1 -0
  136. package/esm/src/core/types/mcp-apps.js +16 -0
  137. package/esm/src/core/types/mod.d.ts +17 -0
  138. package/esm/src/core/types/mod.d.ts.map +1 -0
  139. package/esm/src/core/types/mod.js +7 -0
  140. package/esm/src/core/types/orchestration.d.ts +37 -0
  141. package/esm/src/core/types/orchestration.d.ts.map +1 -0
  142. package/esm/src/core/types/orchestration.js +6 -0
  143. package/esm/src/core/types/resources.d.ts +37 -0
  144. package/esm/src/core/types/resources.d.ts.map +1 -0
  145. package/esm/src/core/types/resources.js +1 -0
  146. package/esm/src/core/types/sync-rules.d.ts +80 -0
  147. package/esm/src/core/types/sync-rules.d.ts.map +1 -0
  148. package/esm/src/core/types/sync-rules.js +6 -0
  149. package/esm/src/deploy/mod.d.ts +12 -0
  150. package/esm/src/deploy/mod.d.ts.map +1 -0
  151. package/esm/src/deploy/mod.js +11 -0
  152. package/esm/src/deploy/types.d.ts +119 -0
  153. package/esm/src/deploy/types.d.ts.map +1 -0
  154. package/esm/src/deploy/types.js +19 -0
  155. package/esm/src/host/components-contract.d.ts +6 -0
  156. package/esm/src/host/components-contract.d.ts.map +1 -0
  157. package/esm/src/host/components-contract.js +5 -0
  158. package/esm/src/host/mod.d.ts +15 -0
  159. package/esm/src/host/mod.d.ts.map +1 -0
  160. package/esm/src/host/mod.js +14 -0
  161. package/esm/src/host/renderer/css/base.d.ts +23 -0
  162. package/esm/src/host/renderer/css/base.d.ts.map +1 -0
  163. package/esm/src/host/renderer/css/base.js +48 -0
  164. package/esm/src/host/renderer/css/layouts.d.ts +31 -0
  165. package/esm/src/host/renderer/css/layouts.d.ts.map +1 -0
  166. package/esm/src/host/renderer/css/layouts.js +129 -0
  167. package/esm/src/host/renderer/html-generator.d.ts +36 -0
  168. package/esm/src/host/renderer/html-generator.d.ts.map +1 -0
  169. package/esm/src/host/renderer/html-generator.js +227 -0
  170. package/esm/src/host/renderer/js/event-bus.d.ts +33 -0
  171. package/esm/src/host/renderer/js/event-bus.d.ts.map +1 -0
  172. package/esm/src/host/renderer/js/event-bus.js +591 -0
  173. package/esm/src/host/renderer/mod.d.ts +9 -0
  174. package/esm/src/host/renderer/mod.d.ts.map +1 -0
  175. package/esm/src/host/renderer/mod.js +7 -0
  176. package/esm/src/host/renderer/options.d.ts +126 -0
  177. package/esm/src/host/renderer/options.d.ts.map +1 -0
  178. package/esm/src/host/renderer/options.js +1 -0
  179. package/esm/src/host/serve.d.ts +55 -0
  180. package/esm/src/host/serve.d.ts.map +1 -0
  181. package/esm/src/host/serve.js +89 -0
  182. package/esm/src/host/types.d.ts +42 -0
  183. package/esm/src/host/types.d.ts.map +1 -0
  184. package/esm/src/host/types.js +9 -0
  185. package/esm/src/runtime/cluster.d.ts +92 -0
  186. package/esm/src/runtime/cluster.d.ts.map +1 -0
  187. package/esm/src/runtime/cluster.js +859 -0
  188. package/esm/src/runtime/compose.d.ts +67 -0
  189. package/esm/src/runtime/compose.d.ts.map +1 -0
  190. package/esm/src/runtime/compose.js +288 -0
  191. package/esm/src/runtime/host-dashboard-types.d.ts +79 -0
  192. package/esm/src/runtime/host-dashboard-types.d.ts.map +1 -0
  193. package/esm/src/runtime/host-dashboard-types.js +9 -0
  194. package/esm/src/runtime/host-dashboard.d.ts +29 -0
  195. package/esm/src/runtime/host-dashboard.d.ts.map +1 -0
  196. package/esm/src/runtime/host-dashboard.js +559 -0
  197. package/esm/src/runtime/manifest.d.ts +58 -0
  198. package/esm/src/runtime/manifest.d.ts.map +1 -0
  199. package/esm/src/runtime/manifest.js +144 -0
  200. package/esm/src/runtime/mod.d.ts +18 -0
  201. package/esm/src/runtime/mod.d.ts.map +1 -0
  202. package/esm/src/runtime/mod.js +21 -0
  203. package/esm/src/runtime/template.d.ts +79 -0
  204. package/esm/src/runtime/template.d.ts.map +1 -0
  205. package/esm/src/runtime/template.js +287 -0
  206. package/esm/src/runtime/types.d.ts +345 -0
  207. package/esm/src/runtime/types.d.ts.map +1 -0
  208. package/esm/src/runtime/types.js +28 -0
  209. package/esm/src/sdk/compose-events.d.ts +130 -0
  210. package/esm/src/sdk/compose-events.d.ts.map +1 -0
  211. package/esm/src/sdk/compose-events.js +127 -0
  212. package/esm/src/sdk/composition-validator.d.ts +97 -0
  213. package/esm/src/sdk/composition-validator.d.ts.map +1 -0
  214. package/esm/src/sdk/composition-validator.js +178 -0
  215. package/esm/src/sdk/mcp-sdk.d.ts +92 -0
  216. package/esm/src/sdk/mcp-sdk.d.ts.map +1 -0
  217. package/esm/src/sdk/mcp-sdk.js +54 -0
  218. package/esm/src/sdk/mod.d.ts +15 -0
  219. package/esm/src/sdk/mod.d.ts.map +1 -0
  220. package/esm/src/sdk/mod.js +10 -0
  221. package/esm/src/sdk/ui-meta-builder.d.ts +99 -0
  222. package/esm/src/sdk/ui-meta-builder.d.ts.map +1 -0
  223. package/esm/src/sdk/ui-meta-builder.js +53 -0
  224. package/esm/src/version.d.ts +30 -0
  225. package/esm/src/version.d.ts.map +1 -0
  226. package/esm/src/version.js +29 -0
  227. package/package.json +55 -4
  228. package/script/_dnt.polyfills.d.ts +18 -0
  229. package/script/_dnt.polyfills.d.ts.map +1 -0
  230. package/script/_dnt.polyfills.js +16 -0
  231. package/script/_dnt.shims.d.ts +2 -0
  232. package/script/_dnt.shims.d.ts.map +1 -0
  233. package/script/_dnt.shims.js +60 -0
  234. package/script/deps/jsr.io/@std/yaml/1.3.0/_chars.d.ts +33 -0
  235. package/script/deps/jsr.io/@std/yaml/1.3.0/_chars.d.ts.map +1 -0
  236. package/script/deps/jsr.io/@std/yaml/1.3.0/_chars.js +55 -0
  237. package/script/deps/jsr.io/@std/yaml/1.3.0/_dumper_state.d.ts +106 -0
  238. package/script/deps/jsr.io/@std/yaml/1.3.0/_dumper_state.d.ts.map +1 -0
  239. package/script/deps/jsr.io/@std/yaml/1.3.0/_dumper_state.js +640 -0
  240. package/script/deps/jsr.io/@std/yaml/1.3.0/_loader_state.d.ts +67 -0
  241. package/script/deps/jsr.io/@std/yaml/1.3.0/_loader_state.d.ts.map +1 -0
  242. package/script/deps/jsr.io/@std/yaml/1.3.0/_loader_state.js +1397 -0
  243. package/script/deps/jsr.io/@std/yaml/1.3.0/_schema.d.ts +44 -0
  244. package/script/deps/jsr.io/@std/yaml/1.3.0/_schema.d.ts.map +1 -0
  245. package/script/deps/jsr.io/@std/yaml/1.3.0/_schema.js +121 -0
  246. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/binary.d.ts +3 -0
  247. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/binary.d.ts.map +1 -0
  248. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/binary.js +106 -0
  249. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/bool.d.ts +3 -0
  250. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/bool.d.ts.map +1 -0
  251. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/bool.js +35 -0
  252. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/float.d.ts +3 -0
  253. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/float.d.ts.map +1 -0
  254. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/float.js +99 -0
  255. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/int.d.ts +3 -0
  256. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/int.d.ts.map +1 -0
  257. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/int.js +162 -0
  258. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/map.d.ts +3 -0
  259. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/map.d.ts.map +1 -0
  260. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/map.js +17 -0
  261. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/merge.d.ts +3 -0
  262. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/merge.d.ts.map +1 -0
  263. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/merge.js +13 -0
  264. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/nil.d.ts +3 -0
  265. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/nil.d.ts.map +1 -0
  266. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/nil.js +25 -0
  267. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/omap.d.ts +3 -0
  268. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/omap.d.ts.map +1 -0
  269. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/omap.js +32 -0
  270. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/pairs.d.ts +3 -0
  271. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/pairs.d.ts.map +1 -0
  272. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/pairs.js +22 -0
  273. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/regexp.d.ts +3 -0
  274. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/regexp.d.ts.map +1 -0
  275. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/regexp.js +33 -0
  276. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/seq.d.ts +3 -0
  277. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/seq.d.ts.map +1 -0
  278. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/seq.js +13 -0
  279. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/set.d.ts +3 -0
  280. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/set.d.ts.map +1 -0
  281. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/set.js +17 -0
  282. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/str.d.ts +3 -0
  283. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/str.d.ts.map +1 -0
  284. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/str.js +12 -0
  285. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/timestamp.d.ts +3 -0
  286. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/timestamp.d.ts.map +1 -0
  287. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/timestamp.js +84 -0
  288. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/undefined.d.ts +3 -0
  289. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/undefined.d.ts.map +1 -0
  290. package/script/deps/jsr.io/@std/yaml/1.3.0/_type/undefined.js +23 -0
  291. package/script/deps/jsr.io/@std/yaml/1.3.0/_type.d.ts +32 -0
  292. package/script/deps/jsr.io/@std/yaml/1.3.0/_type.d.ts.map +1 -0
  293. package/script/deps/jsr.io/@std/yaml/1.3.0/_type.js +7 -0
  294. package/script/deps/jsr.io/@std/yaml/1.3.0/_utils.d.ts +4 -0
  295. package/script/deps/jsr.io/@std/yaml/1.3.0/_utils.d.ts.map +1 -0
  296. package/script/deps/jsr.io/@std/yaml/1.3.0/_utils.js +18 -0
  297. package/script/deps/jsr.io/@std/yaml/1.3.0/mod.d.ts +51 -0
  298. package/script/deps/jsr.io/@std/yaml/1.3.0/mod.d.ts.map +1 -0
  299. package/script/deps/jsr.io/@std/yaml/1.3.0/mod.js +69 -0
  300. package/script/deps/jsr.io/@std/yaml/1.3.0/parse.d.ts +79 -0
  301. package/script/deps/jsr.io/@std/yaml/1.3.0/parse.d.ts.map +1 -0
  302. package/script/deps/jsr.io/@std/yaml/1.3.0/parse.js +95 -0
  303. package/script/deps/jsr.io/@std/yaml/1.3.0/stringify.d.ts +108 -0
  304. package/script/deps/jsr.io/@std/yaml/1.3.0/stringify.d.ts.map +1 -0
  305. package/script/deps/jsr.io/@std/yaml/1.3.0/stringify.js +36 -0
  306. package/script/deps/jsr.io/@std/yaml/1.3.0/types.d.ts +111 -0
  307. package/script/deps/jsr.io/@std/yaml/1.3.0/types.d.ts.map +1 -0
  308. package/script/deps/jsr.io/@std/yaml/1.3.0/types.js +108 -0
  309. package/script/mod.d.ts +49 -0
  310. package/script/mod.d.ts.map +1 -0
  311. package/script/mod.js +60 -0
  312. package/script/package.json +3 -0
  313. package/script/src/core/collector/collector.d.ts +58 -0
  314. package/script/src/core/collector/collector.d.ts.map +1 -0
  315. package/script/src/core/collector/collector.js +63 -0
  316. package/script/src/core/collector/extractor.d.ts +33 -0
  317. package/script/src/core/collector/extractor.d.ts.map +1 -0
  318. package/script/src/core/collector/extractor.js +56 -0
  319. package/script/src/core/collector/mod.d.ts +9 -0
  320. package/script/src/core/collector/mod.d.ts.map +1 -0
  321. package/script/src/core/collector/mod.js +12 -0
  322. package/script/src/core/components/components.d.ts +4 -0
  323. package/script/src/core/components/components.d.ts.map +1 -0
  324. package/script/src/core/components/components.js +31 -0
  325. package/script/src/core/components/mod.d.ts +2 -0
  326. package/script/src/core/components/mod.d.ts.map +1 -0
  327. package/script/src/core/components/mod.js +5 -0
  328. package/script/src/core/composer/composer.d.ts +35 -0
  329. package/script/src/core/composer/composer.d.ts.map +1 -0
  330. package/script/src/core/composer/composer.js +75 -0
  331. package/script/src/core/composer/mod.d.ts +7 -0
  332. package/script/src/core/composer/mod.d.ts.map +1 -0
  333. package/script/src/core/composer/mod.js +10 -0
  334. package/script/src/core/mod.d.ts +15 -0
  335. package/script/src/core/mod.d.ts.map +1 -0
  336. package/script/src/core/mod.js +30 -0
  337. package/script/src/core/sync/mod.d.ts +9 -0
  338. package/script/src/core/sync/mod.d.ts.map +1 -0
  339. package/script/src/core/sync/mod.js +12 -0
  340. package/script/src/core/sync/resolver.d.ts +51 -0
  341. package/script/src/core/sync/resolver.d.ts.map +1 -0
  342. package/script/src/core/sync/resolver.js +91 -0
  343. package/script/src/core/sync/validator.d.ts +39 -0
  344. package/script/src/core/sync/validator.d.ts.map +1 -0
  345. package/script/src/core/sync/validator.js +68 -0
  346. package/script/src/core/types/components.d.ts +46 -0
  347. package/script/src/core/types/components.d.ts.map +1 -0
  348. package/script/src/core/types/components.js +3 -0
  349. package/script/src/core/types/descriptor.d.ts +47 -0
  350. package/script/src/core/types/descriptor.d.ts.map +1 -0
  351. package/script/src/core/types/descriptor.js +7 -0
  352. package/script/src/core/types/errors.d.ts +69 -0
  353. package/script/src/core/types/errors.d.ts.map +1 -0
  354. package/script/src/core/types/errors.js +35 -0
  355. package/script/src/core/types/layout.d.ts +100 -0
  356. package/script/src/core/types/layout.d.ts.map +1 -0
  357. package/script/src/core/types/layout.js +55 -0
  358. package/script/src/core/types/mcp-apps.d.ts +56 -0
  359. package/script/src/core/types/mcp-apps.d.ts.map +1 -0
  360. package/script/src/core/types/mcp-apps.js +17 -0
  361. package/script/src/core/types/mod.d.ts +17 -0
  362. package/script/src/core/types/mod.d.ts.map +1 -0
  363. package/script/src/core/types/mod.js +15 -0
  364. package/script/src/core/types/orchestration.d.ts +37 -0
  365. package/script/src/core/types/orchestration.d.ts.map +1 -0
  366. package/script/src/core/types/orchestration.js +7 -0
  367. package/script/src/core/types/resources.d.ts +37 -0
  368. package/script/src/core/types/resources.d.ts.map +1 -0
  369. package/script/src/core/types/resources.js +2 -0
  370. package/script/src/core/types/sync-rules.d.ts +80 -0
  371. package/script/src/core/types/sync-rules.d.ts.map +1 -0
  372. package/script/src/core/types/sync-rules.js +7 -0
  373. package/script/src/deploy/mod.d.ts +12 -0
  374. package/script/src/deploy/mod.d.ts.map +1 -0
  375. package/script/src/deploy/mod.js +15 -0
  376. package/script/src/deploy/types.d.ts +119 -0
  377. package/script/src/deploy/types.d.ts.map +1 -0
  378. package/script/src/deploy/types.js +22 -0
  379. package/script/src/host/components-contract.d.ts +6 -0
  380. package/script/src/host/components-contract.d.ts.map +1 -0
  381. package/script/src/host/components-contract.js +8 -0
  382. package/script/src/host/mod.d.ts +15 -0
  383. package/script/src/host/mod.d.ts.map +1 -0
  384. package/script/src/host/mod.js +21 -0
  385. package/script/src/host/renderer/css/base.d.ts +23 -0
  386. package/script/src/host/renderer/css/base.d.ts.map +1 -0
  387. package/script/src/host/renderer/css/base.js +51 -0
  388. package/script/src/host/renderer/css/layouts.d.ts +31 -0
  389. package/script/src/host/renderer/css/layouts.d.ts.map +1 -0
  390. package/script/src/host/renderer/css/layouts.js +132 -0
  391. package/script/src/host/renderer/html-generator.d.ts +36 -0
  392. package/script/src/host/renderer/html-generator.d.ts.map +1 -0
  393. package/script/src/host/renderer/html-generator.js +231 -0
  394. package/script/src/host/renderer/js/event-bus.d.ts +33 -0
  395. package/script/src/host/renderer/js/event-bus.d.ts.map +1 -0
  396. package/script/src/host/renderer/js/event-bus.js +594 -0
  397. package/script/src/host/renderer/mod.d.ts +9 -0
  398. package/script/src/host/renderer/mod.d.ts.map +1 -0
  399. package/script/src/host/renderer/mod.js +12 -0
  400. package/script/src/host/renderer/options.d.ts +126 -0
  401. package/script/src/host/renderer/options.d.ts.map +1 -0
  402. package/script/src/host/renderer/options.js +2 -0
  403. package/script/src/host/serve.d.ts +55 -0
  404. package/script/src/host/serve.d.ts.map +1 -0
  405. package/script/src/host/serve.js +92 -0
  406. package/script/src/host/types.d.ts +42 -0
  407. package/script/src/host/types.d.ts.map +1 -0
  408. package/script/src/host/types.js +10 -0
  409. package/script/src/runtime/cluster.d.ts +92 -0
  410. package/script/src/runtime/cluster.d.ts.map +1 -0
  411. package/script/src/runtime/cluster.js +864 -0
  412. package/script/src/runtime/compose.d.ts +67 -0
  413. package/script/src/runtime/compose.d.ts.map +1 -0
  414. package/script/src/runtime/compose.js +292 -0
  415. package/script/src/runtime/host-dashboard-types.d.ts +79 -0
  416. package/script/src/runtime/host-dashboard-types.d.ts.map +1 -0
  417. package/script/src/runtime/host-dashboard-types.js +10 -0
  418. package/script/src/runtime/host-dashboard.d.ts +29 -0
  419. package/script/src/runtime/host-dashboard.d.ts.map +1 -0
  420. package/script/src/runtime/host-dashboard.js +563 -0
  421. package/script/src/runtime/manifest.d.ts +58 -0
  422. package/script/src/runtime/manifest.d.ts.map +1 -0
  423. package/script/src/runtime/manifest.js +150 -0
  424. package/script/src/runtime/mod.d.ts +18 -0
  425. package/script/src/runtime/mod.d.ts.map +1 -0
  426. package/script/src/runtime/mod.js +41 -0
  427. package/script/src/runtime/template.d.ts +79 -0
  428. package/script/src/runtime/template.d.ts.map +1 -0
  429. package/script/src/runtime/template.js +295 -0
  430. package/script/src/runtime/types.d.ts +345 -0
  431. package/script/src/runtime/types.d.ts.map +1 -0
  432. package/script/src/runtime/types.js +31 -0
  433. package/script/src/sdk/compose-events.d.ts +130 -0
  434. package/script/src/sdk/compose-events.d.ts.map +1 -0
  435. package/script/src/sdk/compose-events.js +154 -0
  436. package/script/src/sdk/composition-validator.d.ts +97 -0
  437. package/script/src/sdk/composition-validator.d.ts.map +1 -0
  438. package/script/src/sdk/composition-validator.js +181 -0
  439. package/script/src/sdk/mcp-sdk.d.ts +92 -0
  440. package/script/src/sdk/mcp-sdk.d.ts.map +1 -0
  441. package/script/src/sdk/mcp-sdk.js +57 -0
  442. package/script/src/sdk/mod.d.ts +15 -0
  443. package/script/src/sdk/mod.d.ts.map +1 -0
  444. package/script/src/sdk/mod.js +18 -0
  445. package/script/src/sdk/ui-meta-builder.d.ts +99 -0
  446. package/script/src/sdk/ui-meta-builder.d.ts.map +1 -0
  447. package/script/src/sdk/ui-meta-builder.js +56 -0
  448. package/script/src/version.d.ts +30 -0
  449. package/script/src/version.d.ts.map +1 -0
  450. package/script/src/version.js +33 -0
@@ -0,0 +1,864 @@
1
+ "use strict";
2
+ /**
3
+ * MCP server cluster — start, connect, call tools, and shut down MCP servers.
4
+ *
5
+ * Two transport modes:
6
+ * - **stdio**: The cluster starts the server as a child process with `--http --port=0`.
7
+ * The server picks a free port and prints the URL on stderr. All communication
8
+ * then goes through HTTP (no JSON-RPC over stdio).
9
+ * - **http**: The cluster connects to an already-running server via its URL.
10
+ *
11
+ * Both modes support the modern stateless MCP HTTP protocol and legacy
12
+ * Streamable HTTP. `auto` probes stateless `server/discover` first; only a
13
+ * server that explicitly rejects that protocol falls back to the official SDK
14
+ * client, which performs initialization and retains its session.
15
+ *
16
+ * ## AX (Agent Experience)
17
+ *
18
+ * - **Fast fail**: Invalid manifests, connection failures, and tool call errors
19
+ * produce structured `RuntimeError` objects with machine-readable codes.
20
+ * - **Deterministic cleanup**: `stopAll()` always runs in a `finally` block
21
+ * pattern. Process handles are tracked and killed on shutdown.
22
+ * - **Timeout-aware**: Tool calls and server startup have configurable timeouts
23
+ * with clear error messages on expiry.
24
+ * - **No magic**: The cluster does not retry failed calls or silently swallow
25
+ * errors. Callers decide retry policy.
26
+ *
27
+ * @module runtime/cluster
28
+ */
29
+ Object.defineProperty(exports, "__esModule", { value: true });
30
+ exports.connectHttp = connectHttp;
31
+ exports.startServer = startServer;
32
+ exports.createCluster = createCluster;
33
+ const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
34
+ const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
35
+ const types_js_1 = require("@modelcontextprotocol/sdk/types.js");
36
+ const version_js_1 = require("../version.js");
37
+ const types_js_2 = require("./types.js");
38
+ /** Default timeout for server startup (ms). */
39
+ const DEFAULT_STARTUP_TIMEOUT_MS = 15_000;
40
+ /** Default timeout for tool and resource calls (ms). */
41
+ const DEFAULT_REQUEST_TIMEOUT_MS = 30_000;
42
+ /** Pattern to detect the HTTP listening URL from server stderr.
43
+ * Matches "listening on http://host:port" to avoid false positives
44
+ * from warning messages containing URLs. */
45
+ const LISTEN_URL_PATTERN = /listening on (https?:\/\/[^\s]+)/;
46
+ /**
47
+ * Connect to an already-running MCP server via HTTP.
48
+ *
49
+ * Performs MCP protocol discovery/initialization rather than relying on a
50
+ * non-standard `/health` endpoint.
51
+ *
52
+ * @param manifest - Server manifest with http transport
53
+ * @returns Active connection
54
+ * @throws RuntimeError if health check fails
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * const conn = await connectHttp({
59
+ * name: "einvoice",
60
+ * transport: { type: "http", url: "http://localhost:3015" },
61
+ * tools: [...],
62
+ * });
63
+ * const result = await conn.callTool("invoice_search", { customer_id: "C-1" });
64
+ * ```
65
+ */
66
+ async function connectHttp(manifest) {
67
+ if (manifest.transport.type !== "http") {
68
+ throw {
69
+ code: types_js_2.RuntimeErrorCode.PROCESS_START_FAILED,
70
+ message: `Expected http transport for "${manifest.name}", got "${manifest.transport.type}"`,
71
+ server: manifest.name,
72
+ };
73
+ }
74
+ let baseUrl = manifest.transport.url;
75
+ try {
76
+ baseUrl = normalizeBaseUrl(manifest.transport.url);
77
+ return await createHttpConnection(manifest.name, baseUrl, manifest.transport.protocol ?? "auto");
78
+ }
79
+ catch (cause) {
80
+ throw {
81
+ code: types_js_2.RuntimeErrorCode.PROCESS_START_FAILED,
82
+ message: `Cannot initialize MCP connection to "${manifest.name}" at ${baseUrl}: ${cause instanceof Error ? cause.message : String(cause)}`,
83
+ server: manifest.name,
84
+ cause,
85
+ };
86
+ }
87
+ }
88
+ /**
89
+ * Start an MCP server as a child process and connect via HTTP.
90
+ *
91
+ * Launches the server with `--http --port=0` (dynamic port),
92
+ * reads stderr to detect the listening URL, then communicates via HTTP.
93
+ *
94
+ * @param manifest - Server manifest with stdio transport
95
+ * @param options - Startup options
96
+ * @returns Active connection (with process handle for cleanup)
97
+ * @throws RuntimeError if startup times out or fails
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const conn = await startServer({
102
+ * name: "einvoice",
103
+ * transport: { type: "stdio", command: "deno", args: ["run", "server.ts"] },
104
+ * tools: [...],
105
+ * });
106
+ * ```
107
+ */
108
+ async function startServer(manifest, options) {
109
+ if (manifest.transport.type !== "stdio") {
110
+ throw {
111
+ code: types_js_2.RuntimeErrorCode.PROCESS_START_FAILED,
112
+ message: `Expected stdio transport for "${manifest.name}", got "${manifest.transport.type}"`,
113
+ server: manifest.name,
114
+ };
115
+ }
116
+ const transport = manifest.transport;
117
+ const timeoutMs = options?.timeoutMs ?? DEFAULT_STARTUP_TIMEOUT_MS;
118
+ // Validate required env vars before starting
119
+ if (manifest.requiredEnv?.length) {
120
+ const env = transport.env ?? {};
121
+ const missing = manifest.requiredEnv.filter((k) => !env[k] && !Deno.env.get(k));
122
+ if (missing.length > 0) {
123
+ throw {
124
+ code: types_js_2.RuntimeErrorCode.PROCESS_START_FAILED,
125
+ message: `Server "${manifest.name}" requires env vars: ${missing.join(", ")}`,
126
+ server: manifest.name,
127
+ };
128
+ }
129
+ }
130
+ // Append --http --port=0 if not already present
131
+ const args = [...(transport.args ?? [])];
132
+ if (!args.includes("--http"))
133
+ args.push("--http");
134
+ if (!args.some((a) => a.startsWith("--port=")))
135
+ args.push("--port=0");
136
+ let process;
137
+ try {
138
+ const command = new Deno.Command(transport.command, {
139
+ args,
140
+ stdin: "null",
141
+ stdout: "piped",
142
+ stderr: "piped",
143
+ env: transport.env,
144
+ });
145
+ process = command.spawn();
146
+ }
147
+ catch (cause) {
148
+ throw {
149
+ code: types_js_2.RuntimeErrorCode.PROCESS_START_FAILED,
150
+ message: `Failed to start "${manifest.name}": ${cause instanceof Error ? cause.message : String(cause)}`,
151
+ server: manifest.name,
152
+ cause,
153
+ };
154
+ }
155
+ // Drain stdout in background (we don't use it, prevent pipe pressure)
156
+ drainStream(process.stdout);
157
+ // Read stderr to find the listening URL. If startup fails before the URL is
158
+ // announced, do not leave the owned child process behind.
159
+ let baseUrl;
160
+ try {
161
+ baseUrl = await detectListenUrl(manifest.name, process.stderr, timeoutMs);
162
+ }
163
+ catch (cause) {
164
+ await stopProcess(process);
165
+ throw cause;
166
+ }
167
+ try {
168
+ return await createStdioConnection(manifest.name, baseUrl, transport.protocol ?? "auto", process);
169
+ }
170
+ catch (cause) {
171
+ await stopProcess(process);
172
+ throw {
173
+ code: types_js_2.RuntimeErrorCode.PROCESS_START_FAILED,
174
+ message: `Cannot initialize MCP connection to "${manifest.name}" at ${baseUrl}: ${cause instanceof Error ? cause.message : String(cause)}`,
175
+ server: manifest.name,
176
+ cause,
177
+ };
178
+ }
179
+ }
180
+ /**
181
+ * Create a cluster manager for multiple MCP servers.
182
+ *
183
+ * @param manifests - All available manifests (keyed by name)
184
+ * @param serverNames - Which servers to include in the cluster
185
+ * @returns Cluster manager with startAll/stopAll/callTool
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const cluster = createCluster(manifests, ["mcp-einvoice", "mcp-dataviz"]);
190
+ * await cluster.startAll();
191
+ * try {
192
+ * const result = await cluster.callTool("mcp-einvoice", "invoice_search", { id: "1" });
193
+ * } finally {
194
+ * await cluster.stopAll();
195
+ * }
196
+ * ```
197
+ */
198
+ function createCluster(manifests, serverNames) {
199
+ const connections = new Map();
200
+ let startup;
201
+ const startConnections = async () => {
202
+ // Validate all manifests exist before starting anything. A template may
203
+ // legitimately have several panels from one source; the cluster owns one
204
+ // connection per manifest, not one connection per panel.
205
+ const resolvedManifests = [];
206
+ for (const name of new Set(serverNames)) {
207
+ const manifest = manifests.get(name);
208
+ if (!manifest) {
209
+ throw {
210
+ code: types_js_2.RuntimeErrorCode.MANIFEST_NOT_FOUND,
211
+ message: `Manifest "${name}" not found`,
212
+ server: name,
213
+ };
214
+ }
215
+ resolvedManifests.push(manifest);
216
+ }
217
+ // Start all distinct servers in parallel.
218
+ const results = await Promise.allSettled(resolvedManifests.map((manifest) => manifest.transport.type === "http"
219
+ ? connectHttp(manifest).then((conn) => ({ name: manifest.name, conn }))
220
+ : startServer(manifest).then((conn) => ({ name: manifest.name, conn }))));
221
+ // Collect successes and failures.
222
+ const failures = [];
223
+ for (const result of results) {
224
+ if (result.status === "fulfilled") {
225
+ connections.set(result.value.name, result.value.conn);
226
+ }
227
+ else {
228
+ const err = result.reason;
229
+ failures.push(err.message ?? String(result.reason));
230
+ }
231
+ }
232
+ // If any failed, clean up the ones that succeeded and throw.
233
+ if (failures.length > 0) {
234
+ await Promise.allSettled([...connections.values()].map((conn) => conn.close()));
235
+ connections.clear();
236
+ throw {
237
+ code: types_js_2.RuntimeErrorCode.PROCESS_START_FAILED,
238
+ message: `Failed to start ${failures.length} server(s): ${failures.join("; ")}`,
239
+ };
240
+ }
241
+ };
242
+ return {
243
+ async startAll() {
244
+ if (connections.size > 0)
245
+ return;
246
+ if (startup)
247
+ return await startup;
248
+ startup = startConnections();
249
+ try {
250
+ await startup;
251
+ }
252
+ finally {
253
+ startup = undefined;
254
+ }
255
+ },
256
+ // `async` is load-bearing despite the absence of `await`: the synchronous
257
+ // `throw` below must reach callers as a rejected Promise. Dropping `async`
258
+ // would make it throw synchronously, and `cluster.callTool(...).catch(...)`
259
+ // would stop catching it.
260
+ // deno-lint-ignore require-await
261
+ async callTool(serverName, toolName, args) {
262
+ const conn = connections.get(serverName);
263
+ if (!conn) {
264
+ throw {
265
+ code: types_js_2.RuntimeErrorCode.TOOL_CALL_FAILED,
266
+ message: `No connection for server "${serverName}". Did you call startAll()?`,
267
+ server: serverName,
268
+ tool: toolName,
269
+ };
270
+ }
271
+ return conn.callTool(toolName, args);
272
+ },
273
+ // See callTool above: preserve rejected-Promise behavior for missing
274
+ // connections instead of synchronously throwing from the cluster facade.
275
+ // deno-lint-ignore require-await
276
+ async readResource(serverName, uri) {
277
+ const conn = connections.get(serverName);
278
+ if (!conn) {
279
+ throw {
280
+ code: types_js_2.RuntimeErrorCode.RESOURCE_READ_FAILED,
281
+ message: `No connection for server "${serverName}". Did you call startAll()?`,
282
+ server: serverName,
283
+ };
284
+ }
285
+ return conn.readResource(uri);
286
+ },
287
+ // See callTool above: preserve rejected-Promise behavior for missing
288
+ // connections instead of synchronously throwing from the cluster facade.
289
+ // deno-lint-ignore require-await
290
+ async listTools(serverName, cursor) {
291
+ const conn = connections.get(serverName);
292
+ if (!conn) {
293
+ throw {
294
+ code: types_js_2.RuntimeErrorCode.TOOL_LIST_FAILED,
295
+ message: `No connection for server "${serverName}". Did you call startAll()?`,
296
+ server: serverName,
297
+ };
298
+ }
299
+ return conn.listTools(cursor);
300
+ },
301
+ // See callTool above: preserve rejected-Promise behavior for missing
302
+ // connections instead of synchronously throwing from the cluster facade.
303
+ // deno-lint-ignore require-await
304
+ async listResources(serverName, cursor) {
305
+ const conn = connections.get(serverName);
306
+ if (!conn) {
307
+ throw {
308
+ code: types_js_2.RuntimeErrorCode.RESOURCE_LIST_FAILED,
309
+ message: `No connection for server "${serverName}". Did you call startAll()?`,
310
+ server: serverName,
311
+ };
312
+ }
313
+ return conn.listResources(cursor);
314
+ },
315
+ getUiBaseUrl(serverName) {
316
+ return connections.get(serverName)?.uiBaseUrl;
317
+ },
318
+ async stopAll() {
319
+ const results = await Promise.allSettled([...connections.values()].map((conn) => conn.close()));
320
+ connections.clear();
321
+ // Log failures but don't throw — cleanup is best-effort
322
+ for (const result of results) {
323
+ if (result.status === "rejected") {
324
+ console.error("[mcp-compose] Failed to close connection:", result.reason);
325
+ }
326
+ }
327
+ },
328
+ };
329
+ }
330
+ // =============================================================================
331
+ // Internal helpers
332
+ // =============================================================================
333
+ /**
334
+ * Read stderr line by line until a URL matching the listen pattern is found.
335
+ * Times out with a RuntimeError if no URL appears.
336
+ */
337
+ // `async` keeps a synchronous throw from `getReader()` inside the returned
338
+ // Promise, matching what callers expect from a `Promise<string>`-typed function.
339
+ // deno-lint-ignore require-await
340
+ async function detectListenUrl(serverName, stderr, timeoutMs) {
341
+ const decoder = new TextDecoder();
342
+ const reader = stderr.getReader();
343
+ let buffer = "";
344
+ let timerId;
345
+ const timeout = new Promise((_, reject) => {
346
+ timerId = setTimeout(() => {
347
+ reader.releaseLock();
348
+ drainStream(stderr);
349
+ reject({
350
+ code: types_js_2.RuntimeErrorCode.PROCESS_START_FAILED,
351
+ message: `Server "${serverName}" did not report a listening URL within ${timeoutMs}ms`,
352
+ server: serverName,
353
+ });
354
+ }, timeoutMs);
355
+ });
356
+ const detect = async () => {
357
+ try {
358
+ while (true) {
359
+ const { value, done } = await reader.read();
360
+ if (done) {
361
+ throw {
362
+ code: types_js_2.RuntimeErrorCode.PROCESS_DIED,
363
+ message: `Server "${serverName}" exited before reporting a listening URL. Stderr: ${buffer}`,
364
+ server: serverName,
365
+ };
366
+ }
367
+ buffer += decoder.decode(value, { stream: true });
368
+ const lines = buffer.split("\n");
369
+ for (const line of lines) {
370
+ const match = line.match(LISTEN_URL_PATTERN);
371
+ if (match) {
372
+ reader.releaseLock();
373
+ drainStream(stderr);
374
+ return match[1].replace(/\/+$/, "");
375
+ }
376
+ }
377
+ buffer = lines[lines.length - 1];
378
+ }
379
+ }
380
+ finally {
381
+ clearTimeout(timerId);
382
+ }
383
+ };
384
+ return Promise.race([detect(), timeout]);
385
+ }
386
+ /** Drain a stream in background to prevent pipe backpressure. */
387
+ function drainStream(stream) {
388
+ const reader = stream.getReader();
389
+ (async () => {
390
+ try {
391
+ while (!(await reader.read()).done) { /* discard */ }
392
+ }
393
+ catch {
394
+ /* stream closed */
395
+ }
396
+ finally {
397
+ reader.releaseLock();
398
+ }
399
+ })();
400
+ }
401
+ /** Protocol revision implemented by the stateless transport adapter. */
402
+ const STATELESS_PROTOCOL_VERSION = "2026-07-28";
403
+ /** Metadata required on every stateless MCP request. */
404
+ const STATELESS_PROTOCOL_META_KEY = "io.modelcontextprotocol/protocolVersion";
405
+ const STATELESS_CLIENT_CAPABILITIES_META_KEY = "io.modelcontextprotocol/clientCapabilities";
406
+ const STATELESS_CLIENT_INFO_META_KEY = "io.modelcontextprotocol/clientInfo";
407
+ /**
408
+ * Create an MCP connection to an already-running HTTP server.
409
+ *
410
+ * `auto` is intentionally stateless-first: the 2026-07-28 protocol has no
411
+ * session and asks clients to discover capabilities with `server/discover`.
412
+ * Only explicit stateless incompatibility falls back to the official
413
+ * Streamable HTTP SDK and its stateful `initialize` handshake.
414
+ */
415
+ async function createHttpConnection(name, baseUrl, protocol) {
416
+ return await createMcpConnection(name, "http", baseUrl, protocol);
417
+ }
418
+ /** Create an McpConnection backed by a child process + HTTP transport. */
419
+ async function createStdioConnection(name, baseUrl, protocol, process) {
420
+ return await createMcpConnection(name, "stdio", baseUrl, protocol, () => stopProcess(process));
421
+ }
422
+ /**
423
+ * Select a protocol-specific MCP connection.
424
+ *
425
+ * Compose deliberately exposes concrete operations rather than a generic
426
+ * JSON-RPC escape hatch. The host can therefore enforce its slot/tool/resource
427
+ * allow-lists before delegating to this runtime layer.
428
+ */
429
+ async function createMcpConnection(name, transportType, baseUrl, protocol, stopOwnedProcess) {
430
+ if (protocol === "stateless-2026-07-28") {
431
+ return await createStatelessConnection(name, transportType, baseUrl, stopOwnedProcess);
432
+ }
433
+ if (protocol === "streamable-http") {
434
+ return await createStreamableConnection(name, transportType, baseUrl, stopOwnedProcess);
435
+ }
436
+ try {
437
+ return await createStatelessConnection(name, transportType, baseUrl, stopOwnedProcess);
438
+ }
439
+ catch (cause) {
440
+ if (!shouldFallbackToStreamable(cause))
441
+ throw cause;
442
+ return await createStreamableConnection(name, transportType, baseUrl, stopOwnedProcess);
443
+ }
444
+ }
445
+ /**
446
+ * Connect with the official stateful Streamable HTTP SDK client.
447
+ *
448
+ * `Client.connect()` performs `initialize`, retains the negotiated protocol
449
+ * and session ID, and adds those details to later requests.
450
+ */
451
+ async function createStreamableConnection(name, transportType, baseUrl, stopOwnedProcess) {
452
+ const transport = new streamableHttp_js_1.StreamableHTTPClientTransport(mcpEndpointUrl(baseUrl));
453
+ const client = new index_js_1.Client({ name: "@mcpview/compose", version: version_js_1.COMPOSE_VERSION }, { capabilities: {} });
454
+ try {
455
+ await client.connect(transport, { timeout: DEFAULT_STARTUP_TIMEOUT_MS });
456
+ }
457
+ catch (cause) {
458
+ await client.close().catch(() => undefined);
459
+ throw cause;
460
+ }
461
+ let closed = false;
462
+ return {
463
+ name,
464
+ transportType,
465
+ uiBaseUrl: baseUrl,
466
+ async close() {
467
+ if (closed)
468
+ return;
469
+ closed = true;
470
+ try {
471
+ // Streamable HTTP sessions are server-side state. Terminate them while
472
+ // the transport is still open, then close local listeners regardless
473
+ // of whether the server accepts DELETE (405 is handled by the SDK).
474
+ await transport.terminateSession();
475
+ }
476
+ catch {
477
+ // Cleanup remains best-effort, matching the cluster's prior contract.
478
+ }
479
+ finally {
480
+ try {
481
+ await client.close();
482
+ }
483
+ finally {
484
+ await stopOwnedProcess?.();
485
+ }
486
+ }
487
+ },
488
+ async callTool(toolName, args) {
489
+ try {
490
+ return await client.callTool({ name: toolName, arguments: args ?? {} }, undefined, { timeout: DEFAULT_REQUEST_TIMEOUT_MS });
491
+ }
492
+ catch (cause) {
493
+ throw requestError({
494
+ kind: "tool-call",
495
+ serverName: name,
496
+ toolName,
497
+ timeoutMs: DEFAULT_REQUEST_TIMEOUT_MS,
498
+ cause,
499
+ });
500
+ }
501
+ },
502
+ async readResource(uri) {
503
+ try {
504
+ return await client.readResource({ uri }, { timeout: DEFAULT_REQUEST_TIMEOUT_MS });
505
+ }
506
+ catch (cause) {
507
+ throw requestError({
508
+ kind: "resource-read",
509
+ serverName: name,
510
+ uri,
511
+ timeoutMs: DEFAULT_REQUEST_TIMEOUT_MS,
512
+ cause,
513
+ });
514
+ }
515
+ },
516
+ async listTools(cursor) {
517
+ try {
518
+ return await client.listTools(cursor === undefined ? undefined : { cursor }, { timeout: DEFAULT_REQUEST_TIMEOUT_MS });
519
+ }
520
+ catch (cause) {
521
+ throw requestError({
522
+ kind: "tool-list",
523
+ serverName: name,
524
+ timeoutMs: DEFAULT_REQUEST_TIMEOUT_MS,
525
+ cause,
526
+ });
527
+ }
528
+ },
529
+ async listResources(cursor) {
530
+ try {
531
+ return await client.listResources(cursor === undefined ? undefined : { cursor }, { timeout: DEFAULT_REQUEST_TIMEOUT_MS });
532
+ }
533
+ catch (cause) {
534
+ throw requestError({
535
+ kind: "resource-list",
536
+ serverName: name,
537
+ timeoutMs: DEFAULT_REQUEST_TIMEOUT_MS,
538
+ cause,
539
+ });
540
+ }
541
+ },
542
+ };
543
+ }
544
+ /**
545
+ * Connect to a stateless 2026-07-28 server by issuing `server/discover`.
546
+ *
547
+ * Every later request carries its own protocol/version/capability metadata;
548
+ * no session is created or retained in this transport.
549
+ */
550
+ async function createStatelessConnection(name, transportType, baseUrl, stopOwnedProcess) {
551
+ const client = new StatelessMcpClient(mcpEndpointUrl(baseUrl));
552
+ const discovered = await client.request("server/discover", {}, DEFAULT_STARTUP_TIMEOUT_MS);
553
+ if (!isRecord(discovered) ||
554
+ !Array.isArray(discovered.supportedVersions) ||
555
+ !discovered.supportedVersions.includes(STATELESS_PROTOCOL_VERSION)) {
556
+ throw new StatelessProtocolError(`Server does not advertise stateless protocol ${STATELESS_PROTOCOL_VERSION}`, { rpcCode: -32022 });
557
+ }
558
+ let closed = false;
559
+ return {
560
+ name,
561
+ transportType,
562
+ uiBaseUrl: baseUrl,
563
+ async close() {
564
+ if (closed)
565
+ return;
566
+ closed = true;
567
+ await stopOwnedProcess?.();
568
+ },
569
+ async callTool(toolName, args) {
570
+ try {
571
+ return await client.request("tools/call", { name: toolName, arguments: args ?? {} }, DEFAULT_REQUEST_TIMEOUT_MS);
572
+ }
573
+ catch (cause) {
574
+ throw requestError({
575
+ kind: "tool-call",
576
+ serverName: name,
577
+ toolName,
578
+ timeoutMs: DEFAULT_REQUEST_TIMEOUT_MS,
579
+ cause,
580
+ });
581
+ }
582
+ },
583
+ async readResource(uri) {
584
+ try {
585
+ return await client.request("resources/read", { uri }, DEFAULT_REQUEST_TIMEOUT_MS);
586
+ }
587
+ catch (cause) {
588
+ throw requestError({
589
+ kind: "resource-read",
590
+ serverName: name,
591
+ uri,
592
+ timeoutMs: DEFAULT_REQUEST_TIMEOUT_MS,
593
+ cause,
594
+ });
595
+ }
596
+ },
597
+ async listTools(cursor) {
598
+ try {
599
+ return await client.request("tools/list", cursor === undefined ? {} : { cursor }, DEFAULT_REQUEST_TIMEOUT_MS);
600
+ }
601
+ catch (cause) {
602
+ throw requestError({
603
+ kind: "tool-list",
604
+ serverName: name,
605
+ timeoutMs: DEFAULT_REQUEST_TIMEOUT_MS,
606
+ cause,
607
+ });
608
+ }
609
+ },
610
+ async listResources(cursor) {
611
+ try {
612
+ return await client.request("resources/list", cursor === undefined ? {} : { cursor }, DEFAULT_REQUEST_TIMEOUT_MS);
613
+ }
614
+ catch (cause) {
615
+ throw requestError({
616
+ kind: "resource-list",
617
+ serverName: name,
618
+ timeoutMs: DEFAULT_REQUEST_TIMEOUT_MS,
619
+ cause,
620
+ });
621
+ }
622
+ },
623
+ };
624
+ }
625
+ /**
626
+ * Minimal client for the current stateless MCP HTTP revision.
627
+ *
628
+ * It is intentionally private: callers use the concrete, allow-listable
629
+ * `McpConnection` operations above rather than arbitrary JSON-RPC methods.
630
+ */
631
+ class StatelessMcpClient {
632
+ endpoint;
633
+ #nextRequestId = 1;
634
+ constructor(endpoint) {
635
+ this.endpoint = endpoint;
636
+ }
637
+ async request(method, params, timeoutMs) {
638
+ const id = this.#nextRequestId++;
639
+ const requestParams = withStatelessMetadata(params);
640
+ const headers = new Headers({
641
+ "Accept": "application/json",
642
+ "Content-Type": "application/json",
643
+ "MCP-Protocol-Version": STATELESS_PROTOCOL_VERSION,
644
+ "Mcp-Method": method,
645
+ });
646
+ const mcpName = mcpNameFor(method, requestParams);
647
+ if (mcpName !== undefined)
648
+ headers.set("Mcp-Name", encodeMcpHeaderValue(mcpName));
649
+ let response;
650
+ try {
651
+ response = await fetch(this.endpoint, {
652
+ method: "POST",
653
+ headers,
654
+ body: JSON.stringify({ jsonrpc: "2.0", id, method, params: requestParams }),
655
+ signal: AbortSignal.timeout(timeoutMs),
656
+ });
657
+ }
658
+ catch (cause) {
659
+ throw new StatelessProtocolError(`HTTP request failed: ${formatCause(cause)}`, { cause });
660
+ }
661
+ const payload = await readJsonRpcPayload(response);
662
+ if (!isRecord(payload) || payload.id !== id) {
663
+ throw new StatelessProtocolError("Response did not match its JSON-RPC request id", {
664
+ status: response.status,
665
+ });
666
+ }
667
+ const rpcError = jsonRpcError(payload);
668
+ if (!response.ok || rpcError !== undefined) {
669
+ throw new StatelessProtocolError(rpcError === undefined
670
+ ? `HTTP ${response.status}`
671
+ : `MCP error ${rpcError.code}: ${rpcError.message}`, {
672
+ status: response.status,
673
+ rpcCode: rpcError?.code,
674
+ data: rpcError?.data,
675
+ });
676
+ }
677
+ if (!("result" in payload)) {
678
+ throw new StatelessProtocolError("Response did not contain a JSON-RPC result", {
679
+ status: response.status,
680
+ });
681
+ }
682
+ return payload.result;
683
+ }
684
+ }
685
+ /** A protocol error with enough structure to select the only safe fallback. */
686
+ class StatelessProtocolError extends Error {
687
+ status;
688
+ rpcCode;
689
+ data;
690
+ cause;
691
+ constructor(message, options = {}) {
692
+ super(message);
693
+ this.name = "StatelessProtocolError";
694
+ this.status = options.status;
695
+ this.rpcCode = options.rpcCode;
696
+ this.data = options.data;
697
+ this.cause = options.cause;
698
+ }
699
+ }
700
+ /** Only protocol absence/rejection permits automatic fallback to legacy HTTP. */
701
+ function shouldFallbackToStreamable(cause) {
702
+ return cause instanceof StatelessProtocolError &&
703
+ (cause.status === 404 || cause.rpcCode === -32022 || cause.rpcCode === -32601);
704
+ }
705
+ /** Attach the stateless revision's required per-request metadata. */
706
+ function withStatelessMetadata(params) {
707
+ const existingMeta = isRecord(params._meta) ? params._meta : {};
708
+ return {
709
+ ...params,
710
+ _meta: {
711
+ ...existingMeta,
712
+ [STATELESS_PROTOCOL_META_KEY]: STATELESS_PROTOCOL_VERSION,
713
+ [STATELESS_CLIENT_CAPABILITIES_META_KEY]: {},
714
+ [STATELESS_CLIENT_INFO_META_KEY]: {
715
+ name: "@mcpview/compose",
716
+ version: version_js_1.COMPOSE_VERSION,
717
+ },
718
+ },
719
+ };
720
+ }
721
+ /** Return the name/URI whose metadata header is required for a request. */
722
+ function mcpNameFor(method, params) {
723
+ if (method === "tools/call" && typeof params.name === "string")
724
+ return params.name;
725
+ if (method === "resources/read" && typeof params.uri === "string")
726
+ return params.uri;
727
+ return undefined;
728
+ }
729
+ /** Encode the restricted HTTP header value form required by MCP 2026-07-28. */
730
+ function encodeMcpHeaderValue(value) {
731
+ const sentinelPrefix = "=?base64?";
732
+ const sentinelSuffix = "?=";
733
+ const safe = /^(?:[\x21-\x7E](?:[\x20-\x7E\t]*[\x21-\x7E])?)?$/.test(value);
734
+ const looksEncoded = value.startsWith(sentinelPrefix) && value.endsWith(sentinelSuffix);
735
+ if (safe && !looksEncoded)
736
+ return value;
737
+ const bytes = new TextEncoder().encode(value);
738
+ let latin1 = "";
739
+ for (const byte of bytes)
740
+ latin1 += String.fromCharCode(byte);
741
+ return `${sentinelPrefix}${btoa(latin1)}${sentinelSuffix}`;
742
+ }
743
+ /** Read a JSON response once, retaining malformed/empty responses as errors. */
744
+ async function readJsonRpcPayload(response) {
745
+ const text = await response.text();
746
+ if (text === "")
747
+ return undefined;
748
+ try {
749
+ return JSON.parse(text);
750
+ }
751
+ catch (cause) {
752
+ throw new StatelessProtocolError(`Invalid JSON response: ${formatCause(cause)}`, {
753
+ status: response.status,
754
+ cause,
755
+ });
756
+ }
757
+ }
758
+ function jsonRpcError(payload) {
759
+ if (!isRecord(payload) || !isRecord(payload.error))
760
+ return undefined;
761
+ const code = payload.error.code;
762
+ const message = payload.error.message;
763
+ if (typeof code !== "number" || typeof message !== "string")
764
+ return undefined;
765
+ return {
766
+ code,
767
+ message,
768
+ ...("data" in payload.error ? { data: payload.error.data } : {}),
769
+ };
770
+ }
771
+ /** Return the Streamable HTTP endpoint for a base URL or a full `/mcp` URL. */
772
+ function mcpEndpointUrl(baseUrl) {
773
+ const url = new URL(baseUrl);
774
+ url.search = "";
775
+ url.hash = "";
776
+ const path = url.pathname.replace(/\/+$/, "");
777
+ url.pathname = path.endsWith("/mcp") ? path : `${path}/mcp`;
778
+ return url;
779
+ }
780
+ /**
781
+ * Canonicalize either a base URL or full `/mcp` endpoint to the base URL used
782
+ * for UI resource provenance.
783
+ */
784
+ function normalizeBaseUrl(rawUrl) {
785
+ const url = new URL(rawUrl);
786
+ url.search = "";
787
+ url.hash = "";
788
+ let path = url.pathname.replace(/\/+$/, "");
789
+ if (path.endsWith("/mcp"))
790
+ path = path.slice(0, -"/mcp".length);
791
+ url.pathname = path === "" ? "/" : path;
792
+ return url.toString().replace(/\/$/, "");
793
+ }
794
+ /** Stop an owned child process without letting cleanup obscure the root error. */
795
+ async function stopProcess(process) {
796
+ try {
797
+ process.kill("SIGTERM");
798
+ }
799
+ catch {
800
+ // The process may already have exited.
801
+ }
802
+ try {
803
+ await process.status;
804
+ }
805
+ catch {
806
+ // Best-effort cleanup.
807
+ }
808
+ }
809
+ /** Translate SDK and stateless transport errors into Compose runtime errors. */
810
+ function requestError(input) {
811
+ const target = requestTarget(input);
812
+ const code = requestErrorCode(input.kind, isRequestTimeout(input.cause));
813
+ return {
814
+ code,
815
+ message: isRequestTimeout(input.cause)
816
+ ? `${target} on "${input.serverName}" timed out after ${input.timeoutMs}ms`
817
+ : `${target} on "${input.serverName}" failed: ${formatCause(input.cause)}`,
818
+ server: input.serverName,
819
+ ...(input.toolName ? { tool: input.toolName } : {}),
820
+ cause: input.cause,
821
+ };
822
+ }
823
+ function requestTarget(input) {
824
+ switch (input.kind) {
825
+ case "tool-call":
826
+ return `Tool call "${input.toolName}"`;
827
+ case "resource-read":
828
+ return `Resource read "${input.uri}"`;
829
+ case "tool-list":
830
+ return "Tools list";
831
+ case "resource-list":
832
+ return "Resources list";
833
+ }
834
+ }
835
+ function requestErrorCode(kind, timedOut) {
836
+ switch (kind) {
837
+ case "tool-call":
838
+ return timedOut ? types_js_2.RuntimeErrorCode.TOOL_CALL_TIMEOUT : types_js_2.RuntimeErrorCode.TOOL_CALL_FAILED;
839
+ case "resource-read":
840
+ return timedOut
841
+ ? types_js_2.RuntimeErrorCode.RESOURCE_READ_TIMEOUT
842
+ : types_js_2.RuntimeErrorCode.RESOURCE_READ_FAILED;
843
+ case "tool-list":
844
+ return timedOut ? types_js_2.RuntimeErrorCode.TOOL_LIST_TIMEOUT : types_js_2.RuntimeErrorCode.TOOL_LIST_FAILED;
845
+ case "resource-list":
846
+ return timedOut
847
+ ? types_js_2.RuntimeErrorCode.RESOURCE_LIST_TIMEOUT
848
+ : types_js_2.RuntimeErrorCode.RESOURCE_LIST_FAILED;
849
+ }
850
+ }
851
+ function formatCause(cause) {
852
+ return cause instanceof Error ? cause.message : String(cause);
853
+ }
854
+ function isRequestTimeout(cause) {
855
+ if (cause instanceof types_js_1.McpError) {
856
+ return cause.code === types_js_1.ErrorCode.RequestTimeout;
857
+ }
858
+ if (cause instanceof StatelessProtocolError)
859
+ return isRequestTimeout(cause.cause);
860
+ return cause instanceof DOMException && cause.name === "TimeoutError";
861
+ }
862
+ function isRecord(value) {
863
+ return typeof value === "object" && value !== null && !Array.isArray(value);
864
+ }