mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-01-19 08:46:11 +01: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
152
client/src/components/SidePanel/MCPBuilder/MCPServerCard.tsx
Normal file
152
client/src/components/SidePanel/MCPBuilder/MCPServerCard.tsx
Normal file
|
|
@ -0,0 +1,152 @@
|
|||
import { useState, useRef } from 'react';
|
||||
import { MCPIcon } from '@librechat/client';
|
||||
import { PermissionBits, hasPermissions } from 'librechat-data-provider';
|
||||
import type { MCPServerStatusIconProps } from '~/components/MCP/MCPServerStatusIcon';
|
||||
import type { MCPServerDefinition } from '~/hooks';
|
||||
import MCPServerDialog from './MCPServerDialog';
|
||||
import { getStatusDotColor } from './MCPStatusBadge';
|
||||
import MCPCardActions from './MCPCardActions';
|
||||
import { useMCPServerManager, useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
interface MCPServerCardProps {
|
||||
server: MCPServerDefinition;
|
||||
getServerStatusIconProps: (serverName: string) => MCPServerStatusIconProps;
|
||||
canCreateEditMCPs: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compact card component for displaying an MCP server with status and actions.
|
||||
*
|
||||
* Visual design:
|
||||
* - Status shown via colored dot on icon (no separate badge - avoids redundancy)
|
||||
* - Action buttons clearly indicate available operations
|
||||
* - Consistent with MCPServerMenuItem in chat dropdown
|
||||
*/
|
||||
export default function MCPServerCard({
|
||||
server,
|
||||
getServerStatusIconProps,
|
||||
canCreateEditMCPs,
|
||||
}: MCPServerCardProps) {
|
||||
const localize = useLocalize();
|
||||
const { initializeServer } = useMCPServerManager();
|
||||
const [dialogOpen, setDialogOpen] = useState(false);
|
||||
const triggerRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
const statusIconProps = getServerStatusIconProps(server.serverName);
|
||||
const {
|
||||
serverStatus,
|
||||
onConfigClick,
|
||||
isInitializing,
|
||||
canCancel,
|
||||
onCancel,
|
||||
hasCustomUserVars = false,
|
||||
} = statusIconProps;
|
||||
|
||||
const canEditThisServer = hasPermissions(server.effectivePermissions, PermissionBits.EDIT);
|
||||
const displayName = server.config?.title || server.serverName;
|
||||
const description = server.config?.description;
|
||||
const statusDotColor = getStatusDotColor(serverStatus, isInitializing);
|
||||
const canEdit = canCreateEditMCPs && canEditThisServer;
|
||||
|
||||
const handleInitialize = () => {
|
||||
initializeServer(server.serverName);
|
||||
};
|
||||
|
||||
const handleEditClick = (e: React.MouseEvent) => {
|
||||
e.stopPropagation();
|
||||
e.preventDefault();
|
||||
setDialogOpen(true);
|
||||
};
|
||||
|
||||
// Determine status text for accessibility
|
||||
const getStatusText = () => {
|
||||
if (isInitializing) return localize('com_nav_mcp_status_initializing');
|
||||
if (!serverStatus) return localize('com_nav_mcp_status_unknown');
|
||||
const { connectionState, requiresOAuth } = serverStatus;
|
||||
if (connectionState === 'connected') return localize('com_nav_mcp_status_connected');
|
||||
if (connectionState === 'connecting') return localize('com_nav_mcp_status_connecting');
|
||||
if (connectionState === 'error') return localize('com_nav_mcp_status_error');
|
||||
if (connectionState === 'disconnected') {
|
||||
return requiresOAuth
|
||||
? localize('com_nav_mcp_status_needs_auth')
|
||||
: localize('com_nav_mcp_status_disconnected');
|
||||
}
|
||||
return localize('com_nav_mcp_status_unknown');
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={cn(
|
||||
'group flex items-center gap-3 rounded-lg px-3 py-2.5',
|
||||
'border border-border-light bg-transparent',
|
||||
)}
|
||||
aria-label={`${displayName} - ${getStatusText()}`}
|
||||
>
|
||||
{/* Server Icon with Status Dot */}
|
||||
<div className="relative flex-shrink-0">
|
||||
{server.config?.iconPath ? (
|
||||
<img
|
||||
src={server.config.iconPath}
|
||||
className="size-8 rounded-lg object-cover"
|
||||
alt=""
|
||||
aria-hidden="true"
|
||||
/>
|
||||
) : (
|
||||
<div className="flex size-8 items-center justify-center rounded-lg bg-surface-tertiary">
|
||||
<MCPIcon className="size-5 text-text-secondary" aria-hidden="true" />
|
||||
</div>
|
||||
)}
|
||||
{/* Status dot - color indicates connection state */}
|
||||
<div
|
||||
className={cn(
|
||||
'absolute -bottom-0.5 -right-0.5 size-3 rounded-full',
|
||||
'border-2 border-surface-primary',
|
||||
statusDotColor,
|
||||
(isInitializing || serverStatus?.connectionState === 'connecting') && 'animate-pulse',
|
||||
)}
|
||||
aria-hidden="true"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Server Info */}
|
||||
<div className="min-w-0 flex-1">
|
||||
<span className="truncate text-sm font-medium text-text-primary">{displayName}</span>
|
||||
{description && <p className="truncate text-xs text-text-secondary">{description}</p>}
|
||||
</div>
|
||||
|
||||
{/* Actions */}
|
||||
<div className="flex-shrink-0">
|
||||
<MCPCardActions
|
||||
serverName={server.serverName}
|
||||
serverStatus={serverStatus}
|
||||
isInitializing={isInitializing}
|
||||
canCancel={canCancel}
|
||||
hasCustomUserVars={hasCustomUserVars}
|
||||
canEdit={canEdit}
|
||||
onEditClick={handleEditClick}
|
||||
onConfigClick={onConfigClick}
|
||||
onInitialize={handleInitialize}
|
||||
onCancel={onCancel}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Edit Dialog - separate from card */}
|
||||
{canEdit && (
|
||||
<MCPServerDialog
|
||||
open={dialogOpen}
|
||||
onOpenChange={setDialogOpen}
|
||||
triggerRef={triggerRef}
|
||||
server={server}
|
||||
>
|
||||
{/* Hidden trigger for focus management */}
|
||||
<button ref={triggerRef} className="sr-only" tabIndex={-1} aria-hidden="true">
|
||||
{localize('com_ui_edit')} {displayName}
|
||||
</button>
|
||||
</MCPServerDialog>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue