@mcpview/compose 0.11.0 → 0.13.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 (143) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/README.md +87 -1
  3. package/esm/_dnt.polyfills.d.ts +51 -2
  4. package/esm/_dnt.polyfills.d.ts.map +1 -1
  5. package/esm/_dnt.polyfills.js +36 -0
  6. package/esm/src/code-mode/board.d.ts +66 -0
  7. package/esm/src/code-mode/board.d.ts.map +1 -0
  8. package/esm/src/code-mode/board.js +88 -0
  9. package/esm/src/code-mode/chain.d.ts +20 -0
  10. package/esm/src/code-mode/chain.d.ts.map +1 -0
  11. package/esm/src/code-mode/chain.js +240 -0
  12. package/esm/src/code-mode/connections.d.ts +33 -0
  13. package/esm/src/code-mode/connections.d.ts.map +1 -0
  14. package/esm/src/code-mode/connections.js +120 -0
  15. package/esm/src/code-mode/mod.d.ts +8 -0
  16. package/esm/src/code-mode/mod.d.ts.map +1 -0
  17. package/esm/src/code-mode/mod.js +6 -0
  18. package/esm/src/code-mode/provider-tools.d.ts +38 -0
  19. package/esm/src/code-mode/provider-tools.d.ts.map +1 -0
  20. package/esm/src/code-mode/provider-tools.js +113 -0
  21. package/esm/src/code-mode/providers.d.ts +20 -0
  22. package/esm/src/code-mode/providers.d.ts.map +1 -0
  23. package/esm/src/code-mode/providers.js +9 -0
  24. package/esm/src/code-mode/sandbox.d.ts +10 -0
  25. package/esm/src/code-mode/sandbox.d.ts.map +1 -0
  26. package/esm/src/code-mode/sandbox.js +147 -0
  27. package/esm/src/code-mode/tool.d.ts +13 -0
  28. package/esm/src/code-mode/tool.d.ts.map +1 -0
  29. package/esm/src/code-mode/tool.js +54 -0
  30. package/esm/src/core/collector/collector.d.ts +2 -1
  31. package/esm/src/core/collector/collector.d.ts.map +1 -1
  32. package/esm/src/core/collector/collector.js +6 -0
  33. package/esm/src/core/types/resources.d.ts +4 -0
  34. package/esm/src/core/types/resources.d.ts.map +1 -1
  35. package/esm/src/core/types/resources.js +10 -1
  36. package/esm/src/host/renderer/css/base.d.ts.map +1 -1
  37. package/esm/src/host/renderer/css/base.js +3 -0
  38. package/esm/src/host/renderer/css/layouts.d.ts.map +1 -1
  39. package/esm/src/host/renderer/css/layouts.js +17 -14
  40. package/esm/src/host/renderer/css/panel-controls.d.ts +3 -0
  41. package/esm/src/host/renderer/css/panel-controls.d.ts.map +1 -0
  42. package/esm/src/host/renderer/css/panel-controls.js +89 -0
  43. package/esm/src/host/renderer/html-generator.d.ts.map +1 -1
  44. package/esm/src/host/renderer/html-generator.js +38 -42
  45. package/esm/src/host/renderer/js/card-height.d.ts +3 -0
  46. package/esm/src/host/renderer/js/card-height.d.ts.map +1 -0
  47. package/esm/src/host/renderer/js/card-height.js +58 -0
  48. package/esm/src/host/renderer/js/event-bus.d.ts.map +1 -1
  49. package/esm/src/host/renderer/js/event-bus.js +32 -12
  50. package/esm/src/host/renderer/panel-controls.d.ts +23 -0
  51. package/esm/src/host/renderer/panel-controls.d.ts.map +1 -0
  52. package/esm/src/host/renderer/panel-controls.js +5 -0
  53. package/esm/src/host/renderer/panel-movement.d.ts +8 -0
  54. package/esm/src/host/renderer/panel-movement.d.ts.map +1 -0
  55. package/esm/src/host/renderer/panel-movement.js +392 -0
  56. package/esm/src/host/renderer/panel-reflow.d.ts +17 -0
  57. package/esm/src/host/renderer/panel-reflow.d.ts.map +1 -0
  58. package/esm/src/host/renderer/panel-reflow.js +342 -0
  59. package/esm/src/host/renderer/panel-resizing.d.ts +11 -0
  60. package/esm/src/host/renderer/panel-resizing.d.ts.map +1 -0
  61. package/esm/src/host/renderer/panel-resizing.js +347 -0
  62. package/esm/src/runtime/compose.d.ts.map +1 -1
  63. package/esm/src/runtime/compose.js +3 -0
  64. package/esm/src/runtime/manifest.d.ts.map +1 -1
  65. package/esm/src/runtime/manifest.js +4 -0
  66. package/esm/src/runtime/types.d.ts +2 -0
  67. package/esm/src/runtime/types.d.ts.map +1 -1
  68. package/esm/src/sdk/mcp-sdk.d.ts +2 -1
  69. package/esm/src/sdk/mcp-sdk.d.ts.map +1 -1
  70. package/esm/src/sdk/mcp-sdk.js +2 -2
  71. package/esm/src/version.d.ts +1 -1
  72. package/esm/src/version.js +1 -1
  73. package/package.json +13 -2
  74. package/script/_dnt.polyfills.d.ts +51 -2
  75. package/script/_dnt.polyfills.d.ts.map +1 -1
  76. package/script/_dnt.polyfills.js +36 -0
  77. package/script/src/code-mode/board.d.ts +66 -0
  78. package/script/src/code-mode/board.d.ts.map +1 -0
  79. package/script/src/code-mode/board.js +96 -0
  80. package/script/src/code-mode/chain.d.ts +20 -0
  81. package/script/src/code-mode/chain.d.ts.map +1 -0
  82. package/script/src/code-mode/chain.js +243 -0
  83. package/script/src/code-mode/connections.d.ts +33 -0
  84. package/script/src/code-mode/connections.d.ts.map +1 -0
  85. package/script/src/code-mode/connections.js +123 -0
  86. package/script/src/code-mode/mod.d.ts +8 -0
  87. package/script/src/code-mode/mod.d.ts.map +1 -0
  88. package/script/src/code-mode/mod.js +13 -0
  89. package/script/src/code-mode/provider-tools.d.ts +38 -0
  90. package/script/src/code-mode/provider-tools.d.ts.map +1 -0
  91. package/script/src/code-mode/provider-tools.js +116 -0
  92. package/script/src/code-mode/providers.d.ts +20 -0
  93. package/script/src/code-mode/providers.d.ts.map +1 -0
  94. package/script/src/code-mode/providers.js +13 -0
  95. package/script/src/code-mode/sandbox.d.ts +10 -0
  96. package/script/src/code-mode/sandbox.d.ts.map +1 -0
  97. package/script/src/code-mode/sandbox.js +152 -0
  98. package/script/src/code-mode/tool.d.ts +13 -0
  99. package/script/src/code-mode/tool.d.ts.map +1 -0
  100. package/script/src/code-mode/tool.js +57 -0
  101. package/script/src/core/collector/collector.d.ts +2 -1
  102. package/script/src/core/collector/collector.d.ts.map +1 -1
  103. package/script/src/core/collector/collector.js +6 -0
  104. package/script/src/core/types/resources.d.ts +4 -0
  105. package/script/src/core/types/resources.d.ts.map +1 -1
  106. package/script/src/core/types/resources.js +11 -0
  107. package/script/src/host/renderer/css/base.d.ts.map +1 -1
  108. package/script/src/host/renderer/css/base.js +3 -0
  109. package/script/src/host/renderer/css/layouts.d.ts.map +1 -1
  110. package/script/src/host/renderer/css/layouts.js +17 -14
  111. package/script/src/host/renderer/css/panel-controls.d.ts +3 -0
  112. package/script/src/host/renderer/css/panel-controls.d.ts.map +1 -0
  113. package/script/src/host/renderer/css/panel-controls.js +92 -0
  114. package/script/src/host/renderer/html-generator.d.ts.map +1 -1
  115. package/script/src/host/renderer/html-generator.js +38 -42
  116. package/script/src/host/renderer/js/card-height.d.ts +3 -0
  117. package/script/src/host/renderer/js/card-height.d.ts.map +1 -0
  118. package/script/src/host/renderer/js/card-height.js +61 -0
  119. package/script/src/host/renderer/js/event-bus.d.ts.map +1 -1
  120. package/script/src/host/renderer/js/event-bus.js +32 -12
  121. package/script/src/host/renderer/panel-controls.d.ts +23 -0
  122. package/script/src/host/renderer/panel-controls.d.ts.map +1 -0
  123. package/script/src/host/renderer/panel-controls.js +11 -0
  124. package/script/src/host/renderer/panel-movement.d.ts +8 -0
  125. package/script/src/host/renderer/panel-movement.d.ts.map +1 -0
  126. package/script/src/host/renderer/panel-movement.js +395 -0
  127. package/script/src/host/renderer/panel-reflow.d.ts +17 -0
  128. package/script/src/host/renderer/panel-reflow.d.ts.map +1 -0
  129. package/script/src/host/renderer/panel-reflow.js +345 -0
  130. package/script/src/host/renderer/panel-resizing.d.ts +11 -0
  131. package/script/src/host/renderer/panel-resizing.d.ts.map +1 -0
  132. package/script/src/host/renderer/panel-resizing.js +350 -0
  133. package/script/src/runtime/compose.d.ts.map +1 -1
  134. package/script/src/runtime/compose.js +3 -0
  135. package/script/src/runtime/manifest.d.ts.map +1 -1
  136. package/script/src/runtime/manifest.js +4 -0
  137. package/script/src/runtime/types.d.ts +2 -0
  138. package/script/src/runtime/types.d.ts.map +1 -1
  139. package/script/src/sdk/mcp-sdk.d.ts +2 -1
  140. package/script/src/sdk/mcp-sdk.d.ts.map +1 -1
  141. package/script/src/sdk/mcp-sdk.js +2 -2
  142. package/script/src/version.d.ts +1 -1
  143. package/script/src/version.js +1 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,28 @@ documented in this file.
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.13.0] - 2026-11-27
9
+
10
+ ### Added
11
+
12
+ - Drag a viewer by its top-left grip to swap or position it beside or below another viewer. Embedded
13
+ dashboards report their height to the host as rows appear or disappear. The bottom-right corner
14
+ snaps to widths declared by the viewer's Compose manifest or local adapter. A skeleton reserves
15
+ the destination during the drag so neighbors can move before release. Each App keeps its content
16
+ height, mounted state and event routes. Code Mode boards can use the same controls for locally
17
+ rendered panels.
18
+
19
+ ## [0.12.0] - 2026-11-26
20
+
21
+ ### Added
22
+
23
+ - `@mcpview/compose/code-mode` connects approved snippets on independent MCP servers to a single
24
+ `execute` tool. Programs can pass values between providers, select and order their results, and
25
+ save or replay a chain in a caller-scoped catalog.
26
+ - `@mcpview/compose/code-mode/board` turns selected receipts into a Compose descriptor for one
27
+ interactive MCP App. It preserves repeated views as separate panels and reuses the original
28
+ results when rendering.
29
+
8
30
  ## [0.11.0] - 2026-10-24
9
31
 
10
32
  ### Changed
package/README.md CHANGED
@@ -67,6 +67,66 @@ npm i @mcpview/compose
67
67
  import { buildCompositeUi, createCollector, renderComposite } from "@mcpview/compose";
68
68
  ```
69
69
 
70
+ ## Code Mode across MCP servers
71
+
72
+ A chat can call one `execute` tool that runs snippets on several MCP servers. For example, a CAD
73
+ provider generates a plate and returns an STL digest. A slicing provider accepts that digest and
74
+ estimates print time. The script decides which results to show and in what order.
75
+
76
+ ```js
77
+ const plate = await api.runSnippet("cad", "plate-stl", { thicknessMm: api.params.thicknessMm });
78
+ const estimate = await api.runSnippet("slicer", "pla-print-estimate", {
79
+ stlSha256: plate.value.stlSha256,
80
+ });
81
+ await api.panel(estimate.id, "PLA estimate");
82
+ await api.panel(plate.id, "Plate geometry");
83
+ return { seconds: estimate.value.print_time_s };
84
+ ```
85
+
86
+ To offer this workflow, register the upstream connections on the server that owns the board. The
87
+ following code assumes an existing MCPView `app` with a registered MCP App resource at
88
+ `ui://parts/board`.
89
+
90
+ ```ts
91
+ import {
92
+ connectSnippetProviders,
93
+ createSnippetChain,
94
+ createSnippetExecuteTool,
95
+ } from "@mcpview/compose/code-mode";
96
+
97
+ const connections = await connectSnippetProviders([
98
+ { alias: "cad", url: "http://127.0.0.1:3614/mcp", snippets: ["plate-stl"] },
99
+ { alias: "slicer", url: "http://127.0.0.1:3622/mcp", snippets: ["pla-print-estimate"] },
100
+ ]);
101
+ const execute = createSnippetChain(connections.providers);
102
+ app.registerTool(
103
+ createSnippetExecuteTool({ resourceUri: "ui://parts/board", providers: connections.providers }),
104
+ (args, ctx) => execute(args, { signal: ctx?.request?.signal }),
105
+ );
106
+ // On shutdown, await connections.close().
107
+ ```
108
+
109
+ On an upstream MCPView server, `registerSnippetProvider(app, { snippets, authorize })` exposes
110
+ `list_snippets` and `run_snippet`. Each definition supplies its name, description, JSON input schema
111
+ and `run(input, context)` callback for its saved program. The callback returns a native MCP result
112
+ with the script-visible JSON in `structuredContent.value`. Discovery and replay both check the
113
+ configured authorization. A configured URL uses the host's upstream identity. Where users have
114
+ different permissions, bind a client resolver for the authenticated caller.
115
+
116
+ To save complete workflows, pass a catalog from `@mcpview/server/snippets` as the second argument to
117
+ `createSnippetChain`, set `savedChains: true` on the tool declaration and supply a trusted `scope`
118
+ per call. The host derives this scope from the authenticated user and integration. `saveAs` retains
119
+ the program and its parameter types. `replay` runs it with fresh inputs and the caller's current
120
+ provider permissions.
121
+
122
+ In the board's MCP Apps tool-result handler, call `composeSnippetBoard(result, { layout: "split" })`
123
+ from `@mcpview/compose/code-mode/board`. Each selected receipt has its own component ID, including
124
+ two instances of the same viewer. The board renders each child from `child.context.panel.result`.
125
+ For a result with no declared UI resource, supply `resolveView` to select a local renderer. This
126
+ path uses results already returned by the script. The runnable engineering example includes the
127
+ server, both providers, and a single-frame board with a 3D viewer and interactive print report.
128
+ [Engineering example and setup](https://github.com/mcpview/mcpview/tree/main/packages/compose/examples/multi-mcp-snippets)
129
+
70
130
  ## MCP SDK compatibility
71
131
 
72
132
  Compose uses MCP Apps 2.x and the split MCP SDK 2.x packages. Integrations importing SDK types or
@@ -160,11 +220,37 @@ Each step is a pure function. Use them independently or together.
160
220
 
161
221
  | Layout | Description |
162
222
  | ------- | ----------------------------- |
163
- | `split` | Side-by-side panels (flexbox) |
223
+ | `split` | Side-by-side panels |
164
224
  | `tabs` | Tabbed interface with tab bar |
165
225
  | `grid` | Auto-fit grid for dashboards |
166
226
  | `stack` | Vertical stack (default) |
167
227
 
228
+ Drag the grip in the top-left corner to move a viewer. Aim at the bottom edge of another viewer to
229
+ place it on the row below. Drop beside it to return to one row when both widths fit, or drop in its
230
+ center to swap. The skeleton shows where the viewer will land. An embedded Compose board reports its
231
+ content height to the host as the rows change, including during the preview and on cancellation. You
232
+ can also swap by clicking or tapping two handles in sequence. In a tabbed dashboard the handles
233
+ reorder the tabs.
234
+
235
+ Declare a viewer's supported widths in CSS pixels on its Compose manifest tool, for example
236
+ `"supportedWidths": [380, 640]`. Programmatic descriptors and local Code Mode view adapters accept
237
+ the same field. Omit it for a viewer that should keep its template size.
238
+
239
+ Drag the bottom-right corner to preview an allowed width. At the right edge of the screen, pull down
240
+ to reach a wider format. The skeleton reserves the space and neighbors shift sideways or wrap to a
241
+ new row. When the viewer shrinks, its neighbor returns beside it with the template's original gap as
242
+ soon as both fit. Release to apply the width or press Escape to cancel. The left and right arrow
243
+ keys step between available widths when the corner has focus. Reopening the dashboard restores the
244
+ template layout. Each iframe stays mounted and reports its own content height as its width changes.
245
+
246
+ For a Code Mode board with local renderers, `@mcpview/compose/code-mode/board` exports
247
+ `getPanelControlsCss()`, `installPanelMovement(board, signal?)` and
248
+ `installPanelResizing(board, signal?)`. Mark the grid with `data-compose-board` and its direct panel
249
+ elements with `data-compose-panel` and `data-panel-label`. Set `data-compose-widths` to the
250
+ space-separated widths of each resizable local viewer. Place a `button[data-compose-grip]` inside
251
+ each panel. Named layouts identify each panel's grid area with `data-area`. The
252
+ [CAD and print estimate board](./examples/multi-mcp-snippets/ui/main.ts) shows the full setup.
253
+
168
254
  ## Sync Rules
169
255
 
170
256
  Declarative event routing between UIs:
@@ -1,6 +1,49 @@
1
1
  declare global {
2
- interface Error {
3
- cause?: unknown;
2
+ interface Array<T> {
3
+ /**
4
+ * Returns the value of the last element in the array where predicate is true, and undefined
5
+ * otherwise.
6
+ * @param predicate find calls predicate once for each element of the array, in ascending
7
+ * order, until it finds one where predicate returns true. If such an element is found, find
8
+ * immediately returns that element value. Otherwise, find returns undefined.
9
+ * @param thisArg If provided, it will be used as the this value for each invocation of
10
+ * predicate. If it is not provided, undefined is used instead.
11
+ */
12
+ findLast<S extends T>(predicate: (this: void, value: T, index: number, obj: T[]) => value is S, thisArg?: any): S | undefined;
13
+ findLast(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): T | undefined;
14
+ /**
15
+ * Returns the index of the last element in the array where predicate is true, and -1
16
+ * otherwise.
17
+ * @param predicate find calls predicate once for each element of the array, in ascending
18
+ * order, until it finds one where predicate returns true. If such an element is found,
19
+ * findIndex immediately returns that element index. Otherwise, findIndex returns -1.
20
+ * @param thisArg If provided, it will be used as the this value for each invocation of
21
+ * predicate. If it is not provided, undefined is used instead.
22
+ */
23
+ findLastIndex(predicate: (value: T, index: number, obj: T[]) => unknown, thisArg?: any): number;
24
+ }
25
+ interface Uint8Array {
26
+ /**
27
+ * Returns the value of the last element in the array where predicate is true, and undefined
28
+ * otherwise.
29
+ * @param predicate findLast calls predicate once for each element of the array, in descending
30
+ * order, until it finds one where predicate returns true. If such an element is found, findLast
31
+ * immediately returns that element value. Otherwise, findLast returns undefined.
32
+ * @param thisArg If provided, it will be used as the this value for each invocation of
33
+ * predicate. If it is not provided, undefined is used instead.
34
+ */
35
+ findLast<S extends number>(predicate: (value: number, index: number, array: Uint8Array) => value is S, thisArg?: any): S | undefined;
36
+ findLast(predicate: (value: number, index: number, array: Uint8Array) => unknown, thisArg?: any): number | undefined;
37
+ /**
38
+ * Returns the index of the last element in the array where predicate is true, and -1
39
+ * otherwise.
40
+ * @param predicate findLastIndex calls predicate once for each element of the array, in descending
41
+ * order, until it finds one where predicate returns true. If such an element is found,
42
+ * findLastIndex immediately returns that element index. Otherwise, findLastIndex returns -1.
43
+ * @param thisArg If provided, it will be used as the this value for each invocation of
44
+ * predicate. If it is not provided, undefined is used instead.
45
+ */
46
+ findLastIndex(predicate: (value: number, index: number, array: Uint8Array) => unknown, thisArg?: any): number;
4
47
  }
5
48
  }
6
49
  export {};
@@ -15,4 +58,10 @@ declare global {
15
58
  }
16
59
  }
17
60
  export {};
61
+ declare global {
62
+ interface Error {
63
+ cause?: unknown;
64
+ }
65
+ }
66
+ export {};
18
67
  //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AAAA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC;AAgBV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC"}
1
+ {"version":3,"file":"_dnt.polyfills.d.ts","sourceRoot":"","sources":["../src/_dnt.polyfills.ts"],"names":[],"mappings":"AACA,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC,CAAC;QACf;;;;;;;;WAQG;QACH,QAAQ,CAAC,CAAC,SAAS,CAAC,EAClB,SAAS,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC,EACxE,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QACjB,QAAQ,CACN,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EACzD,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QAEjB;;;;;;;;WAQG;QACH,aAAa,CACX,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,KAAK,OAAO,EACzD,OAAO,CAAC,EAAE,GAAG,GACZ,MAAM,CAAC;KACX;IACD,UAAU,UAAU;QAClB;;;;;;;;WAQG;QACH,QAAQ,CAAC,CAAC,SAAS,MAAM,EACvB,SAAS,EAAE,CACP,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,UAAU,KAChB,KAAK,IAAI,CAAC,EACf,OAAO,CAAC,EAAE,GAAG,GACZ,CAAC,GAAG,SAAS,CAAC;QACjB,QAAQ,CACJ,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,EACvE,OAAO,CAAC,EAAE,GAAG,GACd,MAAM,GAAG,SAAS,CAAC;QAEtB;;;;;;;;WAQG;QACH,aAAa,CACT,SAAS,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,KAAK,OAAO,EACvE,OAAO,CAAC,EAAE,GAAG,GACd,MAAM,CAAC;KACX;CACF;AA4CD,OAAO,EAAE,CAAC;AAgBV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,MAAM;QACd;;;;WAIG;QACH,MAAM,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;KAC5C;CACF;AAED,OAAO,EAAE,CAAC;AACV,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK;QACb,KAAK,CAAC,EAAE,OAAO,CAAC;KACjB;CACF;AAED,OAAO,EAAE,CAAC"}
@@ -1,3 +1,39 @@
1
+ function findLastIndex(self, callbackfn, that) {
2
+ const boundFunc = that === undefined ? callbackfn : callbackfn.bind(that);
3
+ let index = self.length - 1;
4
+ while (index >= 0) {
5
+ const result = boundFunc(self[index], index, self);
6
+ if (result) {
7
+ return index;
8
+ }
9
+ index--;
10
+ }
11
+ return -1;
12
+ }
13
+ function findLast(self, callbackfn, that) {
14
+ const index = self.findLastIndex(callbackfn, that);
15
+ return index === -1 ? undefined : self[index];
16
+ }
17
+ if (!Array.prototype.findLastIndex) {
18
+ Array.prototype.findLastIndex = function (callbackfn, that) {
19
+ return findLastIndex(this, callbackfn, that);
20
+ };
21
+ }
22
+ if (!Array.prototype.findLast) {
23
+ Array.prototype.findLast = function (callbackfn, that) {
24
+ return findLast(this, callbackfn, that);
25
+ };
26
+ }
27
+ if (!Uint8Array.prototype.findLastIndex) {
28
+ Uint8Array.prototype.findLastIndex = function (callbackfn, that) {
29
+ return findLastIndex(this, callbackfn, that);
30
+ };
31
+ }
32
+ if (!Uint8Array.prototype.findLast) {
33
+ Uint8Array.prototype.findLast = function (callbackfn, that) {
34
+ return findLast(this, callbackfn, that);
35
+ };
36
+ }
1
37
  // https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
2
38
  if (!Object.hasOwn) {
3
39
  Object.defineProperty(Object, "hasOwn", {
@@ -0,0 +1,66 @@
1
+ /**
2
+ * Browser-side composition of completed Code Mode results.
3
+ * @module
4
+ */
5
+ import "../../_dnt.polyfills.js";
6
+ import type { ComponentSurface } from "../core/types/components.js";
7
+ import type { CompositeUiDescriptor } from "../core/types/descriptor.js";
8
+ import type { UiLayout } from "../core/types/layout.js";
9
+ export { getPanelControlsCss } from "../host/renderer/css/panel-controls.js";
10
+ export { installPanelMovement, installPanelResizing } from "../host/renderer/panel-controls.js";
11
+ /** MCP App result metadata containing the receipts selected by the program. */
12
+ export declare const SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
13
+ /** A selected provider result. The receipt ID distinguishes calls to the same snippet. */
14
+ export interface SnippetPanel {
15
+ readonly id: string;
16
+ readonly provider: string;
17
+ readonly name: string;
18
+ readonly title: string;
19
+ readonly result: Record<string, unknown>;
20
+ }
21
+ /** An App-owned view for a receipt, with optional renderer data and component selection. */
22
+ export interface SnippetPanelView {
23
+ readonly resourceUri: string;
24
+ readonly context?: Record<string, unknown>;
25
+ readonly surface?: ComponentSurface;
26
+ /** Widths offered by this local view in CSS pixels. An empty list disables resizing. */
27
+ readonly supportedWidths?: readonly number[];
28
+ }
29
+ /** Display options supplied by the board hosting the results. */
30
+ export interface SnippetBoardOptions {
31
+ /** A Compose layout or a function of the number of mounted panels. Defaults to stack. */
32
+ readonly layout?: UiLayout | ((count: number) => UiLayout);
33
+ /** Provide a local view adapter or return undefined to use the result's native MCP App URI. */
34
+ readonly resolveView?: (panel: SnippetPanel) => SnippetPanelView | undefined;
35
+ }
36
+ /**
37
+ * Return selected receipts in display order from the App-only MCP result metadata.
38
+ * Invalid entries and repeated receipt IDs are ignored. Distinct receipts can
39
+ * point to the same snippet and viewer.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * for (const panel of readSnippetPanels(toolResult)) {
44
+ * console.log(panel.provider, panel.name, panel.title);
45
+ * }
46
+ * ```
47
+ */
48
+ export declare function readSnippetPanels(result: unknown): SnippetPanel[];
49
+ /**
50
+ * Build a Compose descriptor from the current execution, without making any provider calls.
51
+ * Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
52
+ * The returned summary is shared as `sharedContext.value` when the execution has a value.
53
+ * A data-only receipt needs a local view adapter to produce a child.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * const board = composeSnippetBoard(toolResult, {
58
+ * layout: "split",
59
+ * resolveView: (panel) => panel.provider === "metrics"
60
+ * ? { resourceUri: "ui://my-board/metrics" }
61
+ * : undefined,
62
+ * });
63
+ * ```
64
+ */
65
+ export declare function composeSnippetBoard(result: unknown, options?: SnippetBoardOptions): CompositeUiDescriptor;
66
+ //# sourceMappingURL=board.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"board.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/board.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,yBAAyB,CAAC;AAMjC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAExD,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,oCAAoC,CAAC;AAEhG,+EAA+E;AAC/E,eAAO,MAAM,uBAAuB,8BAA8B,CAAC;AAEnE,0FAA0F;AAC1F,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC1C;AAED,4FAA4F;AAC5F,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3C,QAAQ,CAAC,OAAO,CAAC,EAAE,gBAAgB,CAAC;IACpC,wFAAwF;IACxF,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED,iEAAiE;AACjE,MAAM,WAAW,mBAAmB;IAClC,yFAAyF;IACzF,QAAQ,CAAC,MAAM,CAAC,EAAE,QAAQ,GAAG,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,QAAQ,CAAC,CAAC;IAC3D,+FAA+F;IAC/F,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,gBAAgB,GAAG,SAAS,CAAC;CAC9E;AAcD;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,OAAO,GAAG,YAAY,EAAE,CAajE;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,OAAO,EACf,OAAO,GAAE,mBAAwB,GAChC,qBAAqB,CAyBvB"}
@@ -0,0 +1,88 @@
1
+ /**
2
+ * Browser-side composition of completed Code Mode results.
3
+ * @module
4
+ */
5
+ import "../../_dnt.polyfills.js";
6
+ import { createCollector } from "../core/collector/collector.js";
7
+ import { extractUiMeta } from "../core/collector/extractor.js";
8
+ import { buildCompositeUi } from "../core/composer/composer.js";
9
+ export { getPanelControlsCss } from "../host/renderer/css/panel-controls.js";
10
+ export { installPanelMovement, installPanelResizing } from "../host/renderer/panel-controls.js";
11
+ /** MCP App result metadata containing the receipts selected by the program. */
12
+ export const SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
13
+ function record(value) {
14
+ return value !== null && typeof value === "object" && !Array.isArray(value);
15
+ }
16
+ function isPanel(value) {
17
+ return record(value) &&
18
+ typeof value.id === "string" && value.id.length > 0 &&
19
+ typeof value.provider === "string" && value.provider.length > 0 &&
20
+ typeof value.name === "string" && value.name.length > 0 &&
21
+ typeof value.title === "string" && record(value.result);
22
+ }
23
+ /**
24
+ * Return selected receipts in display order from the App-only MCP result metadata.
25
+ * Invalid entries and repeated receipt IDs are ignored. Distinct receipts can
26
+ * point to the same snippet and viewer.
27
+ *
28
+ * @example
29
+ * ```ts
30
+ * for (const panel of readSnippetPanels(toolResult)) {
31
+ * console.log(panel.provider, panel.name, panel.title);
32
+ * }
33
+ * ```
34
+ */
35
+ export function readSnippetPanels(result) {
36
+ if (!record(result) || !record(result._meta))
37
+ return [];
38
+ const items = result._meta[SNIPPET_PANELS_META_KEY];
39
+ if (!Array.isArray(items))
40
+ return [];
41
+ const seen = new Set();
42
+ const panels = [];
43
+ for (const item of items) {
44
+ if (isPanel(item) && !seen.has(item.id)) {
45
+ panels.push(item);
46
+ seen.add(item.id);
47
+ }
48
+ }
49
+ return panels;
50
+ }
51
+ /**
52
+ * Build a Compose descriptor from the current execution, without making any provider calls.
53
+ * Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
54
+ * The returned summary is shared as `sharedContext.value` when the execution has a value.
55
+ * A data-only receipt needs a local view adapter to produce a child.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * const board = composeSnippetBoard(toolResult, {
60
+ * layout: "split",
61
+ * resolveView: (panel) => panel.provider === "metrics"
62
+ * ? { resourceUri: "ui://my-board/metrics" }
63
+ * : undefined,
64
+ * });
65
+ * ```
66
+ */
67
+ export function composeSnippetBoard(result, options = {}) {
68
+ const summary = record(result) && record(result.structuredContent)
69
+ ? result.structuredContent
70
+ : {};
71
+ const collector = createCollector();
72
+ for (const panel of readSnippetPanels(result)) {
73
+ const view = options.resolveView?.(panel);
74
+ const resourceUri = view?.resourceUri ?? extractUiMeta(panel.result)?.resourceUri;
75
+ if (!resourceUri || !/^ui:\/\/[^\s]+$/.test(resourceUri))
76
+ continue;
77
+ collector.collect(`${panel.provider}:${panel.name}`, { _meta: { ui: { resourceUri } } }, {
78
+ panel,
79
+ ...(view?.context === undefined ? {} : { view: view.context }),
80
+ ...(Object.hasOwn(summary, "value") ? { value: summary.value } : {}),
81
+ }, { componentId: panel.id, surface: view?.surface, supportedWidths: view?.supportedWidths });
82
+ }
83
+ const resources = collector.getResources();
84
+ const layout = typeof options.layout === "function"
85
+ ? options.layout(resources.length)
86
+ : options.layout;
87
+ return buildCompositeUi(resources, { layout: layout ?? "stack", sharedContext: ["value"] });
88
+ }
@@ -0,0 +1,20 @@
1
+ import type { CallToolResult } from "@modelcontextprotocol/client";
2
+ import type { SnippetCatalog } from "@mcpview/server/snippets";
3
+ import { type SnippetChainContext, type SnippetProvider } from "./providers.js";
4
+ /** Selected native result, available only to the MCP App in result metadata. */
5
+ export interface SnippetPanelReceipt {
6
+ id: string;
7
+ provider: string;
8
+ name: string;
9
+ title: string;
10
+ result: CallToolResult;
11
+ }
12
+ /** Execute input from the MCP tool using trusted context supplied separately by the host. */
13
+ export type SnippetChainExecutor = (input: Record<string, unknown>, context?: SnippetChainContext) => Promise<CallToolResult>;
14
+ /**
15
+ * Run JavaScript against host-configured snippet providers. Selected results stay
16
+ * out of guest memory except for their declared JSON value. Supplying a catalog
17
+ * enables named chains for calls with a trusted scope.
18
+ */
19
+ export declare function createSnippetChain(providers: ReadonlyMap<string, SnippetProvider>, catalog?: SnippetCatalog): SnippetChainExecutor;
20
+ //# sourceMappingURL=chain.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"chain.d.ts","sourceRoot":"","sources":["../../../src/src/code-mode/chain.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,KAAK,EAAE,cAAc,EAAqB,MAAM,0BAA0B,CAAC;AAElF,OAAO,EAAiB,KAAK,mBAAmB,EAAE,KAAK,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAI/F,gFAAgF;AAChF,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,cAAc,CAAC;CACxB;AAqED,6FAA6F;AAC7F,MAAM,MAAM,oBAAoB,GAAG,CACjC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC9B,OAAO,CAAC,EAAE,mBAAmB,KAC1B,OAAO,CAAC,cAAc,CAAC,CAAC;AAE7B;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,eAAe,CAAC,EAC/C,OAAO,CAAC,EAAE,cAAc,GACvB,oBAAoB,CAyMtB"}