@mcpview/components 0.0.0-stage → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +575 -2
  3. package/esm/_dnt.polyfills.d.ts +12 -0
  4. package/esm/_dnt.polyfills.d.ts.map +1 -0
  5. package/esm/_dnt.polyfills.js +15 -0
  6. package/esm/fonts.d.ts +13 -0
  7. package/esm/fonts.d.ts.map +1 -0
  8. package/esm/fonts.js +12 -0
  9. package/esm/layout.d.ts +14 -0
  10. package/esm/layout.d.ts.map +1 -0
  11. package/esm/layout.js +13 -0
  12. package/esm/mod.d.ts +19 -0
  13. package/esm/mod.d.ts.map +1 -0
  14. package/esm/mod.js +14 -0
  15. package/esm/package.json +3 -0
  16. package/esm/preact-components.d.ts +22 -0
  17. package/esm/preact-components.d.ts.map +1 -0
  18. package/esm/preact-components.js +20 -0
  19. package/esm/preact.d.ts +10 -0
  20. package/esm/preact.d.ts.map +1 -0
  21. package/esm/preact.js +9 -0
  22. package/esm/src/component-primitives.d.ts +41 -0
  23. package/esm/src/component-primitives.d.ts.map +1 -0
  24. package/esm/src/component-primitives.js +121 -0
  25. package/esm/src/components.d.ts +50 -0
  26. package/esm/src/components.d.ts.map +1 -0
  27. package/esm/src/components.js +283 -0
  28. package/esm/src/font-families.d.ts +16 -0
  29. package/esm/src/font-families.d.ts.map +1 -0
  30. package/esm/src/font-families.js +11 -0
  31. package/esm/src/fonts-data.d.ts +2 -0
  32. package/esm/src/fonts-data.d.ts.map +1 -0
  33. package/esm/src/fonts-data.js +42 -0
  34. package/esm/src/fonts.d.ts +12 -0
  35. package/esm/src/fonts.d.ts.map +1 -0
  36. package/esm/src/fonts.js +19 -0
  37. package/esm/src/i18n.d.ts +44 -0
  38. package/esm/src/i18n.d.ts.map +1 -0
  39. package/esm/src/i18n.js +98 -0
  40. package/esm/src/layout/hooks.d.ts +60 -0
  41. package/esm/src/layout/hooks.d.ts.map +1 -0
  42. package/esm/src/layout/hooks.js +121 -0
  43. package/esm/src/layout/mod.d.ts +6 -0
  44. package/esm/src/layout/mod.d.ts.map +1 -0
  45. package/esm/src/layout/mod.js +3 -0
  46. package/esm/src/layout/viewer-layout.d.ts +82 -0
  47. package/esm/src/layout/viewer-layout.d.ts.map +1 -0
  48. package/esm/src/layout/viewer-layout.js +74 -0
  49. package/esm/src/preact/components.d.ts +215 -0
  50. package/esm/src/preact/components.d.ts.map +1 -0
  51. package/esm/src/preact/components.js +176 -0
  52. package/esm/src/preact/focused-view.d.ts +42 -0
  53. package/esm/src/preact/focused-view.d.ts.map +1 -0
  54. package/esm/src/preact/focused-view.js +20 -0
  55. package/esm/src/preact/mod.d.ts +6 -0
  56. package/esm/src/preact/mod.d.ts.map +1 -0
  57. package/esm/src/preact/mod.js +3 -0
  58. package/esm/src/preact/plots.d.ts +119 -0
  59. package/esm/src/preact/plots.d.ts.map +1 -0
  60. package/esm/src/preact/plots.js +152 -0
  61. package/esm/src/preact/semantic-element.d.ts +103 -0
  62. package/esm/src/preact/semantic-element.d.ts.map +1 -0
  63. package/esm/src/preact/semantic-element.js +103 -0
  64. package/esm/src/preact/structural.d.ts +178 -0
  65. package/esm/src/preact/structural.d.ts.map +1 -0
  66. package/esm/src/preact/structural.js +147 -0
  67. package/esm/src/preact/surface.d.ts +37 -0
  68. package/esm/src/preact/surface.d.ts.map +1 -0
  69. package/esm/src/preact/surface.js +47 -0
  70. package/esm/src/surface-app.d.ts +188 -0
  71. package/esm/src/surface-app.d.ts.map +1 -0
  72. package/esm/src/surface-app.js +374 -0
  73. package/esm/src/theme.d.ts +65 -0
  74. package/esm/src/theme.d.ts.map +1 -0
  75. package/esm/src/theme.js +1877 -0
  76. package/esm/surface.d.ts +12 -0
  77. package/esm/surface.d.ts.map +1 -0
  78. package/esm/surface.js +10 -0
  79. package/package.json +68 -4
  80. package/script/_dnt.polyfills.d.ts +12 -0
  81. package/script/_dnt.polyfills.d.ts.map +1 -0
  82. package/script/_dnt.polyfills.js +16 -0
  83. package/script/fonts.d.ts +13 -0
  84. package/script/fonts.d.ts.map +1 -0
  85. package/script/fonts.js +19 -0
  86. package/script/layout.d.ts +14 -0
  87. package/script/layout.d.ts.map +1 -0
  88. package/script/layout.js +29 -0
  89. package/script/mod.d.ts +19 -0
  90. package/script/mod.d.ts.map +1 -0
  91. package/script/mod.js +40 -0
  92. package/script/package.json +3 -0
  93. package/script/preact-components.d.ts +22 -0
  94. package/script/preact-components.d.ts.map +1 -0
  95. package/script/preact-components.js +68 -0
  96. package/script/preact.d.ts +10 -0
  97. package/script/preact.d.ts.map +1 -0
  98. package/script/preact.js +25 -0
  99. package/script/src/component-primitives.d.ts +41 -0
  100. package/script/src/component-primitives.d.ts.map +1 -0
  101. package/script/src/component-primitives.js +127 -0
  102. package/script/src/components.d.ts +50 -0
  103. package/script/src/components.d.ts.map +1 -0
  104. package/script/src/components.js +297 -0
  105. package/script/src/font-families.d.ts +16 -0
  106. package/script/src/font-families.d.ts.map +1 -0
  107. package/script/src/font-families.js +14 -0
  108. package/script/src/fonts-data.d.ts +2 -0
  109. package/script/src/fonts-data.d.ts.map +1 -0
  110. package/script/src/fonts-data.js +45 -0
  111. package/script/src/fonts.d.ts +12 -0
  112. package/script/src/fonts.d.ts.map +1 -0
  113. package/script/src/fonts.js +24 -0
  114. package/script/src/i18n.d.ts +44 -0
  115. package/script/src/i18n.d.ts.map +1 -0
  116. package/script/src/i18n.js +102 -0
  117. package/script/src/layout/hooks.d.ts +60 -0
  118. package/script/src/layout/hooks.d.ts.map +1 -0
  119. package/script/src/layout/hooks.js +126 -0
  120. package/script/src/layout/mod.d.ts +6 -0
  121. package/script/src/layout/mod.d.ts.map +1 -0
  122. package/script/src/layout/mod.js +17 -0
  123. package/script/src/layout/viewer-layout.d.ts +82 -0
  124. package/script/src/layout/viewer-layout.d.ts.map +1 -0
  125. package/script/src/layout/viewer-layout.js +83 -0
  126. package/script/src/preact/components.d.ts +215 -0
  127. package/script/src/preact/components.d.ts.map +1 -0
  128. package/script/src/preact/components.js +199 -0
  129. package/script/src/preact/focused-view.d.ts +42 -0
  130. package/script/src/preact/focused-view.d.ts.map +1 -0
  131. package/script/src/preact/focused-view.js +24 -0
  132. package/script/src/preact/mod.d.ts +6 -0
  133. package/script/src/preact/mod.d.ts.map +1 -0
  134. package/script/src/preact/mod.js +55 -0
  135. package/script/src/preact/plots.d.ts +119 -0
  136. package/script/src/preact/plots.d.ts.map +1 -0
  137. package/script/src/preact/plots.js +157 -0
  138. package/script/src/preact/semantic-element.d.ts +103 -0
  139. package/script/src/preact/semantic-element.d.ts.map +1 -0
  140. package/script/src/preact/semantic-element.js +115 -0
  141. package/script/src/preact/structural.d.ts +178 -0
  142. package/script/src/preact/structural.d.ts.map +1 -0
  143. package/script/src/preact/structural.js +158 -0
  144. package/script/src/preact/surface.d.ts +37 -0
  145. package/script/src/preact/surface.d.ts.map +1 -0
  146. package/script/src/preact/surface.js +53 -0
  147. package/script/src/surface-app.d.ts +188 -0
  148. package/script/src/surface-app.d.ts.map +1 -0
  149. package/script/src/surface-app.js +379 -0
  150. package/script/src/theme.d.ts +65 -0
  151. package/script/src/theme.d.ts.map +1 -0
  152. package/script/src/theme.js +1881 -0
  153. package/script/surface.d.ts +12 -0
  154. package/script/surface.d.ts.map +1 -0
  155. package/script/surface.js +15 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Casys AI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,576 @@
1
- # Temporary Holding Version
1
+ # @mcpview/components
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Optional presentation runtime and light-first component kit for MCP Apps. It gives provider-owned
4
+ viewers a shared visual grammar without moving their data, semantics, or rendering authority into
5
+ the host.
6
+
7
+ The intended unit is a small recorded view: one run, artifact, requirement, metric, or other bounded
8
+ object. A provider may export several whole-view resources; it should not turn one viewer into a
9
+ dashboard that contains every provider capability. In a composed host such as the Digital Thread
10
+ Whiteboard, `chip`, `row`, and `card` densities project the same semantic object while the
11
+ whole-view App remains the exact viewer opened for that object.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ # Deno (JSR)
17
+ deno add jsr:@mcpview/components
18
+
19
+ # Node (npm)
20
+ npm i @mcpview/components
21
+ ```
22
+
23
+ ## Package boundary
24
+
25
+ - `@mcpview/contracts` is dependency-free and owns serializable contracts.
26
+ - `@mcpview/view` owns the MCP App lifecycle and transport.
27
+ - `@mcpview/components` is optional. Apps that do not want the kit do not import it.
28
+ - Providers resolve references and validate values, units, limits, verdicts, and provenance. The
29
+ components display those values and never infer them.
30
+ - The host composes and opens recorded views. It does not become a native CAD, Modelica, FEA, or
31
+ SysML renderer.
32
+
33
+ The package root is renderer-neutral and carries no MCP Apps runtime: `@mcpview/view` and
34
+ `@modelcontextprotocol/ext-apps` are reached only through the `/surface` entry, which owns the App
35
+ lifecycle. The responsive layout decision and its hooks live in the `/layout` entry, which takes the
36
+ host context as a value and loads no App runtime. The embedded webfonts are reached only through the
37
+ `/fonts` entry. Preact is an optional peer and is loaded only through the Preact subpaths and
38
+ `/layout`, whose hooks are Preact:
39
+
40
+ ```ts
41
+ import { defineComponentRegistry, installMcpViewTheme } from "@mcpview/components";
42
+ import {
43
+ ArtifactRow,
44
+ BadgeGroup,
45
+ Card,
46
+ CodeBlock,
47
+ CollectionCard,
48
+ DrillHint,
49
+ ElementBody,
50
+ ElementIdent,
51
+ ElementLimit,
52
+ ElementProvenance,
53
+ ElementReading,
54
+ InlineCode,
55
+ IntervalPlot,
56
+ LimitGauge,
57
+ NoticeGroup,
58
+ PathBar,
59
+ renderStatusMessage,
60
+ Row,
61
+ SemanticElement,
62
+ SemanticList,
63
+ SeriesChart,
64
+ Skeleton,
65
+ Slot3D,
66
+ Sparkline,
67
+ StaleBanner,
68
+ TextInput,
69
+ TreeList,
70
+ TypeBadge,
71
+ } from "@mcpview/components/preact";
72
+ ```
73
+
74
+ ## Presentation vocabulary
75
+
76
+ Primitives:
77
+
78
+ - `Card`, `Badge`, `BadgeGroup`, `Button`, `Toolbar`, `Stack`, `Row`, `TextInput`, `InlineCode`,
79
+ `CodeBlock`, `Skeleton`
80
+ - `Metric`, `MetricGrid`, `KeyValueList`, `DataTable`
81
+ - `Message`, `StateMessage`, `EmptyState`, `CrossSelection`, `NoticeGroup`
82
+
83
+ Reusable structures:
84
+
85
+ - `PathBar` for local navigation inside one bounded view; a path of one item renders nothing. New
86
+ optional props: `maxVisible` (inline capacity before leading items collapse; default three),
87
+ `collapsedLabel` (accessible name of the collapsed disclosure), `backLabel` (leading step-out
88
+ control), and `PathBarItem.detail` (recorded state of a kept level, revealed in the collapsed
89
+ disclosure).
90
+ - `LimitGauge` for caller-supplied readings, bounds, labels, and tone
91
+ - `ArtifactRow` for immutable artifact identity and literal verification status
92
+ - `DrillHint` for one available drill-down, in direction `"in-view"` or `"to-model"`. Without a
93
+ callback the hint degrades to plain text so a host that cannot follow it never advertises a step
94
+ that does not exist.
95
+ - `TypeBadge` names what kind of view one level is (`"list"`, `"chart"`, or `"record"`); the caller
96
+ supplies all wording.
97
+ - `StaleBanner` marks surrounding values as recorded earlier without hiding or replacing them. Tone
98
+ defaults to `"warning"`; `"danger"` promotes the ARIA role to `alert`.
99
+ - `Slot3D` reserves a bounded area for a provider-owned renderer; without `children` the slot stays
100
+ visibly reserved. The kit renders no geometry.
101
+ - `TreeList` for a controlled hierarchy with caller-owned type wording and coverage labels;
102
+ expansion and selection state are fully caller-managed.
103
+
104
+ Numeric evidence:
105
+
106
+ - `Sparkline` for the compact shape of one recorded series, readable at chip and row density.
107
+ Requires at least two finite samples already ordered by the caller.
108
+ - `SeriesChart` for a multi-series plot on a shared finite scale. Each series requires a `mark`
109
+ field (`"line"` or `"bar"`): `"line"` connects samples with a polyline — an assertion that the
110
+ quantity existed between them; `"bar"` draws each recorded sample as an isolated mark and claims
111
+ nothing about the interval. The optional `onScrub` callback reports the pointer position on the
112
+ shared x scale (`undefined` when the pointer leaves); a series with no recorded point at that
113
+ position is absent from the readout rather than filled. The kit never interpolates, aligns to a
114
+ nearest neighbour, draws a continuity it has not measured, or invents a value — the provider
115
+ declares both the mark shape and which sample a position corresponds to.
116
+ - `IntervalPlot` for caller-declared deviation intervals laid out against a shared zero line. The
117
+ scale must contain zero; every bound and label is caller-supplied.
118
+
119
+ Semantic composition:
120
+
121
+ - `SemanticElement` with `chip | row | card` density and kit-owned explicit selection
122
+ - `SemanticList` for a bounded, optionally scrollable group of row-density semantic objects
123
+ - `CollectionCard` composing `Card` and `SemanticList` into one outer-border collection
124
+ - required `ElementIdent`
125
+ - optional `ElementReading` or caller-declared `ElementLimit`, plus `ElementBody`, `ElementVerdict`,
126
+ and `ElementProvenance`
127
+ - `ElementSection` for one titled group inside the body
128
+
129
+ `viewer` is deliberately not a `SemanticElement` density. It is the provider's whole-view App,
130
+ usually composed from one `card` plus an optional `PathBar`.
131
+
132
+ ```tsx
133
+ <SemanticElement
134
+ reference={{ domain: "cad", kind: "artifact", id: "bracket.step" }}
135
+ density="card"
136
+ tone="warning"
137
+ ident={<ElementIdent marker="STEP" label="Bracket" detail="revision 4" />}
138
+ reading={<ElementReading label="Minimum thickness" value="0.84" unit="mm" />}
139
+ provenance={<ElementProvenance label="SHA-256" value={digest} />}
140
+ />;
141
+ ```
142
+
143
+ The semantic reference is structured but never dereferenced by the component. Likewise, `LimitGauge`
144
+ never derives whether a value passes a limit, and `ArtifactRow` never claims a digest was verified
145
+ unless the caller supplies that recorded status.
146
+
147
+ Use `ElementLimit` when the record contains only an authored bound. It displays the supplied
148
+ operator, value, and unit without inventing a measurement, range, satisfaction state, or verdict.
149
+
150
+ ## System states
151
+
152
+ Three components express a view's readiness without hiding or fabricating content.
153
+
154
+ `Skeleton` is a frame-first loading placeholder: it draws the structure before values arrive so
155
+ layout does not shift on load. The caller supplies an accessible label and an optional line count
156
+ (default three).
157
+
158
+ `StaleBanner` keeps dated values visible while flagging that the snapshot is not current. The caller
159
+ formats the message, including the recorded instant. The banner never refetches or replaces a value
160
+ with a gap.
161
+
162
+ `DrillHint` without a callback degrades to plain text. A host that cannot follow a drill-down step
163
+ omits `onActivate`; the hint stays visible but renders no affordance. Providers declare every
164
+ available next step without advertising actions the host cannot execute.
165
+
166
+ `NoticeGroup` gathers short notices under a single severity heading. It renders nothing when there
167
+ are no items and no `omittedLabel`, so the caller never has to guard the call site. Truncation is
168
+ stated by the caller via `omittedLabel`: the group displays only the items it was handed and never
169
+ counts what it was not given.
170
+
171
+ ## Imperative bridge
172
+
173
+ `renderStatusMessage(detail, options?)` renders a `StateMessage` into a real DOM node and returns
174
+ it. `defineView` must return a native element, so every viewer built on it previously wrote its own
175
+ Preact-to-DOM bridge; those bridges drifted in tone, ARIA role, and class. `renderStatusMessage` is
176
+ that bridge, made canonical. Without `container` it returns the rendered `.mcp-view-state` element,
177
+ so what you mount carries the class, the tone and the alert role; `className` lands on that same
178
+ node. Pass `container` to render into a node you already own, which is then what comes back. It
179
+ lives in the pure presentation module `@mcpview/components/preact/components` and does not import
180
+ `@mcpview/view`, so it is reachable from any entry that does not need the surface lifecycle.
181
+
182
+ Without `container` it returns the rendered `.mcp-view-state` element; with one it renders into the
183
+ node you passed and returns that.
184
+
185
+ ## Viewer layout
186
+
187
+ `useViewerLayout(hints, options?)` (`/layout` entry) decides one of three treatments for one viewer
188
+ root — `"wide" | "panel" | "mobile"` — from the host's word first, the browser's measure as fallback
189
+ and an explicit override on top. The three treatments are two contexts under one breakpoint
190
+ (`NARROW_BREAKPOINT`, 480px), not a width scale: under it, a finger without hover picks `mobile`,
191
+ anything else `panel`; a tablet under a finger but with room keeps `wide`. The hook measures the
192
+ element you attach `ref` to, not the window, because an iframe's width says nothing about the
193
+ screen's; the host's declared `containerDimensions.width` (then `maxWidth`) outranks that measure
194
+ because it describes the room actually granted. `boundsStyle` bounds the root on the host's declared
195
+ `height` (else `maxHeight`) instead of `100vh`, and is `undefined` when the host declares none so
196
+ the viewer stays intrinsic and lets the host auto-resize.
197
+
198
+ ```tsx
199
+ import { useViewerLayout } from "@mcpview/components/layout";
200
+
201
+ const Viewer = ({ data, context }: PreactSurfaceComponentProps<RunModel>) => {
202
+ const { ref, layout, boundsStyle } = useViewerLayout<HTMLDivElement>(context.hostContext);
203
+ return (
204
+ <div ref={ref} data-layout={layout} style={boundsStyle}>
205
+ {layout === "wide"
206
+ ? <RunTable data={data} />
207
+ : <RunRows data={data} touch={layout === "mobile"} />}
208
+ </div>
209
+ );
210
+ };
211
+ ```
212
+
213
+ `hints` is any `{ deviceCapabilities?, containerDimensions? }` — the kit's `McpViewHostContext`
214
+ satisfies it structurally, so the entry never imports `@mcpview/view`. Touch follows the host's
215
+ `deviceCapabilities` (`touch && hover !== true`: a touch-screen laptop driven by a mouse is no
216
+ phone) and only falls back to `matchMedia("(pointer: coarse)")` when the host says nothing.
217
+ `?layout=mobile` in the page query string forces a treatment for reviewing it without the matching
218
+ device; pass `{ forced: null }` to ignore the URL, or `{ forced: "panel" }` to pin one. The decision
219
+ itself — `resolveViewerLayout`, `layoutWidth`, `touchInput`, `layoutFromSearch`, `viewerBoundsStyle`
220
+ — is exported pure, and the two measuring hooks, `useContainerWidth()` and `useCoarsePointer()`, are
221
+ exported on their own.
222
+
223
+ ## Focused viewers and technical details
224
+
225
+ `FocusedView` keeps one primary visualization or reading prominent and puts optional technical
226
+ metadata behind a closed `Disclosure`. Its `status` slot stays outside that disclosure: warnings,
227
+ unavailable evidence and literal verification state remain visible. The existing surface supplies
228
+ the frame, so the preset adds no card, shadow or application chrome.
229
+
230
+ ```tsx
231
+ import { FocusedView } from "@mcpview/components/preact/components";
232
+
233
+ <FocusedView
234
+ label={labels.geometry}
235
+ hostContext={context.hostContext}
236
+ status={<StateMessage title={recorded.status}>{recorded.message}</StateMessage>}
237
+ primary={<GeometryCanvas geometry={recorded.geometry} />}
238
+ detailsLabel={labels.technicalDetails}
239
+ details={<KeyValueList layout="facts" items={recorded.provenance} />}
240
+ />;
241
+ ```
242
+
243
+ The preset calls `useViewerLayout` with the host hints and applies its container ref, `data-layout`
244
+ and height bounds. At a narrow desktop width it uses `panel`; under a finger it uses `mobile` with a
245
+ larger disclosure target. Pass `layout` only to review a forced treatment. The primary remains
246
+ provider-owned; the preset never invents a preview, a status or an evidence value.
247
+
248
+ Use `Disclosure` on its own for an inline technical section: `label` is supplied by the caller,
249
+ `children` hold the detail, and optional `open` / `onToggle(open)` expose its native state. Native
250
+ `details` / `summary` provide keyboard behavior and expanded state. Omit `open` to start closed.
251
+ `FocusedView` requires a `detailsLabel` whenever it receives `details`; omit both to render no
252
+ technical control. Keep consequential state in `status` or `primary`.
253
+
254
+ ## Theme
255
+
256
+ `installMcpViewTheme()` installs the shared CSS once. The defaults are light-first and include an
257
+ explicit dark mapping (`:root[data-theme="dark"]`, or `prefers-color-scheme` unless the host pins
258
+ `data-theme="light"`). The surface is the one frame a viewer shows — border, radius, panel and a 2px
259
+ accent→brand rule — and its stacked components are separated by hairlines, so a `stack` surface
260
+ defaults to `gap: "none"`. Inside, values sit in hairline cells rather than filled tiles.
261
+
262
+ Typography has three roles: the heading face for titles and large values, the body face for prose,
263
+ and the mono face for labels, keys, units, markers, verdicts, provenance and identifiers. Sizes come
264
+ from a px scale (`--mcp-view-size-micro` 10px … `--mcp-view-size-metric` 22px) so a host that
265
+ rescales `rem` cannot squash the datasheet. The preferred faces mirror the v2 reference
266
+ (`Space Grotesk`, `Work Sans`, `JetBrains Mono`) and fall back to native families; the theme itself
267
+ neither embeds fonts nor makes a network font request. Apps can override the stable variables
268
+ exported as `MCP_VIEW_THEME_TOKENS`:
269
+
270
+ ```css
271
+ :root {
272
+ --mcp-view-accent: #0d7c8a;
273
+ --mcp-view-brand: #8a4fa3;
274
+ --mcp-view-font-heading: "Space Grotesk", "Avenir Next", sans-serif;
275
+ --mcp-view-font-body: "Work Sans", Avenir, sans-serif;
276
+ --mcp-view-font-mono: "JetBrains Mono", "SFMono-Regular", monospace;
277
+ --mcp-view-radius: 8px;
278
+ }
279
+ ```
280
+
281
+ ### Embedded fonts
282
+
283
+ A viewer bundled into one HTML file and opened inside a host iframe usually has neither network
284
+ access nor a CSP that allows font requests, so the preferred faces would silently fall back. The
285
+ `/fonts` entry embeds them (three variable faces, latin subset, ~137 KB of base64 woff2, SIL Open
286
+ Font License 1.1). It is opt-in: import it only from the viewer bundle that wants it.
287
+
288
+ ```ts
289
+ import { installMcpViewTheme } from "@mcpview/components";
290
+ import { installMcpViewFonts } from "@mcpview/components/fonts";
291
+
292
+ installMcpViewFonts();
293
+ installMcpViewTheme();
294
+ ```
295
+
296
+ `MCP_VIEW_FONT_FAMILIES` lists the families, their weight range and the theme role each serves. The
297
+ payload lives in `src/fonts-data.ts`, generated by `deno task fonts:fetch` and drift-checked by
298
+ `deno task fonts:check`.
299
+
300
+ ## Surface App
301
+
302
+ `startSurfaceApp()` (`/surface` entry) runs the whole result-driven App lifecycle for a component
303
+ registry: it opens on a loading status, projects every tool result into one `SurfaceDisplayState`,
304
+ mounts the host-selected surface (or the registry default), remounts it when the host context
305
+ changes, guards overtaken mounts, and converts every failure into a status instead of a blank page.
306
+ A viewer supplies its registry, the projection and how a status is rendered; everything else —
307
+ `strict`, `theme`, the status labels, `onError`, `viewerSession` — has a documented default.
308
+
309
+ ```ts
310
+ import { createTranslator } from "@mcpview/components";
311
+ import { startSurfaceApp } from "@mcpview/components/surface";
312
+
313
+ const messages = createTranslator({
314
+ defaultLocale: "en",
315
+ messages: {
316
+ solvingTitle: "Solving",
317
+ solvingMessage: "The run is still open.",
318
+ },
319
+ translations: {
320
+ fr: {
321
+ solvingTitle: "Résolution",
322
+ solvingMessage: "L’exécution est encore ouverte.",
323
+ },
324
+ },
325
+ });
326
+
327
+ const app = await startSurfaceApp<RunModel>({
328
+ root,
329
+ info: { name: "Run viewer", version: "1.0.0" },
330
+ registry,
331
+ strict: true,
332
+ documentLanguage: messages.locale,
333
+ fromToolResult: async (result, host) => {
334
+ if (result.isError) return { kind: "error", message: toolErrorMessage(result) };
335
+ const model = parseRun(result.structuredContent);
336
+ if (!model) return { kind: "empty" };
337
+ if (model.pending) {
338
+ return {
339
+ kind: "notice",
340
+ title: (locale) => messages(locale)("solvingTitle"),
341
+ message: (locale) => messages(locale)("solvingMessage"),
342
+ busy: true,
343
+ };
344
+ }
345
+ return { kind: "result", result: model };
346
+ },
347
+ renderStatus: (status) => renderMyStatus(status),
348
+ });
349
+ ```
350
+
351
+ The projection may return a promise and may read server resources through `host.readServerResource`.
352
+ Without a projection, `validate` (a type guard) is applied to `structuredContent` with a JSON-text
353
+ fallback; passing both is refused with `SURFACE_APP_PROJECTION_CONFLICT`.
354
+
355
+ Every non-result state reaches `renderStatus` as one `SurfaceStatus` — `kind`, `message`, `title?`,
356
+ `tone`, `busy` and the caller's optional `code`:
357
+
358
+ | `kind` | When | `tone` | `busy` |
359
+ | ------------------ | ------------------------------------------------ | --------- | ------- |
360
+ | `loading` | before the first result, and on tool input | `info` | `true` |
361
+ | `empty` | `{ kind: "empty" }` or a rejected `validate` | `neutral` | `false` |
362
+ | `error` | `{ kind: "error" }`, a rejected session | `danger` | `false` |
363
+ | `notice` | `{ kind: "notice" }`, defaults `neutral`/`false` | given | given |
364
+ | `surface-required` | component-only registry without a host selection | `warning` | `false` |
365
+
366
+ `code` is passed through from a `notice` or `error` state and never invented, so a viewer can key
367
+ its own recovery hints on it. A projection that throws becomes a `Result rejected` error status and
368
+ wipes the previous result; to keep the last good values under the failure, return a `result` that
369
+ carries it — the scaffold does exactly that. A mount that fails or a malformed host selection stays
370
+ on the surface route as `Surface failed` or `Surface invalid`, so a corrected selection can recover
371
+ in place. All three are reported to `onError` (default `console.error`) and the App keeps running.
372
+
373
+ `surfaceFor(data)` lets a result own its composition: a returned surface is mounted as is, with
374
+ neither the host selection nor the registry default consulted, so a recorded session that replaces
375
+ the whole read model composes itself while live results keep following the host. `undefined` keeps
376
+ the host flow. It is asked on every mount of that result, remounts included; a malformed owned
377
+ surface stays on the route as `Surface invalid` and names its owner. `onTeardown` runs once when the
378
+ host tears the App down or `dispose()` runs, before the surface is disposed — the place to close
379
+ what the App holds outside its surface, such as a bridge to the parent page. Its throw goes to
380
+ `onError`.
381
+
382
+ The projection and the session subscription are registered before the App connects, so nothing the
383
+ host sends during the handshake is lost. The host context is re-applied on every
384
+ `hostcontextchanged`, including the notifications the runtime replays from the handshake; the
385
+ surface is remounted only while the surface route holds a result (a surface-route failure included)
386
+ and the context object actually moved — never while a status is shown or a transition is in flight.
387
+ `theme: false` skips the theme install at boot only — primitives still install it when they mount.
388
+
389
+ For a renderer that already follows the CSS theme tokens, `themeUpdates: "in-place"` keeps that
390
+ renderer mounted when only the host theme changes. This preserves local camera or interaction state.
391
+ Hosts that resend a complete JSON snapshot with new object identities but the same non-theme values
392
+ do not remount: comparison is structural (object key order ignored, array order kept). The default
393
+ remains `"remount"`; do not opt in if a component reads theme colors only at mount. Locale,
394
+ dimensions, styles, component selection and other value changes still remount normally in either
395
+ mode.
396
+
397
+ Generic loading, empty and failure headings follow the host locale, including `Result rejected` and
398
+ `Session rejected` after a locale change while that status is visible. `loadingLabel`, `emptyLabel`
399
+ and `surfaceRequiredLabel` also accept `(locale) => string`. `error` and `notice` `title`/`message`
400
+ accept the same `SurfaceLabel` callbacks, resolved on each visible status render so a provider
401
+ dictionary can follow the host locale without re-running `fromToolResult`, session projection or
402
+ resource reads. Literal titles, messages and `code` stay unchanged.
403
+ `documentLanguage: messages.locale` sets `document.documentElement.lang` to the selected dictionary
404
+ at boot and on locale changes; omit it to leave the document language untouched. The `messages`
405
+ option accepts a `createTranslator` catalog for additional languages. Domain values, contract
406
+ states, raw provider messages, codes, identifiers, numbers and units remain literal. Tool-result and
407
+ session projections receive `host.locale` for interface wording, never for interpreting or
408
+ validating domain values.
409
+
410
+ `startPreactSurfaceApp()` (`/preact`) is the same App with statuses rendered through
411
+ `renderStatusMessage`, plus `statusClassName` for viewer-owned styling hooks; its shell keeps the
412
+ `mcp-view-preact-surface` class 0.5 viewers style (the core default is `mcp-view-surface-shell`).
413
+ Both return a `SurfaceAppHandle` whose `show(state)` drives the App from outside the MCP lifecycle
414
+ and whose `dispose()` tears it down. Option conflicts throw `SurfaceAppError`, a `TypeError` with a
415
+ stable `code` (`SURFACE_APP_PROJECTION_CONFLICT`) and a `data.recovery` sentence; `show()` on a
416
+ handle the host already tore down rejects with `SURFACE_APP_CLOSED`.
417
+
418
+ Whole-view recorded sessions are declared in `@mcpview/contracts` and consumed through the core
419
+ resource lifecycle. `viewerSession` pairs a `validate` guard with a `toState` projection; the App
420
+ subscribes before it connects and the runtime buffers what arrives during the handshake, so a
421
+ one-shot session cannot be lost and no individual component claims `viewer.session.apply`. The 0.6
422
+ `validateSession`/`mapSessionToData`/`onInvalidSession` options of `startPreactSurfaceApp()` are
423
+ gone in 0.7.0; `viewerSession: { validate, toState, onInvalid }` is the one form.
424
+
425
+ ## Common compositions
426
+
427
+ The kit stays small and non-prescriptive, leaving assembly to the caller. When multiple viewers
428
+ build the same assembly from the same primitives, this section is what they should have found first.
429
+
430
+ ### Named quantity section
431
+
432
+ `Card` + `MetricGrid` carries one named group of measurements. Repeat the pattern for each domain
433
+ region; `EmptyState` handles the no-data case without shifting layout.
434
+
435
+ ```tsx
436
+ <Card title="Load margins">
437
+ {items.length === 0 ? <EmptyState>No values recorded.</EmptyState> : <MetricGrid items={items} />}
438
+ </Card>;
439
+ ```
440
+
441
+ ### Datasheet body
442
+
443
+ A card-density `SemanticElement` reads as a datasheet only while every figure has one place. The
444
+ readings strip is the headline, so it shows either every measurement or none — a subset picked by
445
+ position is not a headline. Its tiles wrap into rows and a short last row widens them, so five
446
+ readings are four and one wide, never four and a hole. The body is `ElementSection`s, each naming
447
+ what it holds: measurements in a `DataTable` (one row per quantity, the unit in its own column),
448
+ documentary facts in a `KeyValueList layout="facts"`, artifacts in an `ArtifactRow`. Labels are
449
+ worded for the reader, never raw field names. One fingerprint closes the sheet in
450
+ `ElementProvenance`; nothing shown in a section is repeated there.
451
+
452
+ ```tsx
453
+ <SemanticElement
454
+ reference={reference}
455
+ density="card"
456
+ ident={<ElementIdent marker="OP" label="Operating point" detail="Admitted result · r150" />}
457
+ reading={observables.length <= READING_STRIP_LIMIT ? observables.map(toReading) : []}
458
+ body={
459
+ <ElementBody>
460
+ {observables.length > READING_STRIP_LIMIT && (
461
+ <ElementSection title="Observables">
462
+ <DataTable
463
+ label="Observables"
464
+ rows={observables}
465
+ columns={QUANTITY_COLUMNS}
466
+ rowKey={rowKey}
467
+ />
468
+ </ElementSection>
469
+ )}
470
+ <ElementSection title="Provenance">
471
+ <KeyValueList layout="facts" items={provenanceFacts} />
472
+ <ArtifactRow label="Admitted result" uri={artifact.id} fingerprint={artifact.fingerprint} />
473
+ </ElementSection>
474
+ </ElementBody>
475
+ }
476
+ provenance={<ElementProvenance label="Projection" value={projectionFingerprint} />}
477
+ />;
478
+ ```
479
+
480
+ ### Artifact collection
481
+
482
+ `CollectionCard` + `ArtifactRow` keeps a single outer border for a bounded list of immutable
483
+ artifacts. Thread the count through `eyebrow` or `actions`; `EmptyState` fills the list body when
484
+ there is nothing to show. `CollectionCard` is available since 0.3.x; the `eyebrow` slot on `Card`
485
+ accepts any `ComponentChildren`, so a plain count string requires no extra component.
486
+
487
+ ```tsx
488
+ <CollectionCard
489
+ label="Build artifacts"
490
+ title="Artifacts"
491
+ eyebrow={artifacts.length > 0 ? `${artifacts.length} items` : undefined}
492
+ >
493
+ {artifacts.length === 0
494
+ ? <EmptyState>No artifacts recorded.</EmptyState>
495
+ : artifacts.map((a) => (
496
+ <ArtifactRow
497
+ key={a.uri}
498
+ label={a.label}
499
+ uri={a.uri}
500
+ verification={a.verification}
501
+ />
502
+ ))}
503
+ </CollectionCard>;
504
+ ```
505
+
506
+ ## Contributing interface translations
507
+
508
+ English is the default and reference language. French is an optional existing translation;
509
+ additional languages are contributions, not a prerequisite for building or improving a viewer.
510
+
511
+ `createTranslator` is a small renderer-neutral dictionary helper from the package root. Keep stable
512
+ keys in a complete base dictionary, and add language dictionaries as partial overrides. Select the
513
+ translator from the current host locale when rendering, so the same recorded result can change its
514
+ interface language without changing its data.
515
+
516
+ ```ts
517
+ import { createTranslator } from "@mcpview/components";
518
+
519
+ const en = {
520
+ technicalDetails: "Technical details",
521
+ revisionLabel: "Revision {revision}",
522
+ };
523
+ const fr: Partial<Record<keyof typeof en, string>> = {
524
+ technicalDetails: "Détails techniques",
525
+ revisionLabel: "Révision {revision}",
526
+ };
527
+ const messages = createTranslator({ defaultLocale: "en", messages: en, translations: { fr } });
528
+ const t = messages(context.hostContext.locale);
529
+ t("technicalDetails");
530
+ t("revisionLabel", { revision: 17 });
531
+ messages.locale("fr-CA"); // "fr" — the dictionary actually selected
532
+ ```
533
+
534
+ Lookup falls back **per key** through the exact locale, its language parents, then the base
535
+ dictionary: with an English base, `fr-CA` → `fr` → English. A missing entry in a partial dictionary
536
+ does not hide the base text. An absent or invalid host locale uses the configured default locale;
537
+ there is no global mutable locale. `messages.locale(hostLocale)` uses that same chain and returns
538
+ the exact registered locale, the matched parent, or the canonical default — pass it as
539
+ `documentLanguage` so `document.documentElement.lang` names the selected dictionary. Keep
540
+ interpolation names such as `{revision}` intact. Render returned messages as text, never as HTML.
541
+
542
+ Translate interface labels and helper text only. Preserve authored names, payload values, units,
543
+ identifiers, digests, server messages and literal contract states such as `documentary`,
544
+ `unverified`, `unresolved` or `TRACE GAP`. Use `Intl.NumberFormat` and `Intl.DateTimeFormat` with
545
+ the host locale for presentation; formatting must not convert units or overwrite the stored
546
+ evidence.
547
+
548
+ For a new locale contribution, use this short PR checklist:
549
+
550
+ - Name the locale tag and the dictionary being extended (shared interface or a particular MCP).
551
+ - Keep existing keys stable; add any new key to the base dictionary first.
552
+ - List deliberately missing translations and preserve every interpolation placeholder.
553
+ - Include one small example showing a translated label and fallback for an untranslated key.
554
+ - Check the changed wording in a narrow viewer, including accessible labels and technical details.
555
+ - Confirm that authored data and contract states retain their original bytes and meaning.
556
+
557
+ The kit exports its English and French interface dictionaries as `MCP_VIEW_MESSAGES_EN` and
558
+ `MCP_VIEW_MESSAGES_FR`. MCPs keep their domain-specific interface dictionaries beside their viewers;
559
+ they can reuse the same helper without importing a new localization runtime.
560
+
561
+ ## Result-viewer scaffold (Deno/JSR only)
562
+
563
+ The project generator intentionally uses Deno filesystem APIs and `deno fmt`. The generated
564
+ `src/main.ts` is a component registry plus one `fromToolResult` projection handed to
565
+ `startSurfaceApp()` from `@mcpview/components/surface`; it hand-rolls no App lifecycle. Its
566
+ `build.ts` accepts `MCP_VIEW_MODULE` and `MCP_VIEW_COMPONENTS_MODULE` overrides (the `mod.ts` of a
567
+ local checkout); the `/surface` entry is derived from the latter unless
568
+ `MCP_VIEW_COMPONENTS_SURFACE_MODULE` names it. Run the generator from JSR:
569
+
570
+ ```sh
571
+ deno run -A jsr:@mcpview/components@0.10.0/scaffold result-viewer ./result-viewer
572
+ ```
573
+
574
+ The npm package contains only the runtime and presentation entry points. It does not export or ship
575
+ `@mcpview/components/scaffold`; Node ESM imports and CommonJS requires of that subpath are expected
576
+ to fail with `ERR_PACKAGE_PATH_NOT_EXPORTED` rather than loading a Deno-only module.
@@ -0,0 +1,12 @@
1
+ declare global {
2
+ interface Object {
3
+ /**
4
+ * Determines whether an object has a property with the specified name.
5
+ * @param o An object.
6
+ * @param v A property name.
7
+ */
8
+ hasOwn(o: object, v: PropertyKey): boolean;
9
+ }
10
+ }
11
+ export {};
12
+ //# sourceMappingURL=_dnt.polyfills.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,15 @@
1
+ // https://github.com/tc39/proposal-accessible-object-hasownproperty/blob/main/polyfill.js
2
+ if (!Object.hasOwn) {
3
+ Object.defineProperty(Object, "hasOwn", {
4
+ value: function (object, property) {
5
+ if (object == null) {
6
+ throw new TypeError("Cannot convert undefined or null to object");
7
+ }
8
+ return Object.prototype.hasOwnProperty.call(Object(object), property);
9
+ },
10
+ configurable: true,
11
+ enumerable: false,
12
+ writable: true,
13
+ });
14
+ }
15
+ export {};
package/esm/fonts.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Embedded webfaces for the shared theme.
3
+ *
4
+ * Import as `@mcpview/components/fonts`. Opt-in and ~140 KB: a viewer
5
+ * that must render identically inside a host iframe without network access
6
+ * calls `installMcpViewFonts()` next to `installMcpViewTheme()`; one that can
7
+ * rely on system faces leaves this entry out of its bundle.
8
+ *
9
+ * @module
10
+ */
11
+ import "./_dnt.polyfills.js";
12
+ export { installMcpViewFonts, MCP_VIEW_FONT_FAMILIES, MCP_VIEW_FONTS_CSS, MCP_VIEW_FONTS_STYLE_ID, type McpViewFontFamily, } from "./src/fonts.js";
13
+ //# sourceMappingURL=fonts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fonts.d.ts","sourceRoot":"","sources":["../src/fonts.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,qBAAqB,CAAC;AAG7B,OAAO,EACL,mBAAmB,EACnB,sBAAsB,EACtB,kBAAkB,EAClB,uBAAuB,EACvB,KAAK,iBAAiB,GACvB,MAAM,gBAAgB,CAAC"}
package/esm/fonts.js ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Embedded webfaces for the shared theme.
3
+ *
4
+ * Import as `@mcpview/components/fonts`. Opt-in and ~140 KB: a viewer
5
+ * that must render identically inside a host iframe without network access
6
+ * calls `installMcpViewFonts()` next to `installMcpViewTheme()`; one that can
7
+ * rely on system faces leaves this entry out of its bundle.
8
+ *
9
+ * @module
10
+ */
11
+ import "./_dnt.polyfills.js";
12
+ export { installMcpViewFonts, MCP_VIEW_FONT_FAMILIES, MCP_VIEW_FONTS_CSS, MCP_VIEW_FONTS_STYLE_ID, } from "./src/fonts.js";