Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(mcp-host): keep the dashboard theme mode the caller sets

marcoteb95345f3aa4af
diff --git a/mcp-host/src/workflow/__tests__/internalTools.dashboard.fidelity.test.ts b/mcp-host/src/workflow/__tests__/internalTools.dashboard.fidelity.test.ts
index e82ccffaa..f5c79269c 100644
--- a/mcp-host/src/workflow/__tests__/internalTools.dashboard.fidelity.test.ts
+++ b/mcp-host/src/workflow/__tests__/internalTools.dashboard.fidelity.test.ts
@@ -7,6 +7,7 @@ import { afterEach, beforeEach, describe, expect, it } from 'vitest'
import * as fs from 'fs'
import * as os from 'os'
import * as path from 'path'
+import { DASHBOARD_THEMES } from '../dashboardThemes'
import { INTERNAL_TOOLS } from '../internalTools'
import type { InternalToolResult } from '../types'
@@ -532,23 +533,28 @@ describe('section headings', () => {
})
describe('defaultThemeMode', () => {
- it('follows a light viewer when the default is dark', async () => {
- const { html } = await render({
- defaultThemeMode: 'dark',
- data: { title: 'T', kpis: [{ label: 'x', value: 1 }] },
- })
- const light =
- /@media \(prefers-color-scheme: light\) \{\s*:root:not\(\[data-theme\]\) \{([\s\S]*?)\}/.exec(
- html
- )
- expect(light).not.toBeNull()
- expect(light![1]).toContain('--bg: #')
- expect(html).not.toContain('@media (prefers-color-scheme: dark)')
+ const rootBackground = (html: string) => /:root \{[^}]*?--bg: (#[0-9a-f]+);/i.exec(html)![1]
+
+ it("keeps a mode that is set, whatever the viewer's color scheme", async () => {
+ const data = { title: 'T', kpis: [{ label: 'x', value: 1 }] }
+ const dark = (await render({ defaultThemeMode: 'dark', data })).html
+ const light = (await render({ defaultThemeMode: 'light', data })).html
+ expect(rootBackground(dark)).toBe(DASHBOARD_THEMES.default.dark.bg)
+ expect(rootBackground(light)).toBe(DASHBOARD_THEMES.default.light.bg)
+ for (const html of [dark, light]) expect(html).not.toContain('prefers-color-scheme')
+ // Print stays light.
+ const print = /@media print \{([\s\S]*?)\n\}/.exec(dark)![1]
+ expect(print).toContain(`--bg: ${DASHBOARD_THEMES.default.light.bg};`)
})
- it('follows a dark viewer when the default is light', async () => {
+ it("follows the viewer's color scheme when no mode is set", async () => {
const { html } = await render({ data: { title: 'T', kpis: [{ label: 'x', value: 1 }] } })
- expect(html).toContain('@media (prefers-color-scheme: dark)')
+ expect(rootBackground(html)).toBe(DASHBOARD_THEMES.default.light.bg)
+ const dark =
+ /@media \(prefers-color-scheme: dark\) \{\s*:root:not\(\[data-theme\]\) \{([\s\S]*?)\}/.exec(
+ html
+ )
+ expect(dark![1]).toContain(`--bg: ${DASHBOARD_THEMES.default.dark.bg};`)
expect(html).not.toContain('@media (prefers-color-scheme: light)')
})
})
diff --git a/mcp-host/src/workflow/internalTools.ts b/mcp-host/src/workflow/internalTools.ts
index b6270e6be..b39f6c289 100644
--- a/mcp-host/src/workflow/internalTools.ts
+++ b/mcp-host/src/workflow/internalTools.ts
@@ -3415,12 +3415,26 @@ function dashboardColorVars(c: DashboardThemeColors): string {
${c.chart.map((color, i) => `--chart-${i + 1}: ${color};`).join('\n ')}`.trim()
}
-function buildDashboardCss(theme: DashboardTheme, defaultMode: 'light' | 'dark' = 'light'): string {
+/**
+ * The page's styles. With no `mode` the page follows the viewer's color
+ * scheme; a mode given is kept whatever the viewer's scheme. Print is light.
+ */
+function buildDashboardCss(theme: DashboardTheme, mode?: 'light' | 'dark'): string {
const lightVars = dashboardColorVars(theme.light)
const darkVars = dashboardColorVars(theme.dark)
- const baseVars = defaultMode === 'dark' ? darkVars : lightVars
- const oppositeVars = defaultMode === 'dark' ? lightVars : darkVars
- const oppositeKey = defaultMode === 'dark' ? 'light' : 'dark'
+ const baseVars = mode === 'dark' ? darkVars : lightVars
+ const oppositeVars = mode === 'dark' ? lightVars : darkVars
+ const oppositeKey = mode === 'dark' ? 'light' : 'dark'
+ const viewerScheme =
+ mode === undefined
+ ? `
+@media (prefers-color-scheme: dark) {
+ :root:not([data-theme]) {
+ ${darkVars}
+ }
+}
+`
+ : ''
return `
*, *::before, *::after { box-sizing: border-box; }
@@ -3439,13 +3453,7 @@ html, body { margin: 0; padding: 0; }
[data-theme="${oppositeKey}"] {
${oppositeVars}
}
-
-@media (prefers-color-scheme: ${oppositeKey}) {
- :root:not([data-theme]) {
- ${oppositeVars}
- }
-}
-
+${viewerScheme}
body {
font-family: var(--font);
font-size: 15px;
@@ -4981,7 +4989,8 @@ interface DashboardRenderOptions {
template: DashboardTemplateName
data: DashData
theme: ThemeName
- defaultThemeMode: 'light' | 'dark'
+ /** Kept whatever the viewer's color scheme; when absent the page follows it. */
+ defaultThemeMode?: 'light' | 'dark'
branding: DashboardBranding
inlineChartJs: boolean
}
@@ -5286,7 +5295,7 @@ const generateDashboardTool: InternalToolDefinition = {
defaultThemeMode: {
type: 'string',
enum: ['light', 'dark'],
- description: "Default light; the viewer's color scheme still applies.",
+ description: "Omit to follow the viewer's color scheme; set to force it.",
},
inlineChartJs: {
type: 'boolean',
@@ -5484,7 +5493,10 @@ const generateDashboardTool: InternalToolDefinition = {
template,
data,
theme: oneOf(args.theme, ['default', 'corporate', 'warm', 'alert'] as const, 'default'),
- defaultThemeMode: oneOf(args.defaultThemeMode, ['light', 'dark'] as const, 'light'),
+ defaultThemeMode:
+ args.defaultThemeMode === 'light' || args.defaultThemeMode === 'dark'
+ ? args.defaultThemeMode
+ : undefined,
inlineChartJs,
branding: isDashRecord(args.branding) ? args.branding : {},
})