@grackle-ai/web-components 0.110.2 → 0.110.3

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 (31) hide show
  1. package/.rush/temp/{05987f49cbc7b78f5d65af2b44f17ec097f301b3.tar.log → 6bc9700f6b9938b330a84bd0f8c7ef5a7e3dbfb6.tar.log} +2 -2
  2. package/.rush/temp/{05987f49cbc7b78f5d65af2b44f17ec097f301b3.untar.log → 6bc9700f6b9938b330a84bd0f8c7ef5a7e3dbfb6.untar.log} +2 -2
  3. package/.rush/temp/chunked-rush-logs/web-components._phase_build.chunks.jsonl +5 -5
  4. package/.rush/temp/chunked-rush-logs/web-components._phase_test.chunks.jsonl +27 -25
  5. package/.rush/temp/{0d1a9a7ccd09d5c1a54bcb19415c33e9f2c48e61.tar.log → de557b666a8980e74bc5c775dc53097f779f8d53.tar.log} +50 -55
  6. package/.rush/temp/{0d1a9a7ccd09d5c1a54bcb19415c33e9f2c48e61.untar.log → de557b666a8980e74bc5c775dc53097f779f8d53.untar.log} +2 -2
  7. package/.rush/temp/operation/_phase_build/all.log +5 -5
  8. package/.rush/temp/operation/_phase_build/log-chunks.jsonl +5 -5
  9. package/.rush/temp/operation/_phase_build/state.json +1 -1
  10. package/.rush/temp/operation/_phase_test/all.log +27 -25
  11. package/.rush/temp/operation/_phase_test/log-chunks.jsonl +27 -25
  12. package/.rush/temp/operation/_phase_test/state.json +1 -1
  13. package/.rush/temp/shrinkwrap-deps.json +58 -3
  14. package/dist/index.js +18005 -12131
  15. package/mcp-app-sandbox/sample-widget.js +74 -0
  16. package/mcp-app-sandbox/sandbox-relay.js +114 -0
  17. package/mcp-app-sandbox/sandbox.html +37 -0
  18. package/mcp-app-sandbox/serve.mjs +145 -0
  19. package/package.json +10 -2
  20. package/rush-logs/web-components._phase_build.cache.log +1 -1
  21. package/rush-logs/web-components._phase_build.log +5 -5
  22. package/rush-logs/web-components._phase_test.cache.log +1 -1
  23. package/rush-logs/web-components._phase_test.log +27 -25
  24. package/src/components/display/McpAppWidget.stories.tsx +60 -0
  25. package/src/components/display/McpAppWidget.test.tsx +46 -0
  26. package/src/components/display/McpAppWidget.tsx +358 -0
  27. package/src/components/display/index.ts +2 -0
  28. package/src/index.ts +3 -1
  29. package/src/utils/grackleHostStyleVariables.test.ts +25 -0
  30. package/src/utils/grackleHostStyleVariables.ts +134 -0
  31. package/temp/build/lint/_eslint-5eVG3S6w.json +24 -4
@@ -0,0 +1,358 @@
1
+ import { useEffect, useRef, useState, type JSX } from "react";
2
+ import {
3
+ AppBridge,
4
+ PostMessageTransport,
5
+ buildAllowAttribute,
6
+ type McpUiResourceCsp,
7
+ type McpUiResourcePermissions,
8
+ } from "@modelcontextprotocol/ext-apps/app-bridge";
9
+ import type { McpUiStyles } from "@modelcontextprotocol/ext-apps";
10
+ import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
11
+ import { grackleHostStyleVariables } from "../../utils/grackleHostStyleVariables.js";
12
+
13
+ /** Notification method the outer sandbox proxy posts once it is ready. */
14
+ const SANDBOX_PROXY_READY: string = "ui/notifications/sandbox-proxy-ready";
15
+
16
+ /** Default host identity reported to widgets during the MCP Apps handshake. */
17
+ const DEFAULT_HOST_INFO: Readonly<{ name: string; version: string }> = {
18
+ name: "Grackle",
19
+ version: "0.0.0",
20
+ };
21
+
22
+ /** URL schemes the default link handler is permitted to open. */
23
+ const SAFE_LINK_PROTOCOLS: ReadonlySet<string> = new Set(["http:", "https:"]);
24
+
25
+ /** True if `url` parses as an `http(s)` URL safe to open in a new browsing context. */
26
+ function isSafeHttpUrl(url: string): boolean {
27
+ try {
28
+ return SAFE_LINK_PROTOCOLS.has(new URL(url).protocol);
29
+ } catch {
30
+ return false;
31
+ }
32
+ }
33
+
34
+ /** A tool call the widget asked the host to run on its behalf. */
35
+ export interface McpAppWidgetCallToolParams {
36
+ name: string;
37
+ arguments?: Record<string, unknown>;
38
+ }
39
+
40
+ /**
41
+ * Props for {@link McpAppWidget}. Presentational only — all data and side
42
+ * effects arrive as props (no `useGrackle()`).
43
+ */
44
+ export interface McpAppWidgetProps {
45
+ /** Widget HTML (`text/html;profile=mcp-app` contents) rendered in the sandbox. */
46
+ widgetHtml: string;
47
+ /** URL of the sandbox proxy, served from a DIFFERENT origin than the host. */
48
+ sandboxProxyUrl: string;
49
+ /** Tool input delivered to the widget via `ui/notifications/tool-input`. */
50
+ toolInput?: Record<string, unknown>;
51
+ /** Tool result delivered to the widget via `ui/notifications/tool-result`. */
52
+ toolResult?: CallToolResult;
53
+ /** Content-Security-Policy domains for the widget (from the resource `_meta.ui`). */
54
+ csp?: McpUiResourceCsp;
55
+ /** Permissions to grant the widget iframe (from the resource `_meta.ui`). */
56
+ permissions?: McpUiResourcePermissions;
57
+ /** Style variables for `hostContext.styles`; defaults to Grackle's live theme. */
58
+ hostStyleVariables?: McpUiStyles;
59
+ /** Color theme reported to the widget; defaults to the document's `data-theme`. */
60
+ theme?: "light" | "dark";
61
+ /** Host identity reported to the widget; defaults to {@link DEFAULT_HOST_INFO}. */
62
+ hostInfo?: { name: string; version: string };
63
+ /** Handle a tool call the widget requests (no MCP client is wired in T1). */
64
+ onCallTool?: (params: McpAppWidgetCallToolParams) => Promise<CallToolResult>;
65
+ /** Handle a link the widget asks the host to open. */
66
+ onOpenLink?: (url: string) => void;
67
+ /** Handle a message the widget asks the host to surface. */
68
+ onSendMessage?: (message: unknown) => void;
69
+ /** Handle a model-context update pushed by the widget. */
70
+ onUpdateModelContext?: (context: unknown) => void;
71
+ /** Notified when the widget requests a new size. */
72
+ onSizeChange?: (size: { width?: number; height?: number }) => void;
73
+ }
74
+
75
+ /** Resolve the active theme, preferring the prop, then the document, then light. */
76
+ function resolveTheme(theme: McpAppWidgetProps["theme"]): "light" | "dark" {
77
+ if (theme) {
78
+ return theme;
79
+ }
80
+ if (typeof document !== "undefined") {
81
+ const attr: string | null = document.documentElement.getAttribute("data-theme");
82
+ if (attr === "dark") {
83
+ return "dark";
84
+ }
85
+ }
86
+ return "light";
87
+ }
88
+
89
+ /**
90
+ * Point the iframe at the sandbox proxy and resolve once the proxy reports
91
+ * ready. Returns `false` if the iframe was already loaded (guards against an
92
+ * accidental double-invoke) or if `signal` aborts before the proxy responds.
93
+ *
94
+ * The ready listener is bound to `signal` so it is removed on effect cleanup,
95
+ * and only messages from the proxy window AND its expected origin are accepted.
96
+ */
97
+ function loadSandboxProxy(
98
+ iframe: HTMLIFrameElement,
99
+ sandboxProxyUrl: string,
100
+ proxyOrigin: string,
101
+ csp: McpUiResourceCsp | undefined,
102
+ permissions: McpUiResourcePermissions | undefined,
103
+ signal: AbortSignal,
104
+ ): Promise<boolean> {
105
+ if (iframe.src) {
106
+ return Promise.resolve(false);
107
+ }
108
+ iframe.setAttribute("sandbox", "allow-scripts allow-same-origin allow-forms");
109
+ const allow: string = buildAllowAttribute(permissions);
110
+ if (allow) {
111
+ iframe.setAttribute("allow", allow);
112
+ }
113
+ const ready: Promise<boolean> = new Promise<boolean>((resolve) => {
114
+ const listener = (event: MessageEvent): void => {
115
+ const data: { method?: string } | undefined = event.data as { method?: string } | undefined;
116
+ if (
117
+ event.source === iframe.contentWindow &&
118
+ event.origin === proxyOrigin &&
119
+ data?.method === SANDBOX_PROXY_READY
120
+ ) {
121
+ resolve(true);
122
+ }
123
+ };
124
+ // `{ signal }` removes the listener automatically on effect cleanup, so it
125
+ // never outlives the component even if the proxy never responds.
126
+ window.addEventListener("message", listener, { signal });
127
+ signal.addEventListener("abort", () => resolve(false), { once: true });
128
+ });
129
+ const url: URL = new URL(sandboxProxyUrl, window.location.href);
130
+ if (csp) {
131
+ url.searchParams.set("csp", JSON.stringify(csp));
132
+ }
133
+ iframe.src = url.href;
134
+ return ready;
135
+ }
136
+
137
+ /** Swallow a settled promise's rejection (the host outlives transient widget errors). */
138
+ function ignoreRejection(promise: Promise<unknown> | void): void {
139
+ Promise.resolve(promise).catch(() => undefined);
140
+ }
141
+
142
+ /**
143
+ * Renders an MCP Apps widget (untrusted HTML) inside a double-iframe sandbox and
144
+ * drives it over the `ext-apps` `AppBridge` postMessage protocol.
145
+ *
146
+ * The Grackle chat pane is not an MCP client, so this constructs the bridge with
147
+ * `null` (no client) and serves tool input/result from props. Wiring the bridge
148
+ * to a live MCP server is a later ticket (#1238).
149
+ */
150
+ export function McpAppWidget(props: McpAppWidgetProps): JSX.Element {
151
+ const {
152
+ widgetHtml,
153
+ sandboxProxyUrl,
154
+ csp,
155
+ permissions,
156
+ hostStyleVariables,
157
+ theme,
158
+ hostInfo,
159
+ toolInput,
160
+ toolResult,
161
+ onCallTool,
162
+ onOpenLink,
163
+ onSendMessage,
164
+ onUpdateModelContext,
165
+ onSizeChange,
166
+ } = props;
167
+
168
+ // Fail fast on the isolation-breaking misconfiguration: the sandbox proxy MUST
169
+ // be a different origin than the host, otherwise `window.top` is reachable and
170
+ // the double-iframe guarantee is void.
171
+ if (
172
+ typeof window !== "undefined" &&
173
+ new URL(sandboxProxyUrl, window.location.href).origin === window.location.origin
174
+ ) {
175
+ throw new Error(
176
+ "McpAppWidget: sandboxProxyUrl must be served from a DIFFERENT origin than the host.",
177
+ );
178
+ }
179
+
180
+ const iframeRef = useRef<HTMLIFrameElement>(null);
181
+ const bridgeRef = useRef<AppBridge | undefined>(undefined);
182
+ // Flips true once the ui/initialize handshake completes; the tool-input/result
183
+ // effects below key on it so late-arriving props still reach the widget.
184
+ const [initialized, setInitialized] = useState<boolean>(false);
185
+
186
+ // Keep the latest callbacks in a ref so the setup effect can be keyed only on
187
+ // the widget identity (re-running it would reload the iframe).
188
+ const handlers = useRef({ onCallTool, onOpenLink, onSendMessage, onUpdateModelContext, onSizeChange });
189
+ handlers.current = { onCallTool, onOpenLink, onSendMessage, onUpdateModelContext, onSizeChange };
190
+
191
+ // csp/permissions are part of the widget identity (they affect the proxy URL
192
+ // and sendSandboxResourceReady), so the iframe must reload when they change.
193
+ const cspKey: string = JSON.stringify(csp ?? null);
194
+ const permissionsKey: string = JSON.stringify(permissions ?? null);
195
+
196
+ useEffect(() => {
197
+ const iframe: HTMLIFrameElement | null = iframeRef.current;
198
+ if (!iframe) {
199
+ return undefined;
200
+ }
201
+
202
+ // Origin of the proxy, used to validate inbound proxy messages. The
203
+ // different-origin invariant is enforced at render time (see above).
204
+ const proxyOrigin: string = new URL(sandboxProxyUrl, window.location.href).origin;
205
+ const abortController: AbortController = new AbortController();
206
+ const { signal } = abortController;
207
+ // Read abort state through a function so TS flow-analysis can't narrow it to
208
+ // a constant across the awaits below (cleanup flips it asynchronously).
209
+ const isAborted = (): boolean => signal.aborted;
210
+ let resizeObserver: ResizeObserver | undefined;
211
+
212
+ const run = async (): Promise<void> => {
213
+ const firstTime: boolean = await loadSandboxProxy(
214
+ iframe,
215
+ sandboxProxyUrl,
216
+ proxyOrigin,
217
+ csp,
218
+ permissions,
219
+ signal,
220
+ );
221
+ if (!firstTime || isAborted()) {
222
+ return;
223
+ }
224
+
225
+ const bridge = new AppBridge(
226
+ null,
227
+ hostInfo ?? DEFAULT_HOST_INFO,
228
+ { openLinks: {}, updateModelContext: { text: {} } },
229
+ {
230
+ hostContext: {
231
+ theme: resolveTheme(theme),
232
+ platform: "web",
233
+ styles: { variables: hostStyleVariables ?? grackleHostStyleVariables() },
234
+ containerDimensions: { maxHeight: 6000 },
235
+ displayMode: "inline",
236
+ availableDisplayModes: ["inline"],
237
+ },
238
+ },
239
+ );
240
+ bridgeRef.current = bridge;
241
+
242
+ bridge.oncalltool = async (params): Promise<CallToolResult> => {
243
+ const handler = handlers.current.onCallTool;
244
+ if (handler) {
245
+ return handler({ name: params.name, arguments: params.arguments });
246
+ }
247
+ return { isError: true, content: [{ type: "text", text: "No MCP client is connected to this host." }] };
248
+ };
249
+ bridge.onopenlink = async ({ url }): Promise<Record<string, never>> => {
250
+ const handler = handlers.current.onOpenLink;
251
+ if (handler) {
252
+ handler(url);
253
+ } else if (isSafeHttpUrl(url)) {
254
+ // Only http(s) — never javascript:/data: from an untrusted widget.
255
+ window.open(url, "_blank", "noopener,noreferrer");
256
+ }
257
+ return {};
258
+ };
259
+ bridge.onmessage = async (params): Promise<Record<string, never>> => {
260
+ handlers.current.onSendMessage?.(params);
261
+ return {};
262
+ };
263
+ bridge.onupdatemodelcontext = async (params): Promise<Record<string, never>> => {
264
+ handlers.current.onUpdateModelContext?.(params);
265
+ return {};
266
+ };
267
+ bridge.onsizechange = ({ width, height }): void => {
268
+ if (width !== undefined) {
269
+ iframe.style.minWidth = `min(${width}px, 100%)`;
270
+ }
271
+ if (height !== undefined) {
272
+ iframe.style.height = `${height}px`;
273
+ }
274
+ handlers.current.onSizeChange?.({ width, height });
275
+ };
276
+ bridge.onrequestdisplaymode = async (): Promise<{ mode: "inline" }> => ({ mode: "inline" });
277
+
278
+ const handshakeComplete: Promise<void> = new Promise<void>((resolve) => {
279
+ bridge.oninitialized = (): void => resolve();
280
+ });
281
+
282
+ await bridge.connect(new PostMessageTransport(iframe.contentWindow as Window, iframe.contentWindow as Window));
283
+ if (isAborted()) {
284
+ return;
285
+ }
286
+ await bridge.sendSandboxResourceReady({ html: widgetHtml, csp, permissions });
287
+ await handshakeComplete;
288
+ if (isAborted()) {
289
+ return;
290
+ }
291
+ // Tool input/result are delivered (and kept in sync) by the effects below
292
+ // now that the handshake is complete.
293
+ setInitialized(true);
294
+
295
+ resizeObserver = new ResizeObserver(([entry]) => {
296
+ const width: number = Math.round(entry.contentRect.width);
297
+ if (width > 0) {
298
+ ignoreRejection(bridge.sendHostContextChange({ containerDimensions: { width, maxHeight: 6000 } }));
299
+ }
300
+ });
301
+ resizeObserver.observe(iframe);
302
+ };
303
+
304
+ run().catch(() => undefined);
305
+
306
+ return (): void => {
307
+ abortController.abort();
308
+ setInitialized(false);
309
+ resizeObserver?.disconnect();
310
+ const bridge: AppBridge | undefined = bridgeRef.current;
311
+ bridgeRef.current = undefined;
312
+ if (bridge) {
313
+ ignoreRejection(bridge.teardownResource({}));
314
+ }
315
+ iframe.removeAttribute("src");
316
+ };
317
+ // Setup is keyed on the widget identity (html + proxy URL + csp/permissions).
318
+ // Tool input/result and theme updates flow via the dedicated effects below.
319
+ }, [widgetHtml, sandboxProxyUrl, cspKey, permissionsKey]);
320
+
321
+ // Deliver tool input after the handshake, and whenever it changes afterwards.
322
+ useEffect(() => {
323
+ if (!initialized) {
324
+ return;
325
+ }
326
+ ignoreRejection(bridgeRef.current?.sendToolInput({ arguments: toolInput ?? {} }));
327
+ }, [initialized, toolInput]);
328
+
329
+ // Deliver the tool result once it is available, and whenever it changes. The
330
+ // host commonly renders the widget before the result exists.
331
+ useEffect(() => {
332
+ if (!initialized || !toolResult) {
333
+ return;
334
+ }
335
+ ignoreRejection(bridgeRef.current?.sendToolResult(toolResult));
336
+ }, [initialized, toolResult]);
337
+
338
+ // Propagate theme + style-variable changes to a live widget. When
339
+ // hostStyleVariables is omitted, the Grackle token values themselves change
340
+ // with the theme, so the resolved variables are re-sent too.
341
+ useEffect(() => {
342
+ ignoreRejection(
343
+ bridgeRef.current?.sendHostContextChange({
344
+ theme: resolveTheme(theme),
345
+ styles: { variables: hostStyleVariables ?? grackleHostStyleVariables() },
346
+ }),
347
+ );
348
+ }, [theme, hostStyleVariables]);
349
+
350
+ return (
351
+ <iframe
352
+ ref={iframeRef}
353
+ data-testid="mcp-app-widget"
354
+ title="MCP App widget"
355
+ style={{ width: "100%", border: "none", display: "block" }}
356
+ />
357
+ );
358
+ }
@@ -14,7 +14,9 @@ export { Spinner } from "./Spinner.js";
14
14
  export { SplashScreen } from "./SplashScreen.js";
15
15
  export { Tooltip } from "./Tooltip.js";
16
16
  export { SessionAttemptSelector } from "./SessionAttemptSelector.js";
17
+ export { McpAppWidget } from "./McpAppWidget.js";
17
18
 
18
19
  export type { ButtonProps, ButtonVariant, ButtonSize } from "./Button.js";
19
20
  export type { TooltipProps, TooltipPlacement } from "./Tooltip.js";
20
21
  export type { SessionAttemptSelectorProps } from "./SessionAttemptSelector.js";
22
+ export type { McpAppWidgetProps, McpAppWidgetCallToolParams } from "./McpAppWidget.js";
package/src/index.ts CHANGED
@@ -19,10 +19,12 @@ export { useDagLayout } from "./components/dag/useDagLayout.js";
19
19
  export {
20
20
  Breadcrumbs, Button, CopyButton, DemoBanner, SplitButton,
21
21
  EventRenderer, ConfirmDialog, Skeleton, SkeletonText, SkeletonCard,
22
- Spinner, SplashScreen, Tooltip,
22
+ Spinner, SplashScreen, Tooltip, McpAppWidget,
23
23
  } from "./components/display/index.js";
24
24
  export type { ButtonProps, ButtonVariant, ButtonSize } from "./components/display/index.js";
25
25
  export type { TooltipProps, TooltipPlacement } from "./components/display/index.js";
26
+ export type { McpAppWidgetProps, McpAppWidgetCallToolParams } from "./components/display/index.js";
27
+ export { grackleHostStyleVariables } from "./utils/grackleHostStyleVariables.js";
26
28
  export { EventStream } from "./components/display/EventStream.js";
27
29
  export { EventHoverRow } from "./components/display/EventHoverRow.js";
28
30
  export type { EventHoverRowProps } from "./components/display/EventHoverRow.js";
@@ -0,0 +1,25 @@
1
+ // @vitest-environment jsdom
2
+ import { describe, it, expect, afterEach } from "vitest";
3
+ import { grackleHostStyleVariables } from "./grackleHostStyleVariables.js";
4
+
5
+ describe("grackleHostStyleVariables", () => {
6
+ afterEach(() => {
7
+ document.documentElement.removeAttribute("style");
8
+ });
9
+
10
+ it("always returns the MCP-standard fallback variables", () => {
11
+ const vars = grackleHostStyleVariables();
12
+ expect(vars["--color-background-primary"]).toBeDefined();
13
+ expect(vars["--color-text-primary"]).toBeDefined();
14
+ expect(vars["--font-sans"]).toBeDefined();
15
+ expect(vars["--border-radius-md"]).toBeDefined();
16
+ });
17
+
18
+ it("maps a live Grackle token onto its MCP-standard name", () => {
19
+ document.documentElement.style.setProperty("--bg-base", "rgb(1, 2, 3)");
20
+ document.documentElement.style.setProperty("--text-primary", "rgb(4, 5, 6)");
21
+ const vars = grackleHostStyleVariables();
22
+ expect(vars["--color-background-primary"]).toBe("rgb(1, 2, 3)");
23
+ expect(vars["--color-text-primary"]).toBe("rgb(4, 5, 6)");
24
+ });
25
+ });
@@ -0,0 +1,134 @@
1
+ import type { McpUiStyles } from "@modelcontextprotocol/ext-apps";
2
+
3
+ /**
4
+ * MCP Apps widgets consume a fixed, standard set of CSS custom properties
5
+ * (`--color-*`, `--font-*`, `--border-radius-*`, `--shadow-*`). Grackle's own
6
+ * theme tokens live under different names (`--bg-*`, `--text-*`, `--radius-*`) in
7
+ * `src/styles/theme.scss`. This module exposes Grackle's current theme to widgets
8
+ * under the MCP-standard names so a widget renders coherently inside the host.
9
+ *
10
+ * `McpUiStyles` requires the complete variable set, so we seed from the standard
11
+ * theme-adaptive defaults (verbatim from modelcontextprotocol/ext-apps
12
+ * examples/basic-host/src/host-styles.ts, commit 9a37ad7) and override the subset
13
+ * we can source from Grackle's live theme.
14
+ */
15
+
16
+ /** Complete MCP-standard default style variables (theme-adaptive via `light-dark()`). */
17
+ const DEFAULT_MCP_STYLES: McpUiStyles = {
18
+ "--color-background-primary": "light-dark(#ffffff, #1a1a1a)",
19
+ "--color-background-secondary": "light-dark(#f5f5f5, #2d2d2d)",
20
+ "--color-background-tertiary": "light-dark(#e5e5e5, #404040)",
21
+ "--color-background-inverse": "light-dark(#1a1a1a, #ffffff)",
22
+ "--color-background-ghost": "light-dark(rgba(255,255,255,0), rgba(26,26,26,0))",
23
+ "--color-background-info": "light-dark(#eff6ff, #1e3a5f)",
24
+ "--color-background-danger": "light-dark(#fef2f2, #7f1d1d)",
25
+ "--color-background-success": "light-dark(#f0fdf4, #14532d)",
26
+ "--color-background-warning": "light-dark(#fefce8, #713f12)",
27
+ "--color-background-disabled": "light-dark(rgba(255,255,255,0.5), rgba(26,26,26,0.5))",
28
+ "--color-text-primary": "light-dark(#1f2937, #f3f4f6)",
29
+ "--color-text-secondary": "light-dark(#6b7280, #9ca3af)",
30
+ "--color-text-tertiary": "light-dark(#9ca3af, #6b7280)",
31
+ "--color-text-inverse": "light-dark(#f3f4f6, #1f2937)",
32
+ "--color-text-ghost": "light-dark(rgba(107,114,128,0.5), rgba(156,163,175,0.5))",
33
+ "--color-text-info": "light-dark(#1d4ed8, #60a5fa)",
34
+ "--color-text-danger": "light-dark(#b91c1c, #f87171)",
35
+ "--color-text-success": "light-dark(#15803d, #4ade80)",
36
+ "--color-text-warning": "light-dark(#a16207, #fbbf24)",
37
+ "--color-text-disabled": "light-dark(rgba(31,41,55,0.5), rgba(243,244,246,0.5))",
38
+ "--color-border-primary": "light-dark(#e5e7eb, #404040)",
39
+ "--color-border-secondary": "light-dark(#d1d5db, #525252)",
40
+ "--color-border-tertiary": "light-dark(#f3f4f6, #374151)",
41
+ "--color-border-inverse": "light-dark(rgba(255,255,255,0.3), rgba(0,0,0,0.3))",
42
+ "--color-border-ghost": "light-dark(rgba(229,231,235,0), rgba(64,64,64,0))",
43
+ "--color-border-info": "light-dark(#93c5fd, #1e40af)",
44
+ "--color-border-danger": "light-dark(#fca5a5, #991b1b)",
45
+ "--color-border-success": "light-dark(#86efac, #166534)",
46
+ "--color-border-warning": "light-dark(#fde047, #854d0e)",
47
+ "--color-border-disabled": "light-dark(rgba(229,231,235,0.5), rgba(64,64,64,0.5))",
48
+ "--color-ring-primary": "light-dark(#3b82f6, #60a5fa)",
49
+ "--color-ring-secondary": "light-dark(#6b7280, #9ca3af)",
50
+ "--color-ring-inverse": "light-dark(#ffffff, #1f2937)",
51
+ "--color-ring-info": "light-dark(#2563eb, #3b82f6)",
52
+ "--color-ring-danger": "light-dark(#dc2626, #ef4444)",
53
+ "--color-ring-success": "light-dark(#16a34a, #22c55e)",
54
+ "--color-ring-warning": "light-dark(#ca8a04, #eab308)",
55
+ "--font-sans": "system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif",
56
+ "--font-mono": "ui-monospace, 'SF Mono', Monaco, 'Cascadia Code', monospace",
57
+ "--font-weight-normal": "400",
58
+ "--font-weight-medium": "500",
59
+ "--font-weight-semibold": "600",
60
+ "--font-weight-bold": "700",
61
+ "--font-text-xs-size": "0.75rem",
62
+ "--font-text-sm-size": "0.875rem",
63
+ "--font-text-md-size": "1rem",
64
+ "--font-text-lg-size": "1.125rem",
65
+ "--font-heading-xs-size": "0.75rem",
66
+ "--font-heading-sm-size": "0.875rem",
67
+ "--font-heading-md-size": "1rem",
68
+ "--font-heading-lg-size": "1.25rem",
69
+ "--font-heading-xl-size": "1.5rem",
70
+ "--font-heading-2xl-size": "1.875rem",
71
+ "--font-heading-3xl-size": "2.25rem",
72
+ "--font-text-xs-line-height": "1.4",
73
+ "--font-text-sm-line-height": "1.4",
74
+ "--font-text-md-line-height": "1.5",
75
+ "--font-text-lg-line-height": "1.5",
76
+ "--font-heading-xs-line-height": "1.4",
77
+ "--font-heading-sm-line-height": "1.4",
78
+ "--font-heading-md-line-height": "1.4",
79
+ "--font-heading-lg-line-height": "1.3",
80
+ "--font-heading-xl-line-height": "1.25",
81
+ "--font-heading-2xl-line-height": "1.2",
82
+ "--font-heading-3xl-line-height": "1.1",
83
+ "--border-radius-xs": "2px",
84
+ "--border-radius-sm": "4px",
85
+ "--border-radius-md": "6px",
86
+ "--border-radius-lg": "8px",
87
+ "--border-radius-xl": "12px",
88
+ "--border-radius-full": "9999px",
89
+ "--border-width-regular": "1px",
90
+ "--shadow-hairline": "0 1px 2px 0 rgba(0, 0, 0, 0.05)",
91
+ "--shadow-sm": "0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1)",
92
+ "--shadow-md": "0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1)",
93
+ "--shadow-lg": "0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1)",
94
+ };
95
+
96
+ /** MCP-standard variable name -> Grackle theme token to read its value from. */
97
+ const GRACKLE_TOKEN_BY_MCP_NAME: Readonly<Record<string, string>> = {
98
+ "--color-background-primary": "--bg-base",
99
+ "--color-background-secondary": "--bg-surface",
100
+ "--color-background-tertiary": "--bg-elevated",
101
+ "--color-text-primary": "--text-primary",
102
+ "--color-text-secondary": "--text-secondary",
103
+ "--color-text-tertiary": "--text-tertiary",
104
+ "--color-border-primary": "--border-primary",
105
+ "--color-border-secondary": "--border-subtle",
106
+ "--font-sans": "--font-sans",
107
+ "--font-mono": "--font-mono",
108
+ "--border-radius-sm": "--radius-sm",
109
+ "--border-radius-md": "--radius-md",
110
+ "--border-radius-lg": "--radius-lg",
111
+ "--border-radius-full": "--radius-full",
112
+ };
113
+
114
+ /**
115
+ * Build the MCP-standard style-variable map from Grackle's live theme, falling
116
+ * back to theme-adaptive defaults for any token that cannot be read.
117
+ *
118
+ * @returns Style variables suitable for `hostContext.styles.variables`.
119
+ */
120
+ export function grackleHostStyleVariables(): McpUiStyles {
121
+ const out: McpUiStyles = { ...DEFAULT_MCP_STYLES };
122
+ if (typeof window === "undefined" || typeof document === "undefined") {
123
+ return out;
124
+ }
125
+ const computed: CSSStyleDeclaration = window.getComputedStyle(document.documentElement);
126
+ const writable: Record<string, string> = out as Record<string, string>;
127
+ for (const [mcpName, grackleToken] of Object.entries(GRACKLE_TOKEN_BY_MCP_NAME)) {
128
+ const value: string = computed.getPropertyValue(grackleToken).trim();
129
+ if (value) {
130
+ writable[mcpName] = value;
131
+ }
132
+ }
133
+ return out;
134
+ }
@@ -1,5 +1,5 @@
1
1
  {
2
- "cacheVersion": "9.39.4_v22.22.2",
2
+ "cacheVersion": "9.39.4_v22.22.3",
3
3
  "fileVersions": [
4
4
  [
5
5
  "context/ToastContext.tsx",
@@ -173,9 +173,17 @@
173
173
  "components/display/SessionAttemptSelector.tsx",
174
174
  "3P6Dn2a9NBqHlUcL32V4cbFlQnA=_7W3TvvwZxl0TGST6/dyQa8DKDDc="
175
175
  ],
176
+ [
177
+ "utils/grackleHostStyleVariables.ts",
178
+ "4GAn+eMbEHJoOb1z01LPtk6nJ7U=_7W3TvvwZxl0TGST6/dyQa8DKDDc="
179
+ ],
180
+ [
181
+ "components/display/McpAppWidget.tsx",
182
+ "FHPzMKgR6sTY4eFNQv5BPGbIhBI=_7W3TvvwZxl0TGST6/dyQa8DKDDc="
183
+ ],
176
184
  [
177
185
  "components/display/index.ts",
178
- "Da4l2BdBIB2GK67l9c5jGgd3gN0=_7W3TvvwZxl0TGST6/dyQa8DKDDc="
186
+ "RDb8Fh+7051CrG4TyqRFZAV2xes=_7W3TvvwZxl0TGST6/dyQa8DKDDc="
179
187
  ],
180
188
  [
181
189
  "components/display/EventHoverRow.tsx",
@@ -471,7 +479,7 @@
471
479
  ],
472
480
  [
473
481
  "index.ts",
474
- "FNRhCqrVCRyTY3w5VAdlXei++8I=_7W3TvvwZxl0TGST6/dyQa8DKDDc="
482
+ "XEgfwrVvQNW7DJQmsu4ZpsFAvgQ=_7W3TvvwZxl0TGST6/dyQa8DKDDc="
475
483
  ],
476
484
  [
477
485
  "components/index.ts",
@@ -525,6 +533,14 @@
525
533
  "components/display/FloatingActionBar.stories.tsx",
526
534
  "V+eJty0ZPmcq/XfekRbWY23Esc4=_7W3TvvwZxl0TGST6/dyQa8DKDDc="
527
535
  ],
536
+ [
537
+ "components/display/McpAppWidget.stories.tsx",
538
+ "+4zt3cRpRSDqas5f+/6UX9R/X8k=_7W3TvvwZxl0TGST6/dyQa8DKDDc="
539
+ ],
540
+ [
541
+ "components/display/McpAppWidget.test.tsx",
542
+ "ScnWU8DBqJT3ERrmR67s23IJwCU=_orHdc0vDZqoYfD6TIDl1Za3EAL4="
543
+ ],
528
544
  [
529
545
  "components/display/SessionAttemptSelector.stories.tsx",
530
546
  "7zEdkt5nss2kC13o9AffEarsIt0=_7W3TvvwZxl0TGST6/dyQa8DKDDc="
@@ -793,6 +809,10 @@
793
809
  "utils/eventContent.test.ts",
794
810
  "tDSkuhHlQ1SzQLUUM48dGJx+3vM=_orHdc0vDZqoYfD6TIDl1Za3EAL4="
795
811
  ],
812
+ [
813
+ "utils/grackleHostStyleVariables.test.ts",
814
+ "eQMyEKIM+oIyKdVdiJXOk+k9k50=_orHdc0vDZqoYfD6TIDl1Za3EAL4="
815
+ ],
796
816
  [
797
817
  "utils/route-config.test.ts",
798
818
  "AX9zgQvqbwSvAfHCmWgQWq6HiZY=_orHdc0vDZqoYfD6TIDl1Za3EAL4="
@@ -806,5 +826,5 @@
806
826
  "hL9OyAvsoDAPSh4+TPUEgQrdYMI=_orHdc0vDZqoYfD6TIDl1Za3EAL4="
807
827
  ]
808
828
  ],
809
- "filesHash": "HtegKh_bR_JPzWNcQqTeDw"
829
+ "filesHash": "PEVC244sy61mI2jL-TojYg"
810
830
  }