import React, { useState } from 'react'; import { toast } from 'react-toastify'; import { ConfirmModal } from './McpUi'; import { mcpApi, t } from './api'; type Props = { status: any; onChange: () => void; }; const STATE_LABELS: Record< string, [ string, string ] > = { off: [ 'mcp-state-off', 'Off' ], needs_attention: [ 'mcp-state-attention', 'Needs attention' ], ready: [ 'mcp-state-ready', 'Ready' ], connected: [ 'mcp-state-connected', 'Connected' ], }; /** * Section 1: Enable MCP with a status pill. */ const McpStatus = ( { status, onChange }: Props ) => { const [ saving, setSaving ] = useState( false ); const [ confirmOff, setConfirmOff ] = useState( false ); const enabled = !! status.settings.enabled; const label = STATE_LABELS[ status.state ] || STATE_LABELS.off; const save = async ( value: boolean, revokeAll = false ) => { setSaving( true ); try { const res = await mcpApi( 'settings', 'POST', { enabled: value, revoke_all: revokeAll } ); toast.success( value ? t( 'mcp-enabled-toast', 'MCP is on. Connect an AI client below.' ) : revokeAll ? t( 'mcp-disabled-revoked-toast', 'MCP is off and all MCP credentials were revoked.' ) : t( 'mcp-disabled-toast', 'MCP is off. AI clients can no longer connect.' ) ); if ( res && res.settings ) { onChange(); } } catch ( e: any ) { toast.error( e.message ); } finally { setSaving( false ); setConfirmOff( false ); } }; const onToggle = () => { if ( enabled ) { setConfirmOff( true ); } else { save( true ); } }; return (
{ t( 'mcp-intro', 'Let AI assistants such as Claude, ChatGPT (Codex), Cursor and VS Code create, style and publish FlexTable tables from public Google Sheets, using your WordPress permissions. Nothing is shared until you turn MCP on and connect a client.' ) }
{ t( 'mcp-off-note', 'While MCP is off, the MCP endpoint answers "mcp_disabled" and no AI client can read or change any table.' ) }
) } { confirmOff && (