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