@vUYPvUpY2vUY<cvU [vU[>vU =*cvU =vUP_>vU@`>AAЖAA$8A07AAA07A0AA7AX38A07AhAA(AA@A@A048A048AH@AH@A07AAA.Ap7..A > $mcp_transports Array of MCP transport class names to initialize. * @param class-string<\WP\MCP\Infrastructure\ErrorHandling\Contracts\McpErrorHandlerInterface>|null $error_handler The error handler class name. If null, NullMcpErrorHandler will be used. * @param class-string<\WP\MCP\Infrastructure\Observability\Contracts\McpObservabilityHandlerInterface>|null $observability_handler The observability handler class name. If null, NullMcpObservabilityHandler will be used. * @param list $tools Ability names to register as tools. * @param list $resources Resources to register. * @param list $prompts Prompts to register. * @param callable|null $transport_permission_callback Optional custom permission callback for transport-level authentication. If null, defaults to is_user_logged_in(). * * @return \WP\MCP\Core\McpAdapter|\WP_Error McpAdapter instance on success, WP_Error on failure. */ public function create_server( string $server_id, string $server_route_namespace, string $server_route, string $server_name, string $server_description, string $server_version, array $mcp_transports, ?string $error_handler, ?string $observability_handler = null, array $tools = array(), array $resources = array(), array $prompts = array(), ?callable $transport_permission_callback = null ) { // Use NullMcpErrorHandler if no error handler is provided. if ( ! $error_handler ) { $error_handler = NullMcpErrorHandler::class; } // Validate error handler class exists and implements McpErrorHandlerInterface. if ( ! class_exists( $error_handler ) ) { return new WP_Error( 'invalid_error_handler', sprintf( /* translators: %s: error handler class name */ esc_html__( 'Error handler class "%s" does not exist.', 'mcp-adapter' ), esc_html( $error_handler ) ) ); } if ( ! in_array( McpErrorHandlerInterface::class, class_implements( $error_handler ) ?: array(), true ) ) { return new WP_Error( 'invalid_error_handler', sprintf( /* translators: %s: error handler class name */ esc_html__( 'Error handler class "%s" must implement the McpErrorHandlerInterface.', 'mcp-adapter' ), esc_html( $error_handler ) ) ); } // Use NullMcpObservabilityHandler if no observability handler is provided. if ( ! $observability_handler ) { $observability_handler = NullMcpObservabilityHandler::class; } // Validate observability handler class exists and implements McpObservabilityHandlerInterface. if ( ! class_exists( $observability_handler ) ) { return new WP_Error( 'invalid_observability_handler', sprintf( /* translators: %s: observability handler class name */ esc_html__( 'Observability handler class "%s" does not exist.', 'mcp-adapter' ), esc_html( $observability_handler ) ) ); } if ( ! in_array( McpObservabilityHandlerInterface::class, class_implements( $observability_handler ) ?: array(), true ) ) { return new WP_Error( 'invalid_observability_handler', sprintf( /* translators: %s: observability handler class name */ esc_html__( 'Observability handler class "%s" must implement the McpObservabilityHandlerInterface interface.', 'mcp-adapter' ), esc_html( $observability_handler ) ) ); } if ( ! doing_action( 'mcp_adapter_init' ) ) { _doing_it_wrong( __FUNCTION__, esc_html__( 'MCP Servers must be created during the "mcp_adapter_init" action. Hook into "mcp_adapter_init" to register your server.', 'mcp-adapter' ), '0.1.0' ); return new WP_Error( 'invalid_timing', esc_html__( 'MCP Server creation must be done during mcp_adapter_init action.', 'mcp-adapter' ) ); } if ( isset( $this->servers[ $server_id ] ) ) { _doing_it_wrong( __FUNCTION__, sprintf( // translators: %s: server ID esc_html__( 'Server with ID "%s" already exists. Each server must have a unique ID.', 'mcp-adapter' ), esc_html( $server_id ) ), '0.1.0' ); return new WP_Error( 'duplicate_server_id', // translators: %s: server ID. sprintf( esc_html__( 'Server with ID "%s" already exists.', 'mcp-adapter' ), esc_html( $server_id ) ) ); } // Create server with tools, resources, and prompts - let server handle all registration logic. try { $server = new McpServer( $server_id, $server_route_namespace, $server_route, $server_name, $server_description, $server_version, $mcp_transports, $error_handler, $observability_handler, $tools, $resources, $prompts, $transport_permission_callback ); } catch ( \Throwable $e ) { return new WP_Error( 'server_creation_failed', sprintf( /* translators: 1: server ID, 2: error message */ esc_html__( 'Failed to create server "%1$s": %2$s', 'mcp-adapter' ), esc_html( $server_id ), esc_html( $e->getMessage() ) ) ); } // Track server creation. $server->get_observability_handler()->record_event( 'mcp.server.created', array( 'status' => 'success', 'server_id' => $server_id, 'transport_count' => count( $mcp_transports ), 'tools_count' => count( $tools ), 'resources_count' => count( $resources ), 'prompts_count' => count( $prompts ), ) ); // Add server to registry. $this->servers[ $server_id ] = $server; return $this; } /** * Get a server by ID. * * @param string $server_id Server ID. * * @return \WP\MCP\Core\McpServer|null */ public function get_server( string $server_id ): ?McpServer { return $this->servers[ $server_id ] ?? null; } /** * Get all registered servers * * @return \WP\MCP\Core\McpServer[] */ public function get_servers(): array { return $this->servers; } /** * Register the default MCP category. * * @return void */ public function register_default_category(): void { wp_register_ability_category( 'mcp-adapter', array( 'label' => 'MCP Adapter', 'description' => 'Abilities for the MCP Adapter', ) ); } /** * Register the default MCP abilities. * * @return void */ public function register_default_abilities(): void { // Register the three core MCP abilities DiscoverAbilitiesAbility::register(); GetAbilityInfoAbility::register(); ExecuteAbilityAbility::register(); } }