@devries-cameron20 / t3code Mirror · read-only / commits / ccc7b2d96f
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Syncing…

fix(web): MCP App cards no longer flash white in dark mode while the app loads (#33352)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Nov 10, 2026 at 18:58 UTC ccc7b2d96ff9e1814fb22c4110b9608b0c53cc2b
3 files changed +42 -1
apps/web/src/components/chat/McpAppFrame.tsx
+7 -1
@@ -12,6 +12,7 @@ import {
12 import { squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
13 import {
14 clampMcpAppHeight,
15 + MCP_APP_COLOR_SCHEME_PARAM,
16 MCP_APP_DEFAULT_HEIGHT,
17 MCP_APP_MAX_HEIGHT,
18 mcpAppAllowAttribute,
@@ -125,7 +126,12 @@ export function McpAppFrame(props: {
126 // The frame keeps its first URL: a re-minted one would reload the app.
127 const [src, setSrc] = useState<string | null>(null);
128 const asset = useLongLivedAssetUrl(src === null ? props.environmentId : null, resource);
128 - if (src === null && asset._tag === "Success") setSrc(asset.url);
129 + if (src === null && asset._tag === "Success") {
130 + // The app paints before `ui/initialize`, so it reads the initial scheme from its URL.
131 + const url = new URL(asset.url);
132 + url.searchParams.set(MCP_APP_COLOR_SCHEME_PARAM, theme.appearance);
133 + setSrc(url.toString());
134 + }
135
136 const detail = useTurnItemDetail({
137 environmentId: props.environmentId,
packages/shared/src/mcpApp.test.ts
+23
@@ -5,6 +5,7 @@ import {
5 injectMcpAppCsp,
6 injectMcpAppThemeBootstrap,
7 injectMcpAppCookieBootstrap,
8 + MCP_APP_COLOR_SCHEME_PARAM,
9 mcpAppContentSecurityPolicy,
10 mcpAppToolCallableByApp,
11 mcpAppToolResourceUri,
@@ -101,6 +102,28 @@ describe("injectMcpAppThemeBootstrap", () => {
102 send(initialized);
103 expect(style.colorScheme).toBe("dark");
104 });
105 +
106 + it("applies only a valid scheme from the frame URL before any message arrives", () => {
107 + const html = injectMcpAppThemeBootstrap("<p>app</p>");
108 + const script = html.slice(html.indexOf("<script>") + 8, html.indexOf("</script>"));
109 + const initialScheme = (search: string) => {
110 + const head: Array<{ name?: string; content?: string }> = [];
111 + NodeVM.runInNewContext(script, {
112 + URLSearchParams,
113 + location: { search },
114 + window: { parent: {}, addEventListener: () => {} },
115 + document: {
116 + createElement: () => ({}),
117 + head: { append: (element: (typeof head)[number]) => head.push(element) },
118 + },
119 + });
120 + return head.find((element) => element.name === "color-scheme")?.content ?? "normal";
121 + };
122 + expect(initialScheme(`?a=1&${MCP_APP_COLOR_SCHEME_PARAM}=dark`)).toBe("dark");
123 + expect(initialScheme(`?${MCP_APP_COLOR_SCHEME_PARAM}=light`)).toBe("light");
124 + expect(initialScheme(`?${MCP_APP_COLOR_SCHEME_PARAM}=normal`)).toBe("normal");
125 + expect(initialScheme("")).toBe("normal");
126 + });
127 });
128
129 describe("readMcpAppCsp", () => {
packages/shared/src/mcpApp.ts
+12
@@ -5,6 +5,8 @@ export const MCP_APP_MIME_TYPE = "text/html;profile=mcp-app";
5 export const MCP_APP_EXTENSION_ID = "io.modelcontextprotocol/ui";
6 export const MCP_APP_RESOURCE_SCHEME = "ui://";
7 export const MCP_APP_OUTPUT_KEY = "t3McpApp";
8 +/** Frame URL query parameter carrying the host's color scheme before `ui/initialize`. */
9 +export const MCP_APP_COLOR_SCHEME_PARAM = "t3-color-scheme";
10
11 const MCP_APP_MIN_HEIGHT = 80;
12 export const MCP_APP_DEFAULT_HEIGHT = 320;
@@ -201,6 +203,16 @@ export function injectMcpAppCsp(html: string, csp: McpAppCsp | undefined): strin
203 export function injectMcpAppThemeBootstrap(html: string): string {
204 const script = `<script>
205 (() => {
206 + try {
207 + const initial = new URLSearchParams(location.search).get(${JSON.stringify(MCP_APP_COLOR_SCHEME_PARAM)});
208 + if (initial === "light" || initial === "dark") {
209 + // A meta tag, unlike an inline style, survives the app's own <html style> attribute.
210 + const meta = document.createElement("meta");
211 + meta.name = "color-scheme";
212 + meta.content = initial;
213 + document.head.append(meta);
214 + }
215 + } catch {}
216 window.addEventListener("message", (event) => {
217 if (event.source !== window.parent) return;
218 const message = event.data;