import React, { useEffect, useState } from 'react'; import { Notice, Skeleton, Spinner } from './McpUi'; import { toast } from 'react-toastify'; import CopyButton from './CopyButton'; import { expiryLabel } from './McpSecurity'; import { mcpApi, t } from './api'; type Props = { status: any; onGenerated: () => void; }; /** * Section 6: Connect an AI client (Generate prompt / Copy prompt). */ const McpConnectClient = ( { status, onGenerated }: Props ) => { const [ tabs, setTabs ] = useState< any[] >( [] ); const [ verifiedOn, setVerifiedOn ] = useState( '' ); const [ active, setActive ] = useState( 'claude-code' ); const [ ack, setAck ] = useState( false ); const [ expiry, setExpiry ] = useState< number >( status.settings.expiry_days ); const [ publicUrl, setPublicUrl ] = useState( '' ); const [ busy, setBusy ] = useState( false ); const [ generated, setGenerated ] = useState< any >( null ); useEffect( () => { mcpApi( 'connect-prompts' ) .then( ( res ) => { setTabs( res.tabs || [] ); setVerifiedOn( res.verified_on || '' ); } ) .catch( ( e ) => toast.error( e.message ) ); }, [] ); useEffect( () => setExpiry( status.settings.expiry_days ), [ status.settings.expiry_days ] ); const tab = tabs.find( ( item ) => item.client === active ) || tabs[ 0 ]; const shown = generated && tab && generated.client === tab.client ? generated : null; const enabled = !! status.settings.enabled; const switchTab = ( client: string ) => { setActive( client ); setAck( false ); }; const generate = async () => { if ( ! tab ) { return; } setBusy( true ); try { const res = await mcpApi( 'connect/generate', 'POST', { client: tab.client, expiry_days: Number( expiry ), acknowledged: ack, public_url: 'claude-ai' === tab.client ? publicUrl : '', } ); setGenerated( res ); setAck( false ); onGenerated(); toast.success( t( 'mcp-generated', 'Credential created. Copy the prompt now: it is shown only once.' ) ); } catch ( e: any ) { toast.error( e.message ); } finally { setBusy( false ); } }; return (

{ t( 'mcp-connect', 'Connect an AI client' ) }

{ t( 'mcp-connect-desc', 'Pick your client, then Generate prompt. You get a ready-to-paste prompt (or command) with a credential that works only on this MCP endpoint. Paste it into your AI assistant and it sets everything up.' ) }

{ tabs.map( ( item ) => ( ) ) }
{ ! tab && } { tab && (

{ tab.summary }

{ 'claude-ai' === tab.client && (
setPublicUrl( e.target.value ) } /> { t( 'mcp-public-url-desc', 'Use this when the site is reached through a tunnel or another public address.' ) }
) }
{ shown && }
{ ! enabled &&

{ t( 'mcp-generate-off', 'Turn on MCP to generate a credential.' ) }

} { verifiedOn &&

{ t( 'mcp-verified-on', 'Instructions checked on' ) } { verifiedOn }

}
{ shown && ( { t( 'mcp-shown-once', 'Shown once. This prompt contains a working credential. Copy it now and treat it like a password: do not paste it into shared chats, tickets or screenshots.' ) } ) }
							{ shown ? shown.prompt : tab.template }
						
) }
); }; export default McpConnectClient;