PluginProbe
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF / trunk
Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF vtrunk
2.3.4 2.3.3 2.3.2 2.3.1 2.3.0 2.2.9 2.2.8 trunk 1.10 1.3.3 1.3.4 1.3.5 1.3.5.1 1.3.5.2 1.3.6 1.3.6.1 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.5 All 103 releases
imagify / vendor / wordpress / mcp-adapter / includes / Domain / Utils / AbilityArgumentNormalizer.php

AbilityArgumentNormalizer.php in Imagify Image Optimization: Optimize Images | Compress & Convert to WebP/AVIF trunk, at vendor/wordpress/mcp-adapter/includes/Domain/Utils/AbilityArgumentNormalizer.php

46 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Normalizes ability arguments for MCP protocol compatibility.
4 *
5 * @package McpAdapter
6 */
7
8 declare( strict_types=1 );
9
10 namespace WP\MCP\Domain\Utils;
11
12 /**
13 * Normalizes ability arguments between MCP and WordPress Abilities API.
14 *
15 * MCP clients send {} (empty object) for tools without arguments.
16 * PHP decodes this as [] (empty array).
17 * Abilities without input_schema expect null, not empty array.
18 *
19 * @since 0.5.0
20 */
21 class AbilityArgumentNormalizer {
22
23 /**
24 * Normalize parameters for an ability based on its input schema.
25 *
26 * If the ability has no input schema, empty arrays are converted to null.
27 * This ensures compatibility with abilities that don't accept parameters.
28 *
29 * @param \WP_Ability $ability The ability to normalize parameters for.
30 * @param mixed $parameters The parameters to normalize.
31 *
32 * @return mixed Normalized parameters (null if ability has no schema and params are empty).
33 * @since 0.5.0
34 *
35 */
36 public static function normalize( \WP_Ability $ability, $parameters ) {
37 $input_schema = $ability->get_input_schema();
38
39 if ( empty( $input_schema ) && is_array( $parameters ) && empty( $parameters ) ) {
40 return null;
41 }
42
43 return $parameters;
44 }
45 }
46