get_error_message() );
return;
}
self::notice(
'success',
'forget' === $action
? __( 'Client record removed.', 'acrossai-mcp-manager' )
: (string) $result
);
}
/**
* Render the global screen.
*
* @since 0.4.8
* @return void
*/
public function render(): void {
if ( ! current_user_can( 'manage_options' ) ) {
wp_die( esc_html__( 'You do not have permission to view MCP clients.', 'acrossai-mcp-manager' ) );
}
self::maybe_handle_action();
echo '
';
echo '
' . esc_html__( 'MCP Clients', 'acrossai-mcp-manager' ) . '
';
echo '
'
. esc_html__( 'Every AI client, bridge and paired site that has connected to your MCP servers. Rows are kept after a client stops calling, so this outlives the activity log.', 'acrossai-mcp-manager' )
. '
';
self::render_table( 0 );
echo '
';
}
/**
* Render the stat line, any pending notice, and the table.
*
* Shared between this screen and the per-server tab so the two cannot
* drift — the only difference is the scope.
*
* @since 0.4.8
* @param int $server_id Scope to one server, or 0 for every server.
* @return void
*/
public static function render_table( int $server_id ): void {
self::render_notice();
self::render_failure_warning();
self::render_summary( $server_id );
$table = new ClientsListTable( $server_id );
$table->prepare_items();
$table->display();
}
/**
* The counts above the table.
*
* @since 0.4.8
* @param int $server_id Scope, or 0 for all.
* @return void
*/
private static function render_summary( int $server_id ): void {
$summary = ClientsQuery::instance()->summary( $server_id, self::IDLE_DAYS );
if ( 0 === $summary['total'] ) {
return;
}
$parts = array(
sprintf(
/* translators: %s: number of clients. */
_n( '%s client', '%s clients', $summary['total'], 'acrossai-mcp-manager' ),
number_format_i18n( $summary['total'] )
),
);
if ( $summary['never_used'] > 0 ) {
$parts[] = sprintf(
/* translators: %s: number of clients. */
__( '%s never used', 'acrossai-mcp-manager' ),
number_format_i18n( $summary['never_used'] )
);
}
if ( $summary['idle'] > 0 ) {
$parts[] = sprintf(
/* translators: 1: number of clients, 2: number of days. */
__( '%1$s not seen in %2$s days', 'acrossai-mcp-manager' ),
number_format_i18n( $summary['idle'] ),
number_format_i18n( self::IDLE_DAYS )
);
}
if ( $summary['revoked'] > 0 ) {
$parts[] = sprintf(
/* translators: %s: number of clients. */
__( '%s revoked', 'acrossai-mcp-manager' ),
number_format_i18n( $summary['revoked'] )
);
}
echo '' . esc_html( implode( ' · ', $parts ) ) . '
';
}
/**
* Say so when the registry is failing to write.
*
* Without this, a broken write path and a genuinely quiet site look
* identical — an empty list. They are opposite facts, and only one of them
* needs an operator's attention.
*
* @since 0.4.8
* @return void
*/
private static function render_failure_warning(): void {
$failures = ClientsRecorder::failure_count();
if ( $failures <= 0 ) {
return;
}
printf(
'',
esc_html(
sprintf(
/* translators: %s: number of failed writes. */
_n(
'%s client record could not be written. This list may be incomplete.',
'%s client records could not be written. This list may be incomplete.',
$failures,
'acrossai-mcp-manager'
),
number_format_i18n( $failures )
)
)
);
}
/**
* Stash a notice for the current render.
*
* A transient keyed to the user, not a redirect: the row actions are GET
* links handled during the same render that then draws the table, so there
* is no redirect to carry a query argument across. Keyed per user so two
* administrators acting at once cannot read each other's result.
*
* @since 0.4.8
* @param string $type `success` or `error`.
* @param string $message Human-readable text.
* @return void
*/
private static function notice( string $type, string $message ): void {
set_transient( self::notice_key(), array( $type, $message ), 60 );
}
/**
* Draw and clear any pending notice.
*
* @since 0.4.8
* @return void
*/
private static function render_notice(): void {
$notice = get_transient( self::notice_key() );
if ( ! is_array( $notice ) || 2 !== count( $notice ) ) {
return;
}
delete_transient( self::notice_key() );
printf(
'',
'error' === $notice[0] ? 'error' : 'success',
esc_html( (string) $notice[1] )
);
}
/**
* Transient key for the current user's pending notice.
*
* @since 0.4.8
* @return string
*/
private static function notice_key(): string {
return 'acrossai_mcp_clients_notice_' . get_current_user_id();
}
}