🎨 fix: Color Pressed MCP Tool Option Toggles With Their Series Role (#16524)

* fix: color pressed MCP tool option toggles with their series role

* fix: keep a series border and tested hover surface on pressed MCP option toggles
This commit is contained in:
Marco Beretta 2026-09-30 00:21:53 +02:00 • committed by GitHub
parent 3e19b1876e
commit ad28144cb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 279 additions and 47 deletions

View file

@ -88,7 +88,7 @@ export default function MCPToolItem({
pressed={isDeferred}
label={localize('com_ui_mcp_defer_loading')}
tooltip={localize('com_ui_mcp_click_to_defer')}
activeBorderClass="border-series-4"
activeClass="border-series-4 text-series-4 hover:text-series-4"
onToggle={onToggleDefer}
/>
)}
@ -102,7 +102,7 @@ export default function MCPToolItem({
? 'com_ui_mcp_click_to_programmatic'
: 'com_ui_mcp_programmatic_requires_code',
)}
activeBorderClass="border-series-6"
activeClass="border-series-6 text-series-6 hover:text-series-6"
disabled={!programmaticToolsAvailable && !isProgrammatic}
onToggle={onToggleProgrammatic}
/>
@ -113,7 +113,7 @@ export default function MCPToolItem({
pressed={isBackground}
label={localize('com_ui_mcp_background')}
tooltip={localize('com_ui_mcp_click_to_background')}
activeBorderClass="border-series-1"
activeClass="border-series-1 text-series-1 hover:text-series-1"
onToggle={onToggleBackground}
/>
)}
@ -126,7 +126,7 @@ export default function MCPToolItem({
tooltip={localize(
intentDisabled ? 'com_ui_mcp_intent_programmatic' : 'com_ui_mcp_click_to_intent',
)}
activeBorderClass="border-series-3"
activeClass="border-series-3 text-series-3 hover:text-series-3"
onToggle={onToggleIntent}
/>
)}

View file

@ -8,8 +8,12 @@ interface OptionToggleProps {
label: string;
/** Defaults to `label` (bulk toggles use the same text for both). */
tooltip?: string;
/** Semantic series border applied to the pressed button. */
activeBorderClass: string;
/**
* Semantic series border and text color, including the hover text, applied
* when pressed. The border is the non-color cue: pressed and unpressed differ
* by its presence, not only by hue.
*/
activeClass: string;
onToggle: () => void;
size?: 'sm' | 'md';
/**
@ -30,7 +34,7 @@ export default function OptionToggle({
pressed,
label,
tooltip,
activeBorderClass,
activeClass,
onToggle,
size = 'sm',
disabled = false,
@ -44,12 +48,11 @@ export default function OptionToggle({
*/
let stateClass: string;
if (pressed) {
/** `surface-tertiary` is one of the surfaces the series scale is held to
* 3:1 on; the ghost `surface-hover` drops some slots below it in light. */
stateClass = cn(
activeBorderClass,
'bg-surface-active text-text-primary',
disabled
? 'cursor-not-allowed opacity-60 hover:bg-surface-active hover:text-text-primary'
: 'hover:bg-surface-active-alt hover:text-text-primary',
activeClass,
disabled ? 'cursor-not-allowed opacity-60 hover:bg-transparent' : 'hover:bg-surface-tertiary',
);
} else if (disabled) {
stateClass =

View file

@ -576,8 +576,8 @@ describe('McpSection', () => {
expect(screen.getByRole('button', { name: 'com_ui_mcp_unbackground_all' })).toHaveClass(
'border-series-1',
'bg-surface-active',
'text-text-primary',
'text-series-1',
'hover:text-series-1',
);
});

View file

@ -490,7 +490,7 @@ export default function McpSection({ item }: Props) {
size="md"
pressed={allDeferred}
label={localize(allDeferred ? 'com_ui_mcp_undefer_all' : 'com_ui_mcp_defer_all')}
activeBorderClass="border-series-4"
activeClass="border-series-4 text-series-4 hover:text-series-4"
onToggle={() => toggleDeferAll(tools)}
/>
)}
@ -500,7 +500,7 @@ export default function McpSection({ item }: Props) {
size="md"
pressed={allProgrammatic}
label={programmaticBulkLabel}
activeBorderClass="border-series-6"
activeClass="border-series-6 text-series-6 hover:text-series-6"
tooltip={programmaticBulkTooltip}
disabled={!programmaticToolsAvailable && !allProgrammatic}
onToggle={() => toggleProgrammaticAll(tools)}
@ -514,7 +514,7 @@ export default function McpSection({ item }: Props) {
label={localize(
allBackground ? 'com_ui_mcp_unbackground_all' : 'com_ui_mcp_background_all',
)}
activeBorderClass="border-series-1"
activeClass="border-series-1 text-series-1 hover:text-series-1"
onToggle={() => toggleBackgroundAll(tools)}
/>
)}
@ -525,7 +525,7 @@ export default function McpSection({ item }: Props) {
pressed={allIntent}
disabled={intentEligibleTools.length === 0}
label={localize(allIntent ? 'com_ui_mcp_unintent_all' : 'com_ui_mcp_intent_all')}
activeBorderClass="border-series-3"
activeClass="border-series-3 text-series-3 hover:text-series-3"
onToggle={() => toggleIntentAll(intentEligibleTools)}
/>
)}

View file

@ -28,13 +28,13 @@ const pressedOptions: Array<{
name: string;
overrides: Partial<React.ComponentProps<typeof MCPToolItem>>;
label: string;
border: string;
color: string;
}> = [
{
name: 'deferred',
overrides: { deferredToolsEnabled: true, isDeferred: true },
label: 'com_ui_mcp_defer_loading',
border: 'border-series-4',
color: 'text-series-4',
},
{
name: 'programmatic',
@ -44,19 +44,19 @@ const pressedOptions: Array<{
isProgrammatic: true,
},
label: 'com_ui_mcp_programmatic',
border: 'border-series-6',
color: 'text-series-6',
},
{
name: 'background',
overrides: { backgroundToolsEnabled: true, isBackground: true },
label: 'com_ui_mcp_background',
border: 'border-series-1',
color: 'text-series-1',
},
{
name: 'intent',
overrides: { toolIntentsEnabled: true, isIntent: true },
label: 'com_ui_mcp_intent',
border: 'border-series-3',
color: 'text-series-3',
},
];
@ -130,20 +130,23 @@ describe('MCPToolItem', () => {
expect(props.onToggleDefer).toHaveBeenCalledTimes(1);
});
test.each(pressedOptions)('$name option uses a semantic pressed-state border', (option) => {
setup(option.overrides);
const button = screen.getByRole('button', { name: option.label });
test.each(pressedOptions)(
'$name option uses its semantic series border and color when pressed',
(option) => {
setup(option.overrides);
const button = screen.getByRole('button', { name: option.label });
expect(button).toHaveClass(
option.border,
'bg-surface-active',
'text-text-primary',
'hover:bg-surface-active-alt',
);
expect(button.querySelector('svg')?.className.baseVal).not.toMatch(
/text-(?:amber|violet|sky|teal)-/,
);
});
expect(button).toHaveClass(
option.color,
`hover:${option.color}`,
option.color.replace('text-', 'border-'),
);
expect(button).not.toHaveClass('bg-surface-active', 'text-text-primary');
expect(button.querySelector('svg')?.className.baseVal).not.toMatch(
/text-(?:amber|violet|sky|teal)-/,
);
},
);
test('defer button is absent when deferred tools are disabled', () => {
setup();

View file

@ -17,13 +17,13 @@ jest.mock('@librechat/client', () => ({
}));
describe('OptionToggle', () => {
it('gives the pressed state a semantic surface, foreground, and series border', () => {
it('marks the pressed state with a series border and icon color, not an active surface', () => {
render(
<OptionToggle
icon={Circle}
pressed={true}
label="Background"
activeBorderClass="border-series-1"
activeClass="border-series-1 text-series-1 hover:text-series-1"
onToggle={jest.fn()}
/>,
);
@ -33,12 +33,12 @@ describe('OptionToggle', () => {
expect(button).toHaveClass(
'border',
'border-series-1',
'bg-surface-active',
'text-text-primary',
'hover:bg-surface-active-alt',
'text-series-1',
'hover:text-series-1',
'hover:bg-surface-tertiary',
);
expect(button).not.toHaveClass('border-transparent', 'bg-surface-active', 'text-text-primary');
expect(button.querySelector('svg')).toHaveClass('size-4');
expect(button.querySelector('svg')).not.toHaveClass('text-series-1');
});
it('keeps the unpressed state neutral and transparent', () => {
@ -47,7 +47,7 @@ describe('OptionToggle', () => {
icon={Circle}
pressed={false}
label="Background"
activeBorderClass="border-series-1"
activeClass="border-series-1 text-series-1 hover:text-series-1"
onToggle={jest.fn()}
/>,
);
@ -55,7 +55,7 @@ describe('OptionToggle', () => {
const button = screen.getByRole('button', { name: 'Background' });
expect(button).toHaveAttribute('aria-pressed', 'false');
expect(button).toHaveClass('border-transparent', 'text-text-secondary');
expect(button).not.toHaveClass('border-series-1', 'bg-surface-active');
expect(button).not.toHaveClass('border-series-1', 'text-series-1', 'bg-surface-active');
});
/** A tool switched to programmatic-only keeps its stored Intent state and
@ -68,14 +68,14 @@ describe('OptionToggle', () => {
pressed={true}
disabled={true}
label="Intent"
activeBorderClass="border-series-1"
activeClass="border-series-1 text-series-1 hover:text-series-1"
onToggle={jest.fn()}
/>,
);
const button = screen.getByRole('button', { name: 'Intent' });
expect(button).toHaveAttribute('aria-pressed', 'true');
expect(button).toHaveClass('border-series-1', 'bg-surface-active', 'cursor-not-allowed');
expect(button).not.toHaveClass('border-transparent');
expect(button).toHaveClass('border-series-1', 'text-series-1', 'cursor-not-allowed');
expect(button).not.toHaveClass('text-text-tertiary');
});
});

View file

@ -0,0 +1,226 @@
import { expect, test } from '@playwright/test';
import type { Locator, Page } from '@playwright/test';
import type { AgentDetail } from '../agents.helpers';
import { cleanupAgent, openAgentBuilder, uniqueAgentName } from '../agents.helpers';
import { MOCK_ENDPOINTS, fetchJson, getAccessToken, requestJson } from '../helpers';
const SERVER = 'e2e-memory';
/** The fixture registers some tools conditionally, so the seed takes the
* server's live list and only relies on these two. */
const REQUIRED_TOOLS = ['recall_fact', 'slow_echo'];
const toolId = (name: string) => `${name}_mcp_${SERVER}`;
const SERVER_TOOL_ID = `sys__server__sys_mcp_${SERVER}`;
/** WCAG 1.4.11 non-text contrast floor the series scale is held to. */
const MARK_MIN = 3;
type MCPToolsResponse = {
servers?: Record<string, { tools?: Array<{ pluginKey: string }> }>;
};
type Paint = { color: string; border: string; background: string; ratio: number };
async function waitForServerTools(page: Page): Promise<string[]> {
const token = await getAccessToken(page);
let toolIds: string[] = [];
await expect
.poll(
async () => {
const tools = await fetchJson<MCPToolsResponse>(page, '/api/mcp/tools', token);
toolIds = (tools.servers?.[SERVER]?.tools ?? []).map((tool) => tool.pluginKey);
return toolIds;
},
{ timeout: 20000 },
)
.toEqual(expect.arrayContaining(REQUIRED_TOOLS.map(toolId)));
return toolIds;
}
/** Every tool is deferred so the bulk Defer toggle restores pressed; only
* `slow_echo` runs in the background so bulk and per-tool Background differ. */
async function seedAgent(page: Page, toolIds: string[]): Promise<AgentDetail> {
const token = await getAccessToken(page);
const toolOptions = Object.fromEntries(
toolIds.map((id) => [
id,
id === toolId('slow_echo')
? { defer_loading: true, run_in_background: true }
: { defer_loading: true },
]),
);
return requestJson<AgentDetail>(page, {
path: '/api/agents',
token,
method: 'POST',
body: {
name: uniqueAgentName('E2E Option Colors'),
instructions: 'Reply through the mock e2e model.',
provider: MOCK_ENDPOINTS[0].label,
model: MOCK_ENDPOINTS[0].model,
tools: [SERVER_TOOL_ID, ...toolIds],
tool_options: toolOptions,
},
});
}
async function openServerDialog(page: Page, agentName: string): Promise<Locator> {
const form = await openAgentBuilder(page);
await form.getByRole('combobox', { name: 'Agent', exact: true }).click();
await page.getByRole('option', { name: agentName }).click();
await expect(form.getByLabel('Agent name')).toHaveValue(agentName);
await form.getByRole('button', { name: 'Add tools' }).click();
const library = page.getByRole('dialog', { name: 'Tool Library' });
await expect(library).toBeVisible();
await library.getByRole('textbox', { name: 'Search tools…' }).fill(SERVER);
await library.getByRole('button', { name: 'Configure', exact: true }).first().click();
const dialog = page.getByRole('dialog', { name: /e2e-memory|E2E Memory/i });
await expect(dialog.getByRole('button', { name: 'slow_echo', exact: true })).toBeVisible({
timeout: 20000,
});
return dialog;
}
/** The per-tool toggles share the row with the tool's select button. */
function rowToggle(dialog: Locator, tool: string, label: string): Locator {
return dialog
.getByRole('button', { name: tool, exact: true })
.locator('..')
.getByRole('button', { name: label, exact: true });
}
/** Resolves the icon color, border color, and the first opaque background
* under the button, then the contrast between icon and that background. */
function paint(toggle: Locator): Promise<Paint> {
return toggle.evaluate((element) => {
const parse = (value: string) => (value.match(/[\d.]+/g) ?? []).map(Number);
const channel = (value: number) => {
const v = value / 255;
return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
};
const luminance = ([r, g, b]: number[]) =>
0.2126 * channel(r) + 0.7152 * channel(g) + 0.0722 * channel(b);
const style = getComputedStyle(element);
let background = 'rgba(0, 0, 0, 0)';
for (let node: Element | null = element; node; node = node.parentElement) {
const candidate = getComputedStyle(node).backgroundColor;
const alpha = parse(candidate)[3];
if (alpha === undefined || alpha > 0) {
background = candidate;
break;
}
}
const [light, dark] = [luminance(parse(style.color)), luminance(parse(background))].sort(
(a, b) => b - a,
);
return {
color: style.color,
border: style.borderTopColor,
background: style.backgroundColor,
ratio: (light + 0.05) / (dark + 0.05),
};
});
}
const isTransparent = (value: string) => /rgba\(.*,\s*0\)$/.test(value) || value === 'transparent';
async function expectPressed(toggle: Locator) {
await expect(toggle).toHaveAttribute('aria-pressed', 'true');
/** Colors transition on toggle, so wait for the border to settle on the icon color. */
await expect
.poll(async () => {
const { border, color } = await paint(toggle);
return !isTransparent(border) && border === color;
})
.toBe(true);
const result = await paint(toggle);
expect(isTransparent(result.background)).toBe(true);
expect(result.ratio).toBeGreaterThanOrEqual(MARK_MIN);
}
async function expectUnpressed(toggle: Locator, pressedColor: string) {
await expect(toggle).toHaveAttribute('aria-pressed', 'false');
await expect.poll(async () => isTransparent((await paint(toggle)).border)).toBe(true);
const result = await paint(toggle);
expect(result.color).not.toBe(pressedColor);
expect(isTransparent(result.background)).toBe(true);
}
test.describe('MCP tool option colors', () => {
let agent: AgentDetail | undefined;
test.beforeEach(async ({ page }) => {
await page.goto('/c/new', { timeout: 10000 });
agent = await seedAgent(page, await waitForServerTools(page));
});
test.afterEach(async ({ page }) => {
await cleanupAgent(page, agent?.id);
});
test('saved options open pressed in their series color @scenario:saved-mcp-options-open-pressed-in-series-color', async ({
page,
}) => {
const dialog = await openServerDialog(page, agent!.name!);
await expectPressed(dialog.getByRole('button', { name: 'Undefer all tools', exact: true }));
await expectPressed(rowToggle(dialog, 'slow_echo', 'Defer loading'));
await expectPressed(rowToggle(dialog, 'slow_echo', 'Background'));
const defer = await paint(rowToggle(dialog, 'slow_echo', 'Defer loading'));
const background = await paint(rowToggle(dialog, 'slow_echo', 'Background'));
expect(defer.color).not.toBe(background.color);
});
test('an option left off stays neutral @scenario:unpressed-mcp-option-stays-neutral', async ({
page,
}) => {
const dialog = await openServerDialog(page, agent!.name!);
const pressed = await paint(rowToggle(dialog, 'slow_echo', 'Background'));
await expectUnpressed(rowToggle(dialog, 'recall_fact', 'Background'), pressed.color);
await expectUnpressed(
dialog.getByRole('button', { name: 'Mark all as background', exact: true }),
pressed.color,
);
});
test('hovering a pressed option keeps its icon contrast @scenario:pressed-mcp-option-hover-keeps-contrast', async ({
page,
}) => {
const dialog = await openServerDialog(page, agent!.name!);
for (const toggle of [
rowToggle(dialog, 'slow_echo', 'Defer loading'),
rowToggle(dialog, 'slow_echo', 'Background'),
dialog.getByRole('button', { name: 'Undefer all tools', exact: true }),
]) {
const rest = await paint(toggle);
await toggle.hover();
await expect.poll(async () => (await paint(toggle)).background).not.toBe(rest.background);
/** The hover surface fades in; the resting value is what a user sees. */
await expect
.poll(async () => (await paint(toggle)).ratio, { timeout: 5000 })
.toBeGreaterThanOrEqual(MARK_MIN);
const hovered = await paint(toggle);
expect(hovered.color).toBe(rest.color);
}
});
test('keyboard toggling flips the option treatment @scenario:keyboard-toggle-flips-mcp-option-treatment', async ({
page,
}) => {
const dialog = await openServerDialog(page, agent!.name!);
const pressedColor = (await paint(rowToggle(dialog, 'slow_echo', 'Background'))).color;
const toggle = rowToggle(dialog, 'recall_fact', 'Background');
await toggle.focus();
await page.keyboard.press('Space');
await expectPressed(toggle);
await expect.poll(async () => (await paint(toggle)).color).toBe(pressedColor);
await page.keyboard.press('Space');
await expectUnpressed(toggle, pressedColor);
});
});