=' ) && version_compare( $loaded_version, AAFM_MAX_ADAPTER_VERSION, '<' ); } /** * Whether the loaded adapter is newer than the tested upper bound. * * Lets aafm_init_mcp() pick the "too new" notice apart from the "too old" one. * * @param string $loaded_version Version reported by the active adapter copy. * @return bool */ function aafm_adapter_is_too_new( string $loaded_version ): bool { return version_compare( $loaded_version, AAFM_MAX_ADAPTER_VERSION, '>=' ); } /** * The version of the adapter actually loaded - whichever copy our eager load committed PHP to, or * a sibling's copy that was declared before us. * * @return string|null */ function aafm_loaded_adapter_version(): ?string { if ( ! class_exists( McpAdapter::class ) ) { return null; } return defined( McpAdapter::class . '::VERSION' ) ? (string) McpAdapter::VERSION : '0.0.0'; } /** * Initialize the MCP layer if a compatible adapter is present; otherwise show a notice. * * @return bool True when initialization proceeded. */ function aafm_init_mcp(): bool { $version = aafm_loaded_adapter_version(); if ( null === $version ) { add_action( 'admin_notices', 'aafm_notice_adapter_missing' ); return false; } if ( ! aafm_adapter_is_compatible( $version ) ) { if ( aafm_adapter_is_too_new( $version ) ) { add_action( 'admin_notices', 'aafm_notice_adapter_too_new' ); } else { add_action( 'admin_notices', 'aafm_notice_adapter_outdated' ); } return false; } // Only our governed server should exist. add_filter( 'mcp_adapter_create_default_server', '__return_false' ); McpAdapter::instance(); add_action( 'mcp_adapter_init', 'aafm_register_mcp_server' ); return true; } /** * Admin notice: no adapter available. * * @return void */ function aafm_notice_adapter_missing(): void { if ( ! current_user_can( 'activate_plugins' ) ) { return; } echo '
'; echo esc_html__( 'Agent Abilities for MCP could not load the MCP adapter. Please reinstall the plugin.', 'agent-abilities-for-mcp' ); echo '
'; if ( '' !== $plugin ) { printf( /* translators: 1: offending plugin name, 2: loaded adapter version, 3: minimum required adapter version. */ esc_html__( 'Agent Abilities for MCP is disabled: the plugin %1$s is loading MCP Adapter %2$s, but Agent Abilities for MCP requires %3$s or newer. Update or deactivate %1$s to enable agent tools.', 'agent-abilities-for-mcp' ), esc_html( $plugin ), esc_html( $loaded ), esc_html( AAFM_MIN_ADAPTER_VERSION ) ); } else { printf( /* translators: 1: loaded adapter version, 2: minimum required adapter version. */ esc_html__( 'Agent Abilities for MCP is disabled: another active plugin is loading MCP Adapter %1$s, but %2$s or newer is required. Update or deactivate that plugin to enable agent tools.', 'agent-abilities-for-mcp' ), esc_html( $loaded ), esc_html( AAFM_MIN_ADAPTER_VERSION ) ); } echo '
'; if ( '' !== $plugin ) { printf( /* translators: 1: offending plugin name, 2: loaded adapter version, 3: maximum supported adapter version (exclusive). */ esc_html__( 'Agent Abilities for MCP is disabled: the plugin %1$s is loading MCP Adapter %2$s, which is newer than this plugin supports (below %3$s). Update Agent Abilities for MCP, or deactivate %1$s, to enable agent tools.', 'agent-abilities-for-mcp' ), esc_html( $plugin ), esc_html( $loaded ), esc_html( AAFM_MAX_ADAPTER_VERSION ) ); } else { printf( /* translators: 1: loaded adapter version, 2: maximum supported adapter version (exclusive). */ esc_html__( 'Agent Abilities for MCP is disabled: another active plugin is loading MCP Adapter %1$s, which is newer than this plugin supports (below %2$s). Update Agent Abilities for MCP, or deactivate that plugin, to enable agent tools.', 'agent-abilities-for-mcp' ), esc_html( $loaded ), esc_html( AAFM_MAX_ADAPTER_VERSION ) ); } echo '