@mcpview/compose 0.10.0 → 0.12.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 (77) hide show
  1. package/CHANGELOG.md +37 -0
  2. package/README.md +92 -2
  3. package/esm/_dnt.polyfills.d.ts +6 -6
  4. package/esm/_dnt.polyfills.d.ts.map +1 -1
  5. package/esm/src/code-mode/board.d.ts +62 -0
  6. package/esm/src/code-mode/board.d.ts.map +1 -0
  7. package/esm/src/code-mode/board.js +86 -0
  8. package/esm/src/code-mode/chain.d.ts +20 -0
  9. package/esm/src/code-mode/chain.d.ts.map +1 -0
  10. package/esm/src/code-mode/chain.js +240 -0
  11. package/esm/src/code-mode/connections.d.ts +33 -0
  12. package/esm/src/code-mode/connections.d.ts.map +1 -0
  13. package/esm/src/code-mode/connections.js +120 -0
  14. package/esm/src/code-mode/mod.d.ts +8 -0
  15. package/esm/src/code-mode/mod.d.ts.map +1 -0
  16. package/esm/src/code-mode/mod.js +6 -0
  17. package/esm/src/code-mode/provider-tools.d.ts +38 -0
  18. package/esm/src/code-mode/provider-tools.d.ts.map +1 -0
  19. package/esm/src/code-mode/provider-tools.js +113 -0
  20. package/esm/src/code-mode/providers.d.ts +20 -0
  21. package/esm/src/code-mode/providers.d.ts.map +1 -0
  22. package/esm/src/code-mode/providers.js +9 -0
  23. package/esm/src/code-mode/sandbox.d.ts +10 -0
  24. package/esm/src/code-mode/sandbox.d.ts.map +1 -0
  25. package/esm/src/code-mode/sandbox.js +147 -0
  26. package/esm/src/code-mode/tool.d.ts +13 -0
  27. package/esm/src/code-mode/tool.d.ts.map +1 -0
  28. package/esm/src/code-mode/tool.js +54 -0
  29. package/esm/src/core/types/mcp-apps.d.ts +1 -1
  30. package/esm/src/host/renderer/js/event-bus.d.ts.map +1 -1
  31. package/esm/src/host/renderer/js/event-bus.js +4 -3
  32. package/esm/src/runtime/cluster.d.ts.map +1 -1
  33. package/esm/src/runtime/cluster.js +38 -10
  34. package/esm/src/runtime/types.d.ts +3 -3
  35. package/esm/src/runtime/types.d.ts.map +1 -1
  36. package/esm/src/sdk/mcp-sdk.d.ts +4 -4
  37. package/esm/src/sdk/mcp-sdk.js +2 -2
  38. package/esm/src/version.d.ts +1 -1
  39. package/esm/src/version.js +1 -1
  40. package/package.json +17 -3
  41. package/script/_dnt.polyfills.d.ts +6 -6
  42. package/script/_dnt.polyfills.d.ts.map +1 -1
  43. package/script/src/code-mode/board.d.ts +62 -0
  44. package/script/src/code-mode/board.d.ts.map +1 -0
  45. package/script/src/code-mode/board.js +91 -0
  46. package/script/src/code-mode/chain.d.ts +20 -0
  47. package/script/src/code-mode/chain.d.ts.map +1 -0
  48. package/script/src/code-mode/chain.js +243 -0
  49. package/script/src/code-mode/connections.d.ts +33 -0
  50. package/script/src/code-mode/connections.d.ts.map +1 -0
  51. package/script/src/code-mode/connections.js +123 -0
  52. package/script/src/code-mode/mod.d.ts +8 -0
  53. package/script/src/code-mode/mod.d.ts.map +1 -0
  54. package/script/src/code-mode/mod.js +13 -0
  55. package/script/src/code-mode/provider-tools.d.ts +38 -0
  56. package/script/src/code-mode/provider-tools.d.ts.map +1 -0
  57. package/script/src/code-mode/provider-tools.js +116 -0
  58. package/script/src/code-mode/providers.d.ts +20 -0
  59. package/script/src/code-mode/providers.d.ts.map +1 -0
  60. package/script/src/code-mode/providers.js +13 -0
  61. package/script/src/code-mode/sandbox.d.ts +10 -0
  62. package/script/src/code-mode/sandbox.d.ts.map +1 -0
  63. package/script/src/code-mode/sandbox.js +152 -0
  64. package/script/src/code-mode/tool.d.ts +13 -0
  65. package/script/src/code-mode/tool.d.ts.map +1 -0
  66. package/script/src/code-mode/tool.js +57 -0
  67. package/script/src/core/types/mcp-apps.d.ts +1 -1
  68. package/script/src/host/renderer/js/event-bus.d.ts.map +1 -1
  69. package/script/src/host/renderer/js/event-bus.js +4 -3
  70. package/script/src/runtime/cluster.d.ts.map +1 -1
  71. package/script/src/runtime/cluster.js +60 -32
  72. package/script/src/runtime/types.d.ts +3 -3
  73. package/script/src/runtime/types.d.ts.map +1 -1
  74. package/script/src/sdk/mcp-sdk.d.ts +4 -4
  75. package/script/src/sdk/mcp-sdk.js +2 -2
  76. package/script/src/version.d.ts +1 -1
  77. package/script/src/version.js +1 -1
@@ -25,9 +25,7 @@
25
25
  *
26
26
  * @module runtime/cluster
27
27
  */
28
- import { Client } from "@modelcontextprotocol/sdk/client/index.js";
29
- import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
30
- import { ErrorCode, McpError } from "@modelcontextprotocol/sdk/types.js";
28
+ import { Client, SdkError, SdkErrorCode, StreamableHTTPClientTransport, } from "@modelcontextprotocol/client";
31
29
  import { COMPOSE_VERSION } from "../version.js";
32
30
  import { RuntimeErrorCode } from "./types.js";
33
31
  /** Default timeout for server startup (ms). */
@@ -445,7 +443,17 @@ async function createMcpConnection(name, transportType, baseUrl, protocol, stopO
445
443
  */
446
444
  async function createStreamableConnection(name, transportType, baseUrl, stopOwnedProcess) {
447
445
  const transport = new StreamableHTTPClientTransport(mcpEndpointUrl(baseUrl));
448
- const client = new Client({ name: "@mcpview/compose", version: COMPOSE_VERSION }, { capabilities: {} });
446
+ const client = new Client({ name: "@mcpview/compose", version: COMPOSE_VERSION }, { capabilities: {}, versionNegotiation: { mode: "legacy" } });
447
+ // The SDK list helper aggregates pages. Keep the definitions from our single-page
448
+ // requests so callTool still applies the SDK's output-schema validation.
449
+ const toolDefinitions = new Map();
450
+ let toolDefinitionGeneration = 0;
451
+ const invalidateToolDefinitions = () => {
452
+ toolDefinitionGeneration++;
453
+ toolDefinitions.clear();
454
+ };
455
+ client.onclose = invalidateToolDefinitions;
456
+ client.setNotificationHandler("notifications/tools/list_changed", invalidateToolDefinitions);
449
457
  try {
450
458
  await client.connect(transport, { timeout: DEFAULT_STARTUP_TIMEOUT_MS });
451
459
  }
@@ -462,6 +470,7 @@ async function createStreamableConnection(name, transportType, baseUrl, stopOwne
462
470
  if (closed)
463
471
  return;
464
472
  closed = true;
473
+ invalidateToolDefinitions();
465
474
  try {
466
475
  // Streamable HTTP sessions are server-side state. Terminate them while
467
476
  // the transport is still open, then close local listeners regardless
@@ -482,7 +491,10 @@ async function createStreamableConnection(name, transportType, baseUrl, stopOwne
482
491
  },
483
492
  async callTool(toolName, args) {
484
493
  try {
485
- return await client.callTool({ name: toolName, arguments: args ?? {} }, undefined, { timeout: DEFAULT_REQUEST_TIMEOUT_MS });
494
+ return await client.callTool({ name: toolName, arguments: args ?? {} }, {
495
+ timeout: DEFAULT_REQUEST_TIMEOUT_MS,
496
+ toolDefinition: toolDefinitions.get(toolName),
497
+ });
486
498
  }
487
499
  catch (cause) {
488
500
  throw requestError({
@@ -496,7 +508,11 @@ async function createStreamableConnection(name, transportType, baseUrl, stopOwne
496
508
  },
497
509
  async readResource(uri) {
498
510
  try {
499
- return await client.readResource({ uri }, { timeout: DEFAULT_REQUEST_TIMEOUT_MS });
511
+ // Each Compose read must reach its source, even when it supplies cache hints.
512
+ return await client.readResource({ uri }, {
513
+ timeout: DEFAULT_REQUEST_TIMEOUT_MS,
514
+ cacheMode: "bypass",
515
+ });
500
516
  }
501
517
  catch (cause) {
502
518
  throw requestError({
@@ -510,7 +526,19 @@ async function createStreamableConnection(name, transportType, baseUrl, stopOwne
510
526
  },
511
527
  async listTools(cursor) {
512
528
  try {
513
- return await client.listTools(cursor === undefined ? undefined : { cursor }, { timeout: DEFAULT_REQUEST_TIMEOUT_MS });
529
+ // Start a fresh catalog on page one, then retain each explicitly fetched page.
530
+ if (cursor === undefined)
531
+ invalidateToolDefinitions();
532
+ const generation = toolDefinitionGeneration;
533
+ const page = await client.request({ method: "tools/list", params: cursor === undefined ? {} : { cursor } }, { timeout: DEFAULT_REQUEST_TIMEOUT_MS });
534
+ // A list_changed notification or disconnect may have invalidated this reply
535
+ // while it was in flight. Do not restore stale definitions after either.
536
+ if (!closed && generation === toolDefinitionGeneration) {
537
+ for (const tool of page.tools) {
538
+ toolDefinitions.set(tool.name, structuredClone(tool));
539
+ }
540
+ }
541
+ return page;
514
542
  }
515
543
  catch (cause) {
516
544
  throw requestError({
@@ -523,7 +551,7 @@ async function createStreamableConnection(name, transportType, baseUrl, stopOwne
523
551
  },
524
552
  async listResources(cursor) {
525
553
  try {
526
- return await client.listResources(cursor === undefined ? undefined : { cursor }, { timeout: DEFAULT_REQUEST_TIMEOUT_MS });
554
+ return await client.request({ method: "resources/list", params: cursor === undefined ? {} : { cursor } }, { timeout: DEFAULT_REQUEST_TIMEOUT_MS });
527
555
  }
528
556
  catch (cause) {
529
557
  throw requestError({
@@ -847,8 +875,8 @@ function formatCause(cause) {
847
875
  return cause instanceof Error ? cause.message : String(cause);
848
876
  }
849
877
  function isRequestTimeout(cause) {
850
- if (cause instanceof McpError) {
851
- return cause.code === ErrorCode.RequestTimeout;
878
+ if (cause instanceof SdkError) {
879
+ return cause.code === SdkErrorCode.RequestTimeout;
852
880
  }
853
881
  if (cause instanceof StatelessProtocolError)
854
882
  return isRequestTimeout(cause.cause);
@@ -9,7 +9,7 @@
9
9
  import type { UiLayout } from "../core/types/layout.js";
10
10
  import type { UiPortSyncRule, UiSyncRule } from "../core/types/sync-rules.js";
11
11
  import type { CompositeUiDescriptor } from "../core/types/descriptor.js";
12
- import type { ReadResourceResult } from "@modelcontextprotocol/sdk/types.js";
12
+ import type { ReadResourceResult } from "@modelcontextprotocol/client";
13
13
  import type { ComposedDashboardPanel } from "./host-dashboard-types.js";
14
14
  import type { ComponentSurface } from "../core/types/components.js";
15
15
  /**
@@ -183,9 +183,9 @@ export interface McpConnection {
183
183
  callTool(toolName: string, args?: Record<string, unknown>): Promise<unknown>;
184
184
  /** Read a resource through the server's active MCP transport. */
185
185
  readResource(uri: string): Promise<McpReadResourceResult>;
186
- /** List tools through this server's active MCP transport. */
186
+ /** List one page of tools; pass the returned nextCursor to continue. */
187
187
  listTools(cursor?: string): Promise<McpListToolsResult>;
188
- /** List resources through this server's active MCP transport. */
188
+ /** List one page of resources; pass the returned nextCursor to continue. */
189
189
  listResources(cursor?: string): Promise<McpListResourcesResult>;
190
190
  }
191
191
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/src/runtime/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACzE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAMpE;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,mCAAmC;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,yBAAyB;IACzB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,6CAA6C;IAC7C,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC7B,0EAA0E;IAC1E,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,QAAQ,CAAC,EAAE,eAAe,CAAC;CAC5B;AAED,4DAA4D;AAC5D,MAAM,MAAM,eAAe,GACvB,MAAM,GACN,sBAAsB,GACtB,iBAAiB,CAAC;AAEtB,+DAA+D;AAC/D,MAAM,MAAM,YAAY,GAAG,cAAc,GAAG,aAAa,CAAC;AAM1D;;;;;;;;;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AAM,WAAW,YAAY;IAC3B,IAAI,EAAE,gBAAgB,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * MCP SDK adapter — wraps the collector for use with `@modelcontextprotocol/sdk` tool call results.
2
+ * MCP SDK adapter — wraps the collector for use with `@modelcontextprotocol/client` tool call results.
3
3
  *
4
4
  * This adapter provides a convenience wrapper around the collector that accepts
5
5
  * the shape of tool call results from the official MCP SDK. It uses generic interfaces
@@ -12,12 +12,12 @@ import type { UiCollector } from "../core/collector/collector.js";
12
12
  /**
13
13
  * Minimal shape of an MCP SDK `CallToolResult`.
14
14
  *
15
- * This is a structural subset of `@modelcontextprotocol/sdk`'s `CallToolResult`.
15
+ * This is a structural subset of `@modelcontextprotocol/client`'s `CallToolResult`.
16
16
  * Any object matching this shape will be accepted — no need to import the SDK.
17
17
  *
18
18
  * @example
19
19
  * ```typescript
20
- * // This matches the shape of @modelcontextprotocol/sdk CallToolResult
20
+ * // This matches the shape of @modelcontextprotocol/client CallToolResult
21
21
  * const result: McpSdkCallToolResult = {
22
22
  * content: [{ type: "text", text: "OK" }],
23
23
  * _meta: { ui: { resourceUri: "ui://pg/table/1" } },
@@ -68,7 +68,7 @@ export interface McpSdkCollector {
68
68
  * Create an MCP SDK-aware collector.
69
69
  *
70
70
  * Wraps the core `UiCollector` with an interface that accepts
71
- * `@modelcontextprotocol/sdk` `CallToolResult` objects directly.
71
+ * `@modelcontextprotocol/client` `CallToolResult` objects directly.
72
72
  * Error results (`isError: true`) are automatically skipped.
73
73
  *
74
74
  * @returns A new `McpSdkCollector` instance
@@ -1,5 +1,5 @@
1
1
  /**
2
- * MCP SDK adapter — wraps the collector for use with `@modelcontextprotocol/sdk` tool call results.
2
+ * MCP SDK adapter — wraps the collector for use with `@modelcontextprotocol/client` tool call results.
3
3
  *
4
4
  * This adapter provides a convenience wrapper around the collector that accepts
5
5
  * the shape of tool call results from the official MCP SDK. It uses generic interfaces
@@ -12,7 +12,7 @@ import { createCollector } from "../core/collector/collector.js";
12
12
  * Create an MCP SDK-aware collector.
13
13
  *
14
14
  * Wraps the core `UiCollector` with an interface that accepts
15
- * `@modelcontextprotocol/sdk` `CallToolResult` objects directly.
15
+ * `@modelcontextprotocol/client` `CallToolResult` objects directly.
16
16
  * Error results (`isError: true`) are automatically skipped.
17
17
  *
18
18
  * @returns A new `McpSdkCollector` instance
@@ -17,7 +17,7 @@
17
17
  * @module lib/version
18
18
  */
19
19
  /** @mcpview/compose package version. */
20
- export declare const COMPOSE_VERSION: "0.10.0";
20
+ export declare const COMPOSE_VERSION: "0.12.0";
21
21
  /**
22
22
  * MCP Apps protocol version targeted by compose.
23
23
  *
@@ -17,7 +17,7 @@
17
17
  * @module lib/version
18
18
  */
19
19
  /** @mcpview/compose package version. */
20
- export const COMPOSE_VERSION = "0.10.0";
20
+ export const COMPOSE_VERSION = "0.12.0";
21
21
  /**
22
22
  * MCP Apps protocol version targeted by compose.
23
23
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcpview/compose",
3
- "version": "0.10.0",
3
+ "version": "0.12.0",
4
4
  "description": "Compose and synchronize multiple MCP Apps UIs into composite dashboards",
5
5
  "keywords": [
6
6
  "mcp",
@@ -31,6 +31,14 @@
31
31
  "import": "./esm/src/core/mod.js",
32
32
  "require": "./script/src/core/mod.js"
33
33
  },
34
+ "./code-mode": {
35
+ "import": "./esm/src/code-mode/mod.js",
36
+ "require": "./script/src/code-mode/mod.js"
37
+ },
38
+ "./code-mode/board": {
39
+ "import": "./esm/src/code-mode/board.js",
40
+ "require": "./script/src/code-mode/board.js"
41
+ },
34
42
  "./sdk": {
35
43
  "import": "./esm/src/sdk/mod.js",
36
44
  "require": "./script/src/sdk/mod.js"
@@ -48,9 +56,15 @@
48
56
  "require": "./script/src/deploy/mod.js"
49
57
  }
50
58
  },
59
+ "engines": {
60
+ "node": ">=20"
61
+ },
51
62
  "dependencies": {
52
- "@modelcontextprotocol/ext-apps": "^1.7.4",
53
- "@modelcontextprotocol/sdk": "^1.29.0"
63
+ "@mcpview/server": "^0.30.2",
64
+ "@modelcontextprotocol/client": "^2.3.1",
65
+ "@modelcontextprotocol/ext-apps": "^2.0.3",
66
+ "ajv": "^8.17.1",
67
+ "quickjs-emscripten": "0.32.0"
54
68
  },
55
69
  "_generatedBy": "dnt@dev",
56
70
  "types": "./esm/mod.d.ts"
@@ -1,9 +1,3 @@
1
- declare global {
2
- interface Error {
3
- cause?: unknown;
4
- }
5
- }
6
- export {};
7
1
  declare global {
8
2
  interface Object {
9
3
  /**
@@ -15,4 +9,10 @@ declare global {
15
9
  }
16
10
  }
17
11
  export {};
12
+ declare global {
13
+ interface Error {
14
+ cause?: unknown;
15
+ }
16
+ }
17
+ export {};
18
18
  //# 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":"AAeA,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"}
@@ -0,0 +1,62 @@
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
+ /** MCP App result metadata containing the receipts selected by the program. */
10
+ export declare const SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
11
+ /** A selected provider result. The receipt ID distinguishes calls to the same snippet. */
12
+ export interface SnippetPanel {
13
+ readonly id: string;
14
+ readonly provider: string;
15
+ readonly name: string;
16
+ readonly title: string;
17
+ readonly result: Record<string, unknown>;
18
+ }
19
+ /** An App-owned view for a receipt, with optional renderer data and component selection. */
20
+ export interface SnippetPanelView {
21
+ readonly resourceUri: string;
22
+ readonly context?: Record<string, unknown>;
23
+ readonly surface?: ComponentSurface;
24
+ }
25
+ /** Display options supplied by the board hosting the results. */
26
+ export interface SnippetBoardOptions {
27
+ /** A Compose layout or a function of the number of mounted panels. Defaults to stack. */
28
+ readonly layout?: UiLayout | ((count: number) => UiLayout);
29
+ /** Provide a local view adapter or return undefined to use the result's native MCP App URI. */
30
+ readonly resolveView?: (panel: SnippetPanel) => SnippetPanelView | undefined;
31
+ }
32
+ /**
33
+ * Return selected receipts in display order from the App-only MCP result metadata.
34
+ * Invalid entries and repeated receipt IDs are ignored. Distinct receipts can
35
+ * point to the same snippet and viewer.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * for (const panel of readSnippetPanels(toolResult)) {
40
+ * console.log(panel.provider, panel.name, panel.title);
41
+ * }
42
+ * ```
43
+ */
44
+ export declare function readSnippetPanels(result: unknown): SnippetPanel[];
45
+ /**
46
+ * Build a Compose descriptor from the current execution, without making any provider calls.
47
+ * Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
48
+ * The returned summary is shared as `sharedContext.value` when the execution has a value.
49
+ * A data-only receipt needs a local view adapter to produce a child.
50
+ *
51
+ * @example
52
+ * ```ts
53
+ * const board = composeSnippetBoard(toolResult, {
54
+ * layout: "split",
55
+ * resolveView: (panel) => panel.provider === "metrics"
56
+ * ? { resourceUri: "ui://my-board/metrics" }
57
+ * : undefined,
58
+ * });
59
+ * ```
60
+ */
61
+ export declare function composeSnippetBoard(result: unknown, options?: SnippetBoardOptions): CompositeUiDescriptor;
62
+ //# 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,+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;CACrC;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,91 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SNIPPET_PANELS_META_KEY = void 0;
4
+ exports.readSnippetPanels = readSnippetPanels;
5
+ exports.composeSnippetBoard = composeSnippetBoard;
6
+ /**
7
+ * Browser-side composition of completed Code Mode results.
8
+ * @module
9
+ */
10
+ require("../../_dnt.polyfills.js");
11
+ const collector_js_1 = require("../core/collector/collector.js");
12
+ const extractor_js_1 = require("../core/collector/extractor.js");
13
+ const composer_js_1 = require("../core/composer/composer.js");
14
+ /** MCP App result metadata containing the receipts selected by the program. */
15
+ exports.SNIPPET_PANELS_META_KEY = "io.mcpview/snippet-panels";
16
+ function record(value) {
17
+ return value !== null && typeof value === "object" && !Array.isArray(value);
18
+ }
19
+ function isPanel(value) {
20
+ return record(value) &&
21
+ typeof value.id === "string" && value.id.length > 0 &&
22
+ typeof value.provider === "string" && value.provider.length > 0 &&
23
+ typeof value.name === "string" && value.name.length > 0 &&
24
+ typeof value.title === "string" && record(value.result);
25
+ }
26
+ /**
27
+ * Return selected receipts in display order from the App-only MCP result metadata.
28
+ * Invalid entries and repeated receipt IDs are ignored. Distinct receipts can
29
+ * point to the same snippet and viewer.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * for (const panel of readSnippetPanels(toolResult)) {
34
+ * console.log(panel.provider, panel.name, panel.title);
35
+ * }
36
+ * ```
37
+ */
38
+ function readSnippetPanels(result) {
39
+ if (!record(result) || !record(result._meta))
40
+ return [];
41
+ const items = result._meta[exports.SNIPPET_PANELS_META_KEY];
42
+ if (!Array.isArray(items))
43
+ return [];
44
+ const seen = new Set();
45
+ const panels = [];
46
+ for (const item of items) {
47
+ if (isPanel(item) && !seen.has(item.id)) {
48
+ panels.push(item);
49
+ seen.add(item.id);
50
+ }
51
+ }
52
+ return panels;
53
+ }
54
+ /**
55
+ * Build a Compose descriptor from the current execution, without making any provider calls.
56
+ * Each child keeps its receipt in `context.panel` and adapter data in `context.view`.
57
+ * The returned summary is shared as `sharedContext.value` when the execution has a value.
58
+ * A data-only receipt needs a local view adapter to produce a child.
59
+ *
60
+ * @example
61
+ * ```ts
62
+ * const board = composeSnippetBoard(toolResult, {
63
+ * layout: "split",
64
+ * resolveView: (panel) => panel.provider === "metrics"
65
+ * ? { resourceUri: "ui://my-board/metrics" }
66
+ * : undefined,
67
+ * });
68
+ * ```
69
+ */
70
+ function composeSnippetBoard(result, options = {}) {
71
+ const summary = record(result) && record(result.structuredContent)
72
+ ? result.structuredContent
73
+ : {};
74
+ const collector = (0, collector_js_1.createCollector)();
75
+ for (const panel of readSnippetPanels(result)) {
76
+ const view = options.resolveView?.(panel);
77
+ const resourceUri = view?.resourceUri ?? (0, extractor_js_1.extractUiMeta)(panel.result)?.resourceUri;
78
+ if (!resourceUri || !/^ui:\/\/[^\s]+$/.test(resourceUri))
79
+ continue;
80
+ collector.collect(`${panel.provider}:${panel.name}`, { _meta: { ui: { resourceUri } } }, {
81
+ panel,
82
+ ...(view?.context === undefined ? {} : { view: view.context }),
83
+ ...(Object.hasOwn(summary, "value") ? { value: summary.value } : {}),
84
+ }, { componentId: panel.id, surface: view?.surface });
85
+ }
86
+ const resources = collector.getResources();
87
+ const layout = typeof options.layout === "function"
88
+ ? options.layout(resources.length)
89
+ : options.layout;
90
+ return (0, composer_js_1.buildCompositeUi)(resources, { layout: layout ?? "stack", sharedContext: ["value"] });
91
+ }
@@ -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"}