PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / trunk
Booking for Appointments and Events Calendar – Amelia vtrunk
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 / McpAbilityHelperTrait.php
ameliabooking / vendor / wordpress / mcp-adapter / includes / Abilities Last commit date
DiscoverAbilitiesAbility.php 1 month ago ExecuteAbilityAbility.php 1 month ago GetAbilityInfoAbility.php 1 month ago McpAbilityHelperTrait.php 1 month ago
McpAbilityHelperTrait.php
88 lines
1 <?php
2 /**
3 * Helper trait for WordPress abilities providing MCP-related utilities.
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 * Trait McpAbilityHelperTrait
16 *
17 * Provides helper methods for MCP abilities including MCP exposure checking and metadata handling.
18 */
19 trait McpAbilityHelperTrait {
20
21 /**
22 * Checks if ability is publicly exposed via MCP.
23 *
24 * Validates against the ability's mcp.public metadata flag.
25 * Only abilities with mcp.public=true are accessible via default MCP server.
26 *
27 * @param string $ability_name The ability name to check.
28 *
29 * @return bool|\WP_Error True if publicly exposed, WP_Error if not.
30 */
31 protected static function check_ability_mcp_exposure( string $ability_name ) {
32 $ability = wp_get_ability( $ability_name );
33
34 if ( ! $ability ) {
35 return new WP_Error( 'ability_not_found', "Ability '{$ability_name}' not found" );
36 }
37
38 $meta = $ability->get_meta();
39 $is_public_mcp = $meta['mcp']['public'] ?? false;
40
41 if ( ! $is_public_mcp ) {
42 return new WP_Error(
43 'ability_not_public_mcp',
44 sprintf( 'Ability "%s" is not exposed via MCP (mcp.public!=true)', $ability_name )
45 );
46 }
47
48 return true;
49 }
50
51 /**
52 * Checks if ability is publicly exposed via MCP (simple boolean version).
53 *
54 * This is a simplified version that returns only boolean values,
55 * useful for filtering operations where WP_Error handling isn't needed.
56 *
57 * @param \WP_Ability $ability The ability object to check.
58 *
59 * @return bool True if publicly exposed, false otherwise.
60 */
61 protected static function is_ability_mcp_public( \WP_Ability $ability ): bool {
62 $meta = $ability->get_meta();
63
64 return (bool) ( $meta['mcp']['public'] ?? false );
65 }
66
67 /**
68 * Gets the MCP type of an ability.
69 *
70 * Returns the type specified in meta.mcp.type, defaulting to 'tool' if not specified.
71 *
72 * @param \WP_Ability $ability The ability object to check.
73 *
74 * @return string The MCP type ('tool', 'resource', or 'prompt'). Defaults to 'tool'.
75 */
76 protected static function get_ability_mcp_type( \WP_Ability $ability ): string {
77 $meta = $ability->get_meta();
78 $type = $meta['mcp']['type'] ?? 'tool';
79
80 // Validate type is one of the allowed values
81 if ( ! in_array( $type, array( 'tool', 'resource', 'prompt' ), true ) ) {
82 return 'tool';
83 }
84
85 return $type;
86 }
87 }
88