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