Automattic\WooCommerce\Internal\MCP

MCPAdapterProvider::is_mcp_requestpublic staticWC 1.0

Check if the current request is for the MCP endpoint.

Method of the class: MCPAdapterProvider{}

No Hooks.

Returns

true|false. True if this is an MCP endpoint request.

Usage

$result = MCPAdapterProvider::is_mcp_request(): bool;

MCPAdapterProvider::is_mcp_request() code WC 10.3.3

public static function is_mcp_request(): bool {
	// Check if this is a REST request.
	if ( ! defined( 'REST_REQUEST' ) || ! REST_REQUEST ) {
		return false;
	}

	// Get the request URI.
	$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';

	// Build the MCP endpoint path dynamically from constants.
	$mcp_endpoint = '/' . self::MCP_NAMESPACE . '/' . self::MCP_ROUTE;

	// Check if the request is for the MCP endpoint.
	return false !== strpos( $request_uri, $mcp_endpoint );
}