PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.8
Booking for Appointments and Events Calendar – Amelia v2.4.8
2.4.8 2.4.7 2.4.6 2.4.5 2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / wordpress / mcp-adapter / includes / Abilities / DiscoverAbilitiesAbility.php
ameliabooking / vendor / wordpress / mcp-adapter / includes / Abilities Last commit date
DiscoverAbilitiesAbility.php 3 months ago ExecuteAbilityAbility.php 3 months ago GetAbilityInfoAbility.php 3 months ago McpAbilityHelperTrait.php 3 months ago
DiscoverAbilitiesAbility.php
150 lines
1 <?php
2 /**
3 * Ability for discovering available WordPress abilities.
4 *
5 * @package McpAdapter
6 */
7
8 declare( strict_types=1 );
9
10 namespace WP\MCP\Abilities;
11
12 use WP_Error;
13
14 /**
15 * Discover Abilities - Lists all available WordPress abilities in the system.
16 *
17 * This ability provides discovery functionality for the MCP protocol.
18 * It discovers all registered WordPress abilities in the system.
19 *
20 * SECURITY CONSIDERATIONS:
21 * - This ability exposes information about all registered abilities in the system
22 * - Only abilities with mcp.public=true metadata will be returned
23 * - Requires proper WordPress capability checks for secure operation
24 *
25 * @see https://developer.wordpress.org/apis/security/ for detailed security guidance
26 */
27 final class DiscoverAbilitiesAbility {
28 use McpAbilityHelperTrait;
29
30 /**
31 * Register the ability.
32 */
33 public static function register(): void {
34 wp_register_ability(
35 'mcp-adapter/discover-abilities',
36 array(
37 'label' => 'Discover Abilities',
38 'description' => 'Discover all available WordPress abilities in the system. Returns a list of all registered abilities with their basic information.',
39 'category' => 'mcp-adapter',
40 'output_schema' => array(
41 'type' => 'object',
42 'properties' => array(
43 'abilities' => array(
44 'type' => 'array',
45 'items' => array(
46 'type' => 'object',
47 'properties' => array(
48 'name' => array( 'type' => 'string' ),
49 'label' => array( 'type' => 'string' ),
50 'description' => array( 'type' => 'string' ),
51 ),
52 'required' => array( 'name', 'label', 'description' ),
53 ),
54 ),
55 ),
56 'required' => array( 'abilities' ),
57 ),
58 'permission_callback' => array( self::class, 'check_permission' ),
59 'execute_callback' => array( self::class, 'execute' ),
60 'meta' => array(
61 'annotations' => array(
62 'readonly' => true,
63 'destructive' => false,
64 'idempotent' => true,
65 ),
66 ),
67 )
68 );
69 }
70
71 /**
72 * Execute the discover abilities functionality.
73 *
74 * Note: Permission checks are handled by the WP_Ability::execute() framework method
75 * before this callback is invoked.
76 *
77 * @see \WP_Ability::execute()
78 *
79 * @param array $input Input parameters (unused for this ability).
80 *
81 * @return array Array containing public MCP abilities.
82 */
83 public static function execute( $input = array() ): array {
84 // Get all abilities and filter for publicly exposed ones
85 $abilities = wp_get_abilities();
86
87 $ability_list = array();
88 foreach ( $abilities as $ability ) {
89 $ability_name = $ability->get_name();
90
91 // Check if ability is publicly exposed via MCP
92 if ( ! self::is_ability_mcp_public( $ability ) ) {
93 continue;
94 }
95
96 // Only discover abilities with type='tool' (default type)
97 if ( self::get_ability_mcp_type( $ability ) !== 'tool' ) {
98 continue;
99 }
100
101 $ability_list[] = array(
102 'name' => $ability_name,
103 'label' => $ability->get_label(),
104 'description' => $ability->get_description(),
105 );
106 }
107
108 return array(
109 'abilities' => $ability_list,
110 );
111 }
112
113 /**
114 * Check permissions for discovering abilities.
115 *
116 * Validates user capabilities and caller identity.
117 *
118 * @param array $input Input parameters (unused for this ability).
119 *
120 * @return bool|\WP_Error True if the user has permission to discover abilities.
121 */
122 public static function check_permission( $input = array() ) {
123 // Verify caller identity - ensure user is authenticated
124 if ( ! is_user_logged_in() ) {
125 return new WP_Error( 'authentication_required', 'User must be authenticated to access this ability' );
126 }
127
128 /**
129 * Filters the capability required to discover available abilities.
130 *
131 * This capability is checked before listing all registered WordPress abilities
132 * through the mcp-adapter-discover-abilities tool.
133 *
134 * @since 0.3.0
135 *
136 * @param string $capability The required capability. Default 'read'.
137 */
138 $required_capability = apply_filters( 'mcp_adapter_discover_abilities_capability', 'read' );
139 // phpcs:ignore WordPress.WP.Capabilities.Undetermined -- Capability is determined dynamically via filter
140 if ( ! current_user_can( $required_capability ) ) {
141 return new WP_Error(
142 'insufficient_capability',
143 sprintf( 'User lacks required capability: %s', $required_capability )
144 );
145 }
146
147 return true;
148 }
149 }
150