import React, { useCallback } from 'react'; import { Button } from '@librechat/client'; import { RefreshCw, Link } from 'lucide-react'; import { useMCPServerManager } from '~/hooks/MCP/useMCPServerManager'; import { useLocalize } from '~/hooks'; interface ServerInitializationSectionProps { serverName: string; requiresOAuth: boolean; } export default function ServerInitializationSection({ serverName, requiresOAuth, }: ServerInitializationSectionProps) { const localize = useLocalize(); // Use the centralized server manager instead of the old initialization hook so we can handle multiple oauth flows at once const { initializeServer, connectionStatus, cancelOAuthFlow, isInitializing, isCancellable, getOAuthUrl, } = useMCPServerManager(); const serverStatus = connectionStatus[serverName]; const isConnected = serverStatus?.connectionState === 'connected'; const canCancel = isCancellable(serverName); const isServerInitializing = isInitializing(serverName); const serverOAuthUrl = getOAuthUrl(serverName); const handleInitializeClick = useCallback(() => { initializeServer(serverName); }, [initializeServer, serverName]); const handleCancelClick = useCallback(() => { cancelOAuthFlow(serverName); }, [cancelOAuthFlow, serverName]); // Show subtle reinitialize option if connected if (isConnected) { return (
); } return (
{requiresOAuth ? localize('com_ui_mcp_not_authenticated', { 0: serverName }) : localize('com_ui_mcp_not_initialized', { 0: serverName })}
{/* Only show authenticate button when OAuth URL is not present */} {!serverOAuthUrl && ( )}
{/* OAuth URL display */} {serverOAuthUrl && (
{localize('com_ui_auth_url')}

{localize('com_ui_oauth_flow_desc')}

)}
); }