Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix ChatGPT and Cursor dark theme override for MCP Apps (#74739)

Phoomparin Mano52c81f31f07d
diff --git a/frontend/src/metabase/embedding/mcp/McpUiAppRoute.tsx b/frontend/src/metabase/embedding/mcp/McpUiAppRoute.tsx
index ba6670cb340..2a7c21b6f95 100644
--- a/frontend/src/metabase/embedding/mcp/McpUiAppRoute.tsx
+++ b/frontend/src/metabase/embedding/mcp/McpUiAppRoute.tsx
@@ -60,8 +60,13 @@ export function McpUiAppRoute() {
);
const theme = useMemo(
- () => buildMcpAppsTheme(hostCssVariables, scheme),
- [hostCssVariables, scheme],
+ () =>
+ buildMcpAppsTheme({
+ hostCssVariables,
+ preset: scheme,
+ agentName: hostContext?.userAgent,
+ }),
+ [hostCssVariables, scheme, hostContext?.userAgent],
);
return (
diff --git a/frontend/src/metabase/embedding/mcp/utils/buildMcpAppsTheme.ts b/frontend/src/metabase/embedding/mcp/utils/buildMcpAppsTheme.ts
index 3ff8143dc3b..93442f37207 100644
--- a/frontend/src/metabase/embedding/mcp/utils/buildMcpAppsTheme.ts
+++ b/frontend/src/metabase/embedding/mcp/utils/buildMcpAppsTheme.ts
@@ -22,16 +22,67 @@ const MCP_HOST_VAR_TO_SDK_COLOR: Record<
"--color-text-tertiary": "text-tertiary",
};
-export function buildMcpAppsTheme(
- hostCssVariables: Record<string, string>,
- preset: ResolvedColorScheme,
-): MetabaseTheme {
+/**
+ * Per-agent CSS variable overrides, applied on top of what the host sends.
+ * Keyed by `hostContext.userAgent`. Each agent may define `light` and/or `dark`
+ * overrides; both are optional.
+ */
+const AGENT_CSS_VARIABLE_OVERRIDES: Record<
+ string,
+ Partial<Record<ResolvedColorScheme, Record<string, string>>>
+> = {
+ // ChatGPT does not send theming variables, so we have to
+ // provide them to match ChatGPT's looks.
+ chatgpt: {
+ light: {
+ "--color-background-primary": "#FFFFFF",
+ "--color-background-secondary": "#F9F9F9",
+ },
+ dark: {
+ "--color-background-primary": "#212121",
+ "--color-background-secondary": "#181818",
+ },
+ },
+
+ // Cursor's agents window does not send theming variables,
+ // so we can provide a default based on agents window's theme.
+ // Agents window only supports 2 themes, no custom theme.
+ cursor: {
+ light: {
+ "--color-background-primary": "#FFFFFF",
+ "--color-background-secondary": "#F8F8F8",
+ },
+ dark: {
+ "--color-background-primary": "#181818",
+ "--color-background-secondary": "#141414",
+ },
+ },
+};
+
+interface BuildMcpAppsThemeOptions {
+ hostCssVariables: Record<string, string>;
+ preset: ResolvedColorScheme;
+ agentName?: string;
+}
+
+export function buildMcpAppsTheme({
+ hostCssVariables,
+ preset,
+ agentName,
+}: BuildMcpAppsThemeOptions): MetabaseTheme {
+ const agentOverrides =
+ (agentName && AGENT_CSS_VARIABLE_OVERRIDES[agentName]?.[preset]) || {};
+
+ // Agent overrides serve as per-key defaults — any value the host actually
+ // sends takes precedence.
+ const mergedCssVariables = { ...agentOverrides, ...hostCssVariables };
+
const colors: MetabaseTheme["colors"] = {};
for (const [cssVarKey, sdkKey] of Object.entries(MCP_HOST_VAR_TO_SDK_COLOR)) {
- if (hostCssVariables[cssVarKey]) {
+ if (mergedCssVariables[cssVarKey]) {
colors[sdkKey] = resolveConcreteColor(
- hostCssVariables[cssVarKey],
+ mergedCssVariables[cssVarKey],
preset,
);
}
diff --git a/frontend/src/metabase/embedding/mcp/utils/buildMcpAppsTheme.unit.spec.ts b/frontend/src/metabase/embedding/mcp/utils/buildMcpAppsTheme.unit.spec.ts
new file mode 100644
index 00000000000..001a70c91ad
--- /dev/null
+++ b/frontend/src/metabase/embedding/mcp/utils/buildMcpAppsTheme.unit.spec.ts
@@ -0,0 +1,36 @@
+import { buildMcpAppsTheme } from "./buildMcpAppsTheme";
+
+describe("buildMcpAppsTheme", () => {
+ it("applies ChatGPT dark theme overrides", () => {
+ expect(
+ buildMcpAppsTheme({
+ hostCssVariables: {},
+ preset: "dark",
+ agentName: "chatgpt",
+ }),
+ ).toEqual({
+ preset: "dark",
+ colors: {
+ background: "#212121",
+ "background-secondary": "#181818",
+ },
+ });
+ });
+
+ it("lets host variables override ChatGPT theme defaults", () => {
+ expect(
+ buildMcpAppsTheme({
+ hostCssVariables: {
+ "--color-background-primary": "#000000",
+ },
+ preset: "dark",
+ agentName: "chatgpt",
+ }).colors,
+ ).toEqual(
+ expect.objectContaining({
+ background: "#000000",
+ "background-secondary": "#181818",
+ }),
+ );
+ });
+});
diff --git a/resources/frontend_client/mcp_apps_template.html b/resources/frontend_client/mcp_apps_template.html
index 3f462b67af5..f43a3808546 100644
--- a/resources/frontend_client/mcp_apps_template.html
+++ b/resources/frontend_client/mcp_apps_template.html
@@ -30,6 +30,9 @@
color: var(--vscode-foreground);
background: var(--vscode-editor-background);
font-family: var(--vscode-font-family);
+
+ /* Remove card padding from cursor */
+ padding: 0;
}
.mcp-loading {