$server Server row data. * @return void */ protected function render_body( array $server ): void { $profiles = ConnectorProfileRegistry::instance()->get_profiles(); if ( empty( $profiles ) ) { $this->render_empty_state(); return; } $server_id = (int) ( $server['id'] ?? 0 ); // phpcs:disable WordPress.Security.NonceVerification.Recommended -- Read-only routing. $requested_panel = isset( $_GET['panel'] ) ? sanitize_key( wp_unslash( (string) $_GET['panel'] ) ) : ''; // phpcs:enable // No panel requested, or an unknown / legacy name: land on the FIRST // connector in display order (Claude today) rather than Connections. // Setting a connector up is what operators come here to do; the // server-wide panels are follow-up management. `$profiles` is // guaranteed non-empty (the empty case returned above) and already // sorted by ConnectorProfileRegistry, so index 0 is the leftmost tab. // // Valid panel = one of the cross panels OR a registered connector slug. $valid_panels = array_merge( self::CROSS_PANELS, $this->connector_panel_slugs( $profiles ) ); if ( ! in_array( $requested_panel, $valid_panels, true ) ) { $requested_panel = $profiles[0]->get_slug(); } echo '
'; $this->render_top_tabs( $server, $requested_panel, $profiles ); echo '
'; $this->render_panel_dispatch( $server, $requested_panel, $profiles ); echo '
'; echo '
'; } /** * Extract the list of connector-slug panels from the registry — one * per registered profile. * * @param array $profiles * @return array */ private function connector_panel_slugs( array $profiles ): array { $slugs = array(); foreach ( $profiles as $profile ) { $slugs[] = $profile->get_slug(); } return $slugs; } /** * Render the level-2 tab bar — the three cross-connector server-wide * panels followed by one tab per registered connector profile. * * @param array $server Server row. * @param string $selected_panel Active panel id. * @param array $profiles Registered profiles from the registry. * @return void */ private function render_top_tabs( array $server, string $selected_panel, array $profiles ): void { echo ''; } /** * Dispatch to the correct renderer — either a cross-connector panel * or a per-connector tab that delegates to the profile itself. * * @param array $server Server row. * @param string $panel One of self::CROSS_PANELS or a connector slug. * @param array $profiles Registered profiles from the registry. * @return void */ private function render_panel_dispatch( array $server, string $panel, array $profiles ): void { switch ( $panel ) { case 'connections': $this->render_connections_all( $server ); return; case 'approved-users': $this->render_approved_users_all( $server ); return; case 'settings': $this->render_server_settings( $server ); return; } // Connector-slug panel — delegate to the profile's own render. foreach ( $profiles as $profile ) { if ( $profile->get_slug() === $panel ) { $this->maybe_render_disabled_notice( $server, $profile ); $profile->render_tab_section( $server ); return; } } } /** * Warn, on a connector's own tab, when that connector is disabled on this * server (FR-001). * * The tab itself stays visible and keeps its position — that is settled by * DEC-CONNECTOR-TAB-VISIBILITY (docs/memory/DECISIONS.md): "rethink WHAT the * per-entity page renders, not whether the tab should exist. Keep the tab." * The setup instructions below this notice stay readable for the same * reason: an operator reads a connector's instructions, decides to use it, * and only then enables it (FR-003). * * History — this is a restoration, not a new idea. Feature 008 shipped the * same notice for the "Any other OAuth-compliant MCP client" bucket in * `render_others_panel()`. Feature 010 (`624108f`) dropped the per-connector * tabs and deleted that method wholesale, taking the only disabled-state * notice in the plugin with it; the same-day restore (`4dd0bbc`) rebuilt the * tab strip but not the check, leaving the `ConnectorSettings` import above * unused until now. Named connectors never had this notice at all. See * memory B21. * * Rendered by this class rather than by each profile so there is one * implementation for all five, and so a profile that overrides * `render_tab_section()` cannot accidentally omit it. * * @param array $server Server row. * @param AbstractConnectorProfile $profile The connector whose panel is open. * @return void * @since 0.9.14 */ private function maybe_render_disabled_notice( array $server, AbstractConnectorProfile $profile ): void { $server_id = (int) ( $server['id'] ?? 0 ); if ( $server_id <= 0 ) { return; } if ( ConnectorSettings::is_slug_enabled_on_server( $server_id, $profile->get_slug() ) ) { return; } echo '

'; echo wp_kses_post( sprintf( /* translators: %s: connector display name, e.g. "Grok" */ __( '%s is disabled on this server. New connections are refused and any tokens it held were revoked when it was disabled. The setup steps below are for reference until you switch it back on.', 'acrossai-mcp-manager' ), esc_html( $profile->get_name() ) ) ); printf( ' %2$s', esc_url( $this->panel_url( $server, 'settings' ) ), esc_html__( 'Enable it in Settings', 'acrossai-mcp-manager' ) ); echo '

'; } /** * Build the query-arg URL for a top-level tab. * * @param array $server Server row. * @param string $panel Tab identifier (connector slug or cross-panel id). * @return string */ private function panel_url( array $server, string $panel ): string { // Feature 020 chained `&panel=` onto whichever address shape the // installed host used, asking the cross-plugin `HostCapabilities` shim // which one that was. F095 removed the shim with the rest of the // companion-only wiring: this plugin IS the host, so the Connect-tab // shape is the only shape and ConnectTab owns it. `method_url()` // returns a RAW url by contract precisely so this chaining works; it is // esc_url()'d at the output sites above. return add_query_arg( 'panel', sanitize_key( $panel ), ConnectTab::method_url( $server, 'ai-connectors' ) ); } /** * Connections panel — one row per authorization GRANT (token_family_id) * on this server, sorted by most-recent activity DESC. A user who * authorized twice from two claude.ai accounts shows up as two "Claude" * rows (they share one DCR client_id but never a token family), each * independently revocable. Legacy pre-family tokens fall back to one * (user × connector) row with the old client-scoped actions. * * @param array $server Server row. * @return void */ private function render_connections_all( array $server ): void { $server_id = (int) ( $server['id'] ?? 0 ); $groups = AccessTokenRepository::group_by_grant_for_server( $server_id ); // Feature 013: n8n admin-issued bearer tokens live in the same // oauth_tokens table and are grouped by the shared helper, but they // belong on the n8n tab's Connections sub-panel, not here. That tab // is the acrossai-pro companion's — this filter stays regardless, // because the rows it hides are written to OUR table by whoever owns // n8n, and showing them here would be wrong either way. Leaves this // panel showing only OAuth-based AI connectors (Claude / ChatGPT / // Cursor / Gemini / Grok / DCR-inferred / Others). $groups = array_values( array_filter( $groups, static function ( $g ) { return ! isset( $g['connector_slug'] ) || 'n8n' !== $g['connector_slug']; } ) ); echo '
'; printf( '

%s

', esc_html( sprintf( /* translators: %d: total number of active authorization grants */ _n( '%d active connection', '%d active connections', count( $groups ), 'acrossai-mcp-manager' ), count( $groups ) ) ) ); if ( empty( $groups ) ) { printf( '

%s

', esc_html__( 'No AI clients have connected to this server yet.', 'acrossai-mcp-manager' ) ); echo '
'; return; } echo '

' . esc_html__( 'What each action button does', 'acrossai-mcp-manager' ) . ':

    '; printf( '
  • %s — %s
  • ', esc_html__( 'Revoke', 'acrossai-mcp-manager' ), esc_html__( 'Marks every token issued by THIS authorization grant on THIS server as revoked. Other connections are unaffected — including other connections by the same user from the same AI host (e.g. a second claude.ai account). The underlying OAuth client rows stay intact; the user can re-authorize from their AI host without re-registering.', 'acrossai-mcp-manager' ) ); printf( '
  • %s — %s
  • ', esc_html__( 'Delete client (legacy rows only)', 'acrossai-mcp-manager' ), esc_html__( 'Shown only on rows marked (legacy) — tokens issued before per-grant tracking. Revokes this user\'s tokens AND deletes the underlying OAuth client row(s) if no other user still has active tokens on them. Because a client can be shared by several grants and users, deleting it may disconnect others; per-grant rows therefore only offer Revoke.', 'acrossai-mcp-manager' ) ); echo '
'; echo ''; echo ''; printf( '', esc_html__( 'User', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'Connector', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'Active tokens', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'Connected', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'Actions', 'acrossai-mcp-manager' ) ); echo ''; $now = time(); // GMT — matches stored created_at. foreach ( $groups as $group ) { $uid = (int) $group['user_id']; $user = get_userdata( $uid ); if ( $user instanceof \WP_User ) { $user_label = sprintf( '%s (#%d)', $user->user_login, $uid ); } else { // Deleted / unresolvable user — still show the id so operators // can trace it back rather than silently hiding the row. $user_label = sprintf( /* translators: %d: WordPress user id whose row has been deleted */ __( '(deleted user #%d)', 'acrossai-mcp-manager' ), $uid ); } $connector_label = ConnectorSlugDisplay::display_name( (string) $group['connector_slug'] ); $family = (string) ( $group['token_family_id'] ?? '' ); $is_legacy = ! empty( $group['is_legacy'] ); // "Connected" cell — absolute first-authorization date/time in the // site timezone (stable across refresh rotation, so it doubles as // the differentiator between two grants from the same AI host), // with last-activity time-ago alongside. $first_iso = (string) ( $group['first_created_at'] ?? '' ); $latest_iso = (string) $group['latest_created_at']; $connected = '' !== $first_iso ? get_date_from_gmt( $first_iso, get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) : '—'; $latest_ts = '' !== $latest_iso ? (int) strtotime( $latest_iso . ' UTC' ) : 0; if ( $latest_ts > 0 ) { $last_activity = sprintf( /* translators: %s: human-readable time difference like "5 minutes" */ __( 'last activity %s ago', 'acrossai-mcp-manager' ), human_time_diff( $latest_ts, $now ) ); } else { $last_activity = ''; } echo ''; printf( '', esc_html( $user_label ) ); if ( '' !== $family ) { printf( '', esc_html( $connector_label ), esc_attr( $family ), esc_html( sprintf( /* translators: %s: last 8 characters of the authorization grant id */ __( 'grant …%s', 'acrossai-mcp-manager' ), substr( $family, -8 ) ) ) ); } else { printf( '', esc_html( $connector_label ), esc_html__( '(legacy)', 'acrossai-mcp-manager' ) ); } printf( '', (int) $group['token_count'], esc_html( sprintf( /* translators: 1: access token count, 2: refresh token count */ __( '%1$d access · %2$d refresh', 'acrossai-mcp-manager' ), (int) $group['access_count'], (int) $group['refresh_count'] ) ) ); printf( '', esc_attr( $first_iso ), esc_html( $connected ), '' !== $last_activity ? sprintf( ' (%s)', esc_attr( $latest_iso ), esc_html( $last_activity ) ) : '' ); if ( ! $is_legacy ) { printf( '', esc_attr( $family ), (int) $server_id, esc_html__( 'Revoke', 'acrossai-mcp-manager' ) ); } else { $client_ids_json = wp_json_encode( array_values( $group['client_ids'] ) ); printf( '', (int) $uid, esc_attr( (string) $group['connector_slug'] ), (int) $server_id, esc_attr( (string) $client_ids_json ), esc_html__( 'Revoke', 'acrossai-mcp-manager' ), esc_html__( 'Delete client', 'acrossai-mcp-manager' ) ); } echo ''; } echo '
%s%s%s%s%s
%s%s %s%s %s%d (%s)%s%s' . '' . '' . '' . ' | ' . '
'; echo ''; } /** * Consolidated server-wide Approved Users panel. Always visible in the * top tab bar; when admin-approval is off, both sections just show * their empty state and a note that gating isn't enforced. * * @param array $server Server row. * @return void */ private function render_approved_users_all( array $server ): void { $server_id = (int) ( $server['id'] ?? 0 ); $settings = ConnectorSettings::get_server_settings( $server_id ); $pending = ConnectorSettings::server_pending_user_ids( $server_id ); $approved = ConnectorApprovedUsersQuery::instance()->find_all_by_server( $server_id ); echo '
'; printf( '

%s

', esc_html__( 'Approved Users', 'acrossai-mcp-manager' ) ); if ( ! $settings['require_admin_approval'] ) { echo '

'; esc_html_e( 'Admin approval is not currently required for this server. Any signed-in WordPress user who passes the Access Control gate can complete the OAuth consent flow. Turn on "Require admin approval for new connections" in the Settings tab if you want to gate connections here.', 'acrossai-mcp-manager' ); echo '

'; } echo '

' . esc_html__( 'What each action button does', 'acrossai-mcp-manager' ) . ':

    '; printf( '
  • %s — %s
  • ', esc_html__( 'Approve', 'acrossai-mcp-manager' ), esc_html__( 'Grants this user permission to complete the OAuth consent flow for any connector on this server.', 'acrossai-mcp-manager' ) ); printf( '
  • %s — %s
  • ', esc_html__( 'Deny', 'acrossai-mcp-manager' ), esc_html__( 'Removes this user from the pending list without approving. The user must re-attempt the connect flow from their AI host if they want to try again.', 'acrossai-mcp-manager' ) ); printf( '
  • %s — %s
  • ', esc_html__( 'Revoke approval', 'acrossai-mcp-manager' ), esc_html__( 'Removes this user from the approved list AND revokes every active OAuth token they hold on this server (any connector). The user is disconnected immediately and their next connect attempt re-enters the pending flow.', 'acrossai-mcp-manager' ) ); echo '
'; printf( '

%s

', esc_html__( 'Pending approvals', 'acrossai-mcp-manager' ) ); if ( empty( $pending ) ) { printf( '

%s

', esc_html__( 'No pending approval requests.', 'acrossai-mcp-manager' ) ); } else { echo ''; echo ''; printf( '', esc_html__( 'User', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'User ID', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'Login', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'Actions', 'acrossai-mcp-manager' ) ); echo ''; foreach ( $pending as $pending_user_id ) { $user = get_user_by( 'id', (int) $pending_user_id ); if ( ! $user ) { continue; } echo ''; printf( '', esc_html( $user->display_name ) ); printf( '', (int) $pending_user_id ); printf( '', esc_html( $user->user_login ) ); printf( '', (int) $pending_user_id, esc_html__( 'Approve', 'acrossai-mcp-manager' ), esc_html__( 'Deny', 'acrossai-mcp-manager' ) ); echo ''; } echo '
%s%s%s%s
%s#%d%s' . '' . ' | ' . '
'; } echo '
'; printf( '

%s

', esc_html__( 'Approved users', 'acrossai-mcp-manager' ) ); if ( empty( $approved ) ) { printf( '

%s

', esc_html__( 'No users have been approved yet.', 'acrossai-mcp-manager' ) ); } else { // Collapse the row list to one row per user_id — a legacy install // may have per-connector rows for the same user; server-wide UX // only wants to show them once. $seen = array(); $grouped = array(); foreach ( $approved as $row ) { $uid = (int) $row->user_id; if ( isset( $seen[ $uid ] ) ) { continue; } $seen[ $uid ] = true; $grouped[] = $row; } echo ''; echo ''; printf( '', esc_html__( 'User', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'User ID', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'Approved by', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'Approved at', 'acrossai-mcp-manager' ) ); printf( '', esc_html__( 'Actions', 'acrossai-mcp-manager' ) ); echo ''; foreach ( $grouped as $row ) { $user = get_user_by( 'id', (int) $row->user_id ); $approved_by = (int) $row->approved_by > 0 ? get_user_by( 'id', (int) $row->approved_by ) : null; echo ''; if ( $user ) { printf( '', esc_html( $user->display_name ) ); } else { printf( '', esc_html__( 'deleted', 'acrossai-mcp-manager' ) ); } printf( '', (int) $row->user_id ); if ( $approved_by ) { printf( '', esc_html( $approved_by->display_name ), (int) $row->approved_by ); } else { printf( '', esc_html__( '—', 'acrossai-mcp-manager' ) ); } printf( '', esc_html( (string) $row->approved_at ) ); printf( '', (int) $row->user_id, esc_html__( 'Revoke approval', 'acrossai-mcp-manager' ) ); echo ''; } echo '
%s%s%s%s%s
%s%s#%d%s #%d%s%s
'; } echo '
'; } /** * Server-wide Settings panel — enabled-connectors checkboxes, the * admin-approval toggle, and the "Revoke all connections on this server" * nuclear button. * * @param array $server Server row. * @return void */ private function render_server_settings( array $server ): void { $server_id = (int) ( $server['id'] ?? 0 ); $settings = ConnectorSettings::get_server_settings( $server_id ); $profiles = ConnectorProfileRegistry::instance()->get_profiles(); echo '
'; printf( '

%s

', esc_html__( 'Settings', 'acrossai-mcp-manager' ) ); echo '
'; printf( '

%s

', esc_html__( 'Connectors enabled on this server', 'acrossai-mcp-manager' ) ); foreach ( $profiles as $profile ) { $slug = $profile->get_slug(); $checked = in_array( $slug, $settings['enabled_slugs'], true ); echo '

'; } echo '

'; // FR-013 — the Others bucket's disabled-state notice, restored inline // here rather than on a panel of its own. Feature 008 rendered it in // `render_others_panel()`, which Feature 010 deleted along with the // per-connector tabs (memory B21); the panel never came back and // CROSS_PANELS has no `others` member, so the checkbox itself is now // the only surface this warning can attach to. Wording follows the // original: what is refused, and what is still recorded meanwhile. if ( empty( $settings['allow_other'] ) ) { echo '

'; esc_html_e( 'This category is currently disabled. Unrecognized clients can still register, but /authorize returns access_denied until you opt in here.', 'acrossai-mcp-manager' ); echo '

'; } echo '

' . esc_html__( 'When a connector is disabled, every active token for it on this server is immediately revoked.', 'acrossai-mcp-manager' ) . '

'; echo '

' . esc_html__( 'Enabling "Any other OAuth-compliant MCP client" always requires per-user admin approval, even when the setting below is off — unknown clients are higher-risk, so each user must be individually approved before /authorize completes.', 'acrossai-mcp-manager' ) . '

'; echo '
'; echo '

'; echo '

' . esc_html__( 'When enabled, a user must be pre-approved by an admin before they can complete the OAuth consent flow. Pending requests and the approved user list appear in the "Approved Users" panel.', 'acrossai-mcp-manager' ) . '

'; echo '

' . esc_html__( 'Note: Administrators (users with the manage_options capability) bypass this requirement and are auto-added to the approved list on first connection — they can always approve themselves anyway from the Approved Users panel, so the pending step would only add friction.', 'acrossai-mcp-manager' ) . '

'; printf( '

', esc_html__( 'Save settings', 'acrossai-mcp-manager' ) ); echo '
'; echo '
'; printf( '

', esc_attr__( 'Revoke every active token on this server, across every connector? This cannot be undone.', 'acrossai-mcp-manager' ), esc_html__( 'Revoke all connections on this server', 'acrossai-mcp-manager' ) ); echo '
'; } /** * Empty state — centered card matching the AcrossAI Ability Library * pattern (circular icon, heading, description, dashed separator, tip). * Emits self-scoped CSS so this tab doesn't depend on an external * stylesheet. * * Before F095 this was the normal state of a free install and the card * sold the add-on that supplied the profiles. The five profiles now ship * here, so reaching this state means something unregistered them on the * `acrossai_mcp_manager_connector_profiles` filter — a developer problem, * not a purchase. The add-on CTA is gone (FR-018); the filter docs link * stays, because it is now the only thing that can explain the state. * * @return void */ private function render_empty_state(): void { $docs_url = 'https://github.com/acrossai-co/acrossai-mcp-manager/blob/main/docs/extending-connector-profiles.md'; ?>


' . esc_html__( 'connector-profile filter', 'acrossai-mcp-manager' ) . '' ); ?>