import React, { useState } from 'react'; import { Spinner } from './McpUi'; import { toast } from 'react-toastify'; import { mcpApi, t } from './api'; const ICONS: Record< string, string > = { pass: '✓', warn: '!', fail: '✕', info: 'i', }; /** * Section 4: Connection test. */ const McpSelfTest = ( { enabled }: { enabled: boolean } ) => { const [ running, setRunning ] = useState( false ); const [ result, setResult ] = useState< any >( null ); const run = async () => { setRunning( true ); try { setResult( await mcpApi( 'self-test', 'POST' ) ); } catch ( e: any ) { toast.error( e.message ); } finally { setRunning( false ); } }; return (

{ t( 'mcp-test', 'Connection test' ) }

{ t( 'mcp-test-desc', 'Checks the MCP endpoint from this server: HTTPS, the MCP handshake, tool discovery, that requests without a credential are refused, and that nothing is changed. No credential is created or shown.' ) }

{ ! enabled && ! result &&

{ t( 'mcp-test-off', 'Turn on MCP to run all checks.' ) }

} { result && ( <>
{ result.ok ? t( 'mcp-test-ok', 'All required checks passed.' ) : t( 'mcp-test-fail', 'Some checks failed. See the fixes below.' ) }

{ result.note }

) }
); }; export default McpSelfTest;