settings = $settings; } /** * Hook the conditional bootstrap. init:5 — late enough that every plugin file has * loaded (an external bootstrapper has shown its hand, see the class doc), early * enough to beat the adapter's own WP-CLI path (init:20) and any rest_api_init. */ public function register() { add_action( 'init', array( $this, 'maybe_bootstrap' ), 5 ); } /** * Load and initialise the bundled adapter when the owner opted in. Public so an * integration test can drive the gate chain directly instead of re-running boot. */ public function maybe_bootstrap() { if ( ! $this->settings->enabled( 'enable_mcp_server' ) ) { return; } if ( ! function_exists( 'wp_register_ability' ) ) { return; // WP < 6.9 without the Abilities API plugin — nothing to serve. } /** * Escape hatch: veto the bundled-adapter bootstrap entirely (e.g. a host that * manages the adapter itself), independent of the owner's setting. * * @param bool $bootstrap Whether Agentimus may boot the bundled MCP Adapter. */ if ( ! apply_filters( 'agentimus_bootstrap_mcp_adapter', true ) ) { return; } $externally_booted = class_exists( '\WP\MCP\Core\McpAdapter', false ); if ( ! class_exists( '\WP\MCP\Core\McpAdapter' ) ) { $autoload = AGENTIMUS_DIR . 'vendor/autoload_packages.php'; if ( ! file_exists( $autoload ) ) { return; // Bare git checkout without `composer install` — never fatal. } require_once $autoload; if ( ! class_exists( '\WP\MCP\Core\McpAdapter' ) ) { return; // Vendor tree present but incomplete — stand down. } } if ( ! $externally_booted ) { add_filter( 'mcp_adapter_create_default_server', '__return_false' ); } \WP\MCP\Core\McpAdapter::instance(); } }