mirror of
https://github.com/danny-avila/LibreChat.git
synced 2025-12-29 22:58:51 +01:00
* 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
99 lines
3.6 KiB
TypeScript
99 lines
3.6 KiB
TypeScript
import { useState, useRef, useMemo } from 'react';
|
|
import { Plus } from 'lucide-react';
|
|
import { PermissionTypes, Permissions } from 'librechat-data-provider';
|
|
import { Button, Spinner, FilterInput, OGDialogTrigger, TooltipAnchor } from '@librechat/client';
|
|
import { useLocalize, useMCPServerManager, useHasAccess } from '~/hooks';
|
|
import MCPConfigDialog from '~/components/MCP/MCPConfigDialog';
|
|
import MCPAdminSettings from './MCPAdminSettings';
|
|
import MCPServerDialog from './MCPServerDialog';
|
|
import MCPServerList from './MCPServerList';
|
|
|
|
export default function MCPBuilderPanel() {
|
|
const localize = useLocalize();
|
|
const { availableMCPServers, isLoading, getServerStatusIconProps, getConfigDialogProps } =
|
|
useMCPServerManager();
|
|
|
|
const hasCreateAccess = useHasAccess({
|
|
permissionType: PermissionTypes.MCP_SERVERS,
|
|
permission: Permissions.CREATE,
|
|
});
|
|
const [showDialog, setShowDialog] = useState(false);
|
|
const [searchQuery, setSearchQuery] = useState('');
|
|
const addButtonRef = useRef<HTMLButtonElement | null>(null);
|
|
const configDialogProps = getConfigDialogProps();
|
|
|
|
const filteredServers = useMemo(() => {
|
|
if (!searchQuery.trim()) {
|
|
return availableMCPServers;
|
|
}
|
|
const query = searchQuery.toLowerCase();
|
|
return availableMCPServers.filter((server) => {
|
|
const displayName = server.config?.title || server.serverName;
|
|
return (
|
|
displayName.toLowerCase().includes(query) || server.serverName.toLowerCase().includes(query)
|
|
);
|
|
});
|
|
}, [availableMCPServers, searchQuery]);
|
|
|
|
return (
|
|
<div className="flex h-full w-full flex-col overflow-visible">
|
|
<div role="region" aria-label={localize('com_ui_mcp_servers')} className="mt-2 space-y-2">
|
|
{/* Toolbar: Search + Add Button */}
|
|
<div className="flex items-center gap-2">
|
|
<FilterInput
|
|
inputId="mcp-filter"
|
|
label={localize('com_ui_filter_mcp_servers')}
|
|
value={searchQuery}
|
|
onChange={(e) => setSearchQuery(e.target.value)}
|
|
containerClassName="flex-1"
|
|
/>
|
|
{hasCreateAccess && (
|
|
<MCPServerDialog
|
|
open={showDialog}
|
|
onOpenChange={setShowDialog}
|
|
triggerRef={addButtonRef}
|
|
>
|
|
<OGDialogTrigger asChild>
|
|
<TooltipAnchor
|
|
description={localize('com_ui_add_mcp')}
|
|
side="bottom"
|
|
render={
|
|
<Button
|
|
ref={addButtonRef}
|
|
variant="outline"
|
|
size="icon"
|
|
className="shrink-0 bg-transparent"
|
|
onClick={() => setShowDialog(true)}
|
|
aria-label={localize('com_ui_add_mcp')}
|
|
>
|
|
<Plus className="size-4" aria-hidden="true" />
|
|
</Button>
|
|
}
|
|
/>
|
|
</OGDialogTrigger>
|
|
</MCPServerDialog>
|
|
)}
|
|
</div>
|
|
|
|
{/* Server Cards List */}
|
|
{isLoading ? (
|
|
<div className="flex items-center justify-center p-8">
|
|
<Spinner className="size-6" aria-label={localize('com_ui_loading')} />
|
|
</div>
|
|
) : (
|
|
<MCPServerList
|
|
servers={filteredServers}
|
|
getServerStatusIconProps={getServerStatusIconProps}
|
|
isFiltered={searchQuery.trim().length > 0}
|
|
/>
|
|
)}
|
|
|
|
{/* Config Dialog for custom user vars */}
|
|
{configDialogProps && <MCPConfigDialog {...configDialogProps} />}
|
|
|
|
{/* Admin Settings Section */}
|
|
<MCPAdminSettings />
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|