mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-04-02 22:07:19 +02:00
🔌 refactor: MCP UI with Improved Accessibility and Reusable Components (#11118)
* feat: enhance MCP server selection UI with new components and improved accessibility * fix(i18n): add missing com_ui_mcp_servers translation key The MCP server menu aria-label was referencing a non-existent translation key. Added the missing key for accessibility. * feat(MCP): enhance MCP components with improved accessibility and focus management * fix(i18n): remove outdated MCP server translation keys * fix(MCPServerList): improve color contrast by updating text color for no MCP servers message * refactor(MCP): Server status components and improve user action handling Updated MCPServerStatusIcon to use a unified icon system for better clarity Introduced new MCPCardActions component for standardized action buttons on server cards Created MCPServerCard component to encapsulate server display logic and actions Enhanced MCPServerList to render MCPServerCard components, improving code organization Added MCPStatusBadge for consistent status representation in dialogs Updated utility functions for status color and text retrieval to align with new design Improved localization keys for better clarity and consistency in user messages * style(MCP): update button and card background styles for improved UI consistency * feat(MCP): implement global server initialization state management using Jotai * refactor(MCP): modularize MCPServerDialog into structured component architecture - Split monolithic dialog into dedicated section components (Auth, BasicInfo, Connection, Transport, Trust) - Extract form logic into useMCPServerForm custom hook - Add utility modules for JSON import and URL handling - Introduce reusable SecretInput component in @librechat/client - Remove deprecated MCPAuth component * style(MCP): update button styles for improved layout and adjust empty state background color * refactor(Radio): enhance component mounting logic and background style updates * refactor(translation): remove unused keys and streamline localization strings
This commit is contained in:
parent
0b8e0fcede
commit
e4870ed0b0
32 changed files with 2594 additions and 1646 deletions
113
client/src/components/MCP/MCPServerMenuItem.tsx
Normal file
113
client/src/components/MCP/MCPServerMenuItem.tsx
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
import * as Ariakit from '@ariakit/react';
|
||||
import { Check } from 'lucide-react';
|
||||
import { MCPIcon } from '@librechat/client';
|
||||
import type { MCPServerDefinition } from '~/hooks/MCP/useMCPServerManager';
|
||||
import type { MCPServerStatusIconProps } from './MCPServerStatusIcon';
|
||||
import MCPServerStatusIcon from './MCPServerStatusIcon';
|
||||
import {
|
||||
getStatusColor,
|
||||
getStatusTextKey,
|
||||
shouldShowActionButton,
|
||||
type ConnectionStatusMap,
|
||||
} from './mcpServerUtils';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
interface MCPServerMenuItemProps {
|
||||
server: MCPServerDefinition;
|
||||
isSelected: boolean;
|
||||
connectionStatus?: ConnectionStatusMap;
|
||||
isInitializing?: (serverName: string) => boolean;
|
||||
statusIconProps?: MCPServerStatusIconProps | null;
|
||||
onToggle: (serverName: string) => void;
|
||||
}
|
||||
|
||||
export default function MCPServerMenuItem({
|
||||
server,
|
||||
isSelected,
|
||||
connectionStatus,
|
||||
isInitializing,
|
||||
statusIconProps,
|
||||
onToggle,
|
||||
}: MCPServerMenuItemProps) {
|
||||
const localize = useLocalize();
|
||||
const displayName = server.config?.title || server.serverName;
|
||||
const statusColor = getStatusColor(server.serverName, connectionStatus, isInitializing);
|
||||
const statusTextKey = getStatusTextKey(server.serverName, connectionStatus, isInitializing);
|
||||
const statusText = localize(statusTextKey as Parameters<typeof localize>[0]);
|
||||
const showActionButton = shouldShowActionButton(statusIconProps);
|
||||
|
||||
// Include status in aria-label so screen readers announce it
|
||||
const accessibleLabel = `${displayName}, ${statusText}`;
|
||||
|
||||
return (
|
||||
<Ariakit.MenuItemCheckbox
|
||||
hideOnClick={false}
|
||||
name="mcp-servers"
|
||||
value={server.serverName}
|
||||
checked={isSelected}
|
||||
setValueOnChange={false}
|
||||
onChange={() => onToggle(server.serverName)}
|
||||
aria-label={accessibleLabel}
|
||||
className={cn(
|
||||
'group flex w-full cursor-pointer items-center gap-3 rounded-lg px-2.5 py-2',
|
||||
'outline-none transition-all duration-150',
|
||||
'hover:bg-surface-hover data-[active-item]:bg-surface-hover',
|
||||
isSelected && 'bg-surface-active-alt',
|
||||
)}
|
||||
>
|
||||
{/* Server Icon with Status Dot */}
|
||||
<div className="relative flex-shrink-0">
|
||||
{server.config?.iconPath ? (
|
||||
<img
|
||||
src={server.config.iconPath}
|
||||
className="h-8 w-8 rounded-lg object-cover"
|
||||
alt={displayName}
|
||||
/>
|
||||
) : (
|
||||
<div className="flex h-8 w-8 items-center justify-center rounded-lg bg-surface-tertiary">
|
||||
<MCPIcon className="h-5 w-5 text-text-secondary" />
|
||||
</div>
|
||||
)}
|
||||
{/* Status dot - decorative, status is announced via aria-label on MenuItem */}
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
'absolute -bottom-0.5 -right-0.5 h-3 w-3 rounded-full border-2 border-surface-secondary',
|
||||
statusColor,
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Server Info */}
|
||||
<div className="min-w-0 flex-1">
|
||||
<div className="flex items-center gap-1.5">
|
||||
<span className="truncate text-sm font-medium text-text-primary">{displayName}</span>
|
||||
</div>
|
||||
{server.config?.description && (
|
||||
<p className="truncate text-xs text-text-secondary">{server.config.description}</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Action Button - only show when actionable */}
|
||||
{showActionButton && statusIconProps && (
|
||||
<div className="flex-shrink-0" onClick={(e) => e.stopPropagation()}>
|
||||
<MCPServerStatusIcon {...statusIconProps} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Selection Indicator - purely visual, state conveyed by aria-checked on MenuItem */}
|
||||
<span
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
'flex h-4 w-4 flex-shrink-0 items-center justify-center rounded-sm border',
|
||||
isSelected
|
||||
? 'border-primary bg-primary text-primary-foreground'
|
||||
: 'border-border-xheavy bg-transparent',
|
||||
)}
|
||||
>
|
||||
{isSelected && <Check className="h-4 w-4" />}
|
||||
</span>
|
||||
</Ariakit.MenuItemCheckbox>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue