mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-03-04 07:10:18 +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
|
|
@ -1,65 +1,44 @@
|
|||
import { useState, useRef } from 'react';
|
||||
import { GearIcon, MCPIcon, OGDialogTrigger } from '@librechat/client';
|
||||
import {
|
||||
PermissionBits,
|
||||
PermissionTypes,
|
||||
Permissions,
|
||||
hasPermissions,
|
||||
} from 'librechat-data-provider';
|
||||
import { useLocalize, useHasAccess, MCPServerDefinition } from '~/hooks';
|
||||
import MCPServerStatusIcon from '~/components/MCP/MCPServerStatusIcon';
|
||||
import MCPServerDialog from './MCPServerDialog';
|
||||
import { MCPIcon } from '@librechat/client';
|
||||
import { PermissionTypes, Permissions } from 'librechat-data-provider';
|
||||
import type { MCPServerStatusIconProps } from '~/components/MCP/MCPServerStatusIcon';
|
||||
import type { MCPServerDefinition } from '~/hooks';
|
||||
import { useLocalize, useHasAccess } from '~/hooks';
|
||||
import MCPServerCard from './MCPServerCard';
|
||||
|
||||
interface MCPServerListProps {
|
||||
servers: MCPServerDefinition[];
|
||||
getServerStatusIconProps: (
|
||||
serverName: string,
|
||||
) => React.ComponentProps<typeof MCPServerStatusIcon>;
|
||||
getServerStatusIconProps: (serverName: string) => MCPServerStatusIconProps;
|
||||
isFiltered?: boolean;
|
||||
}
|
||||
|
||||
// Self-contained edit button component (follows MemoryViewer pattern)
|
||||
const EditMCPServerButton = ({ server }: { server: MCPServerDefinition }) => {
|
||||
const localize = useLocalize();
|
||||
const [open, setOpen] = useState(false);
|
||||
const triggerRef = useRef<HTMLButtonElement>(null);
|
||||
|
||||
return (
|
||||
<MCPServerDialog open={open} onOpenChange={setOpen} triggerRef={triggerRef} server={server}>
|
||||
<OGDialogTrigger asChild>
|
||||
<button
|
||||
ref={triggerRef}
|
||||
onClick={() => setOpen(true)}
|
||||
className="flex h-5 w-5 items-center justify-center rounded hover:bg-surface-secondary"
|
||||
aria-label={localize('com_ui_edit')}
|
||||
>
|
||||
<GearIcon className="h-4 w-4" />
|
||||
</button>
|
||||
</OGDialogTrigger>
|
||||
</MCPServerDialog>
|
||||
);
|
||||
};
|
||||
|
||||
/**
|
||||
* Renders a list of MCP server cards with empty state handling
|
||||
*/
|
||||
export default function MCPServerList({
|
||||
servers,
|
||||
getServerStatusIconProps,
|
||||
isFiltered = false,
|
||||
}: MCPServerListProps) {
|
||||
const localize = useLocalize();
|
||||
const canCreateEditMCPs = useHasAccess({
|
||||
permissionType: PermissionTypes.MCP_SERVERS,
|
||||
permission: Permissions.CREATE,
|
||||
});
|
||||
const localize = useLocalize();
|
||||
|
||||
if (servers.length === 0) {
|
||||
return (
|
||||
<div className="rounded-lg border border-border-light bg-transparent p-8 text-center shadow-sm">
|
||||
<div className="flex flex-col items-center justify-center rounded-lg border border-border-light bg-transparent p-6 text-center">
|
||||
<div className="mb-2 flex size-10 items-center justify-center rounded-full bg-surface-tertiary">
|
||||
<MCPIcon className="size-5 text-text-secondary" aria-hidden="true" />
|
||||
</div>
|
||||
{isFiltered ? (
|
||||
<p className="text-sm text-text-secondary">{localize('com_ui_no_mcp_servers_match')}</p>
|
||||
) : (
|
||||
<>
|
||||
<p className="text-sm text-text-secondary">{localize('com_ui_no_mcp_servers')}</p>
|
||||
<p className="mt-1 text-xs text-text-tertiary">
|
||||
<p className="text-sm font-medium text-text-primary">
|
||||
{localize('com_ui_no_mcp_servers')}
|
||||
</p>
|
||||
<p className="mt-0.5 text-xs text-text-secondary">
|
||||
{localize('com_ui_add_first_mcp_server')}
|
||||
</p>
|
||||
</>
|
||||
|
|
@ -69,36 +48,16 @@ export default function MCPServerList({
|
|||
}
|
||||
|
||||
return (
|
||||
<div className="space-y-2">
|
||||
{servers.map((server) => {
|
||||
const canEditThisServer = hasPermissions(server.effectivePermissions, PermissionBits.EDIT);
|
||||
const displayName = server.config?.title || server.serverName;
|
||||
const serverKey = `key_${server.serverName}`;
|
||||
|
||||
return (
|
||||
<div key={serverKey} className="rounded-lg border border-border-light bg-transparent p-3">
|
||||
<div className="flex items-center gap-3">
|
||||
{/* Server Icon */}
|
||||
{server.config?.iconPath ? (
|
||||
<img src={server.config.iconPath} className="h-5 w-5 rounded" alt={displayName} />
|
||||
) : (
|
||||
<MCPIcon className="h-5 w-5" />
|
||||
)}
|
||||
|
||||
{/* Server Info */}
|
||||
<div className="min-w-0 flex-1">
|
||||
<h3 className="truncate font-semibold text-text-primary">{displayName}</h3>
|
||||
</div>
|
||||
|
||||
{/* Edit Button - Only for DB servers and when user has CREATE access */}
|
||||
{canCreateEditMCPs && canEditThisServer && <EditMCPServerButton server={server} />}
|
||||
|
||||
{/* Connection Status Icon */}
|
||||
<MCPServerStatusIcon {...getServerStatusIconProps(server.serverName)} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
<div className="space-y-2" role="list" aria-label={localize('com_ui_mcp_servers')}>
|
||||
{servers.map((server) => (
|
||||
<div key={`card_${server.serverName}`} role="listitem">
|
||||
<MCPServerCard
|
||||
server={server}
|
||||
getServerStatusIconProps={getServerStatusIconProps}
|
||||
canCreateEditMCPs={canCreateEditMCPs}
|
||||
/>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue