PluginProbe
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages / 3.4.4
Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages v3.4.4
3.4.4 3.4.3 3.4.2 3.4.1 3.4.0 3.3.9 3.3.8 3.3.7 3.3.6 3.3.5 3.3.4 3.3.3 3.3.2 3.3.1 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 All 197 releases
convertkit / vendor / wordpress / mcp-adapter / includes / Abilities / DiscoverAbilitiesAbility.php

DiscoverAbilitiesAbility.php in Kit (formerly ConvertKit) – Email Newsletter, Email Marketing, Membership, Subscribers and Landing Pages 3.4.4, at vendor/wordpress/mcp-adapter/includes/Abilities/DiscoverAbilitiesAbility.php

152 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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 effective MCP public exposure 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 // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Required by the ability callback.
84 public static function execute( $input = array() ): array {
85 // Get all abilities and filter for publicly exposed ones
86 $abilities = wp_get_abilities();
87
88 $ability_list = array();
89 foreach ( $abilities as $ability ) {
90 $ability_name = $ability->get_name();
91
92 // Check if ability is publicly exposed via MCP
93 if ( ! self::is_ability_mcp_public( $ability ) ) {
94 continue;
95 }
96
97 // Only discover abilities with type='tool' (default type)
98 if ( self::get_ability_mcp_type( $ability ) !== 'tool' ) {
99 continue;
100 }
101
102 $ability_list[] = array(
103 'name' => $ability_name,
104 'label' => $ability->get_label(),
105 'description' => $ability->get_description(),
106 );
107 }
108
109 return array(
110 'abilities' => $ability_list,
111 );
112 }
113
114 /**
115 * Check permissions for discovering abilities.
116 *
117 * Validates user capabilities and caller identity.
118 *
119 * @param array $input Input parameters (unused for this ability).
120 *
121 * @return bool|\WP_Error True if the user has permission to discover abilities.
122 */
123 // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found -- Required by the ability callback.
124 public static function check_permission( $input = array() ) {
125 // Verify caller identity - ensure user is authenticated
126 if ( ! is_user_logged_in() ) {
127 return new WP_Error( 'authentication_required', 'User must be authenticated to access this ability' );
128 }
129
130 /**
131 * Filters the capability required to discover available abilities.
132 *
133 * This capability is checked before listing all registered WordPress abilities
134 * through the mcp-adapter-discover-abilities tool.
135 *
136 * @since 0.3.0
137 *
138 * @param string $capability The required capability. Default 'read'.
139 */
140 $required_capability = apply_filters( 'mcp_adapter_discover_abilities_capability', 'read' );
141 // phpcs:ignore WordPress.WP.Capabilities.Undetermined -- Capability is determined dynamically via filter
142 if ( ! current_user_can( $required_capability ) ) {
143 return new WP_Error(
144 'insufficient_capability',
145 sprintf( 'User lacks required capability: %s', $required_capability )
146 );
147 }
148
149 return true;
150 }
151 }
152