import React, { useEffect, useState } from 'react'; import { Notice } from './McpUi'; import { toast } from 'react-toastify'; import { mcpApi, t } from './api'; type Props = { status: any; onChange: () => void; }; export const expiryLabel = ( days: number ): string => { if ( 0 === days ) { return t( 'mcp-expiry-never', 'Never' ); } return `${ days } ${ t( 'mcp-days', 'days' ) }`; }; /** * Section 3: Credentials (strict mode, default expiry) and policies. */ const McpSecurity = ( { status, onChange }: Props ) => { const [ form, setForm ] = useState( status.settings ); const [ saving, setSaving ] = useState( false ); useEffect( () => setForm( status.settings ), [ status.settings ] ); const dirty = JSON.stringify( form ) !== JSON.stringify( status.settings ); const save = async () => { setSaving( true ); try { await mcpApi( 'settings', 'POST', { strict: form.strict, expiry_days: Number( form.expiry_days ), publishing: form.publishing, allow_deletes: form.allow_deletes, data_reads: form.data_reads, } ); toast.success( t( 'mcp-saved', 'MCP settings saved.' ) ); onChange(); } catch ( e: any ) { toast.error( e.message ); } finally { setSaving( false ); } }; return (

{ t( 'mcp-security', 'Credentials and policies' ) }

{ ! status.app_passwords_available && ( { t( 'mcp-app-passwords-off', 'Application Passwords are not available on this site, so credentials cannot be generated. WordPress needs HTTPS (or a local environment), and some security plugins turn them off.' ) } ) }
{ t( 'mcp-publishing-desc', 'With "Drafts only", AI clients can create draft pages and edit drafts, but never publish or change live content.' ) }
); }; export default McpSecurity;