Automattic\WooCommerce\Internal\MCP

MCPAdapterProvider::get_woocommerce_mcp_abilitiesprivateWC 1.0

Get WooCommerce abilities for MCP server.

Filters abilities to include only those explicitly exposed to the deprecated WooCommerce MCP endpoint, with a filter to override inclusion decisions.

Method of the class: MCPAdapterProvider{}

Hooks from the method

Returns

Array. Array of ability IDs for MCP server.

Usage

// private - for code of main (parent) class only
$result = $this->get_woocommerce_mcp_abilities(): array;

MCPAdapterProvider::get_woocommerce_mcp_abilities() code WC 10.9.1

private function get_woocommerce_mcp_abilities(): array {
	// Get all abilities from the registry.
	$abilities_registry = wc_get_container()->get( AbilitiesRegistry::class );
	$all_abilities_ids  = $abilities_registry->get_abilities_ids();

	// Filter abilities based on deprecated endpoint exposure metadata and custom filter.
	$mcp_abilities = array_filter(
		$all_abilities_ids,
		static function ( $ability_id ) {
			$include = self::should_include_ability_by_default( $ability_id );

			// Allow filter to override inclusion decision.
			/**
			 * Filter to override MCP ability inclusion decision.
			 *
			 * @since 10.3.0
			 *
			 * @param bool   $include    Whether to include the ability by default. True when the ability has
			 *                            `expose_in_deprecated_woocommerce_mcp => true` in its metadata
			 *                            (set automatically on REST-derived abilities by RestAbilityFactory).
			 *                            Migration note: this value no longer represents whether the ability uses
			 *                            the `woocommerce/` namespace.
			 *                            Return unchanged to keep the default, or return true/false to override.
			 * @param string $ability_id The ability ID.
			 */
			return apply_filters( 'woocommerce_mcp_include_ability', $include, $ability_id );
		}
	);

	// Re-index array.
	return array_values( $mcp_abilities );
}